From 09ff142a39921481a0129ec9ab9bd6903dbc8941 Mon Sep 17 00:00:00 2001 From: Sanae Date: Tue, 15 Mar 2022 01:23:37 -0600 Subject: [PATCH] Also sync game packets --- Server/Client.cs | 2 +- Server/Program.cs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Server/Client.cs b/Server/Client.cs index 7497d0e..3a9ab0e 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -9,7 +9,7 @@ using Shared.Packet.Packets; namespace Server; public class Client : IDisposable { - public readonly ConcurrentDictionary Metadata = new ConcurrentDictionary(); // can be used to store any information about a player + public readonly ConcurrentDictionary Metadata = new ConcurrentDictionary(); // can be used to store any information about a player public bool Connected = false; public CostumePacket? CurrentCostume = null; // required for proper client sync public string Name { diff --git a/Server/Program.cs b/Server/Program.cs index 009fd27..3a75ac2 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -17,9 +17,18 @@ server.ClientJoined += (c, _) => { c.Metadata["loadedSave"] = false; c.Metadata["scenario"] = 0; c.Metadata["2d"] = false; + foreach (Client client in server.Clients.Where(client => client.Metadata["lastGamePacket"] != null).ToArray()) { + try { + await c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client); + } + catch { + // lol who gives a fuck + } + } + c.PacketTransformer += (sender, packet) => { if (Settings.Instance.Scenario.MergeEnabled && packet is GamePacket gamePacket) { - gamePacket.ScenarioNum = (byte) c.Metadata["scenario"]; + gamePacket.ScenarioNum = (byte?) c.Metadata["scenario"] ?? 0; return gamePacket; } @@ -29,7 +38,7 @@ server.ClientJoined += (c, _) => { async Task ClientSyncShineBag(Client client) { try { - ConcurrentBag clientBag = ((ConcurrentBag)client.Metadata["shineSync"]); + ConcurrentBag clientBag = (ConcurrentBag) (client.Metadata["shineSync"] ??= new ConcurrentBag()); foreach (int shine in shineBag.Except(clientBag).ToArray()) { clientBag.Add(shine); await client.Send(new ShinePacket { @@ -67,6 +76,7 @@ server.PacketHandler = (c, p) => { case GamePacket gamePacket: { c.Metadata["scenario"] = gamePacket.ScenarioNum; c.Metadata["2d"] = gamePacket.Is2d; + c.Metadata["lastGamePacket"] = gamePacket; break; } case TagPacket tagPacket: {