diff --git a/Server/Program.cs b/Server/Program.cs index bbd2d7c..37bce16 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -87,10 +87,11 @@ async Task ClientSyncShineBag(Client client) { if ((bool?) client.Metadata["speedrun"] ?? false) return; ConcurrentBag clientBag = (ConcurrentBag) (client.Metadata["shineSync"] ??= new ConcurrentBag()); foreach (int shine in shineBag.Except(clientBag).ToArray()) { - clientBag.Add(shine); + if (!client.Connected) return; await client.Send(new ShinePacket { ShineId = shine }); + clientBag.Add(shine); } } catch { // errors that can happen when sending will crash the server :) @@ -100,7 +101,7 @@ async Task ClientSyncShineBag(Client client) { async void SyncShineBag() { try { await PersistShines(); - await Parallel.ForEachAsync(server.Clients.ToArray(), async (client, _) => await ClientSyncShineBag(client)); + await Parallel.ForEachAsync(server.ClientsConnected.ToArray(), async (client, _) => await ClientSyncShineBag(client)); } catch { // errors that can happen shines change will crash the server :) }