mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +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:
parent
f0d837190a
commit
a0642e6a30
1 changed files with 3 additions and 2 deletions
|
@ -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 :)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue