0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-21 18:55:17 +00:00

fix: only send shines to connected clients and save only after sending

otherwise it will save that the client got it to the bag and then fail sending it, therefore forever preventing the client to get the shine.
This commit is contained in:
Robin C. Ladiges 2022-11-07 20:49:34 +01:00 committed by Sanae
parent f0d837190a
commit a0642e6a30

View file

@ -87,10 +87,11 @@ async Task ClientSyncShineBag(Client client) {
if ((bool?) client.Metadata["speedrun"] ?? false) return;
ConcurrentBag<int> clientBag = (ConcurrentBag<int>) (client.Metadata["shineSync"] ??= new ConcurrentBag<int>());
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 :)
}