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

Shine sync sending might crash the game, try catch it lol

This commit is contained in:
Sanae 2022-02-22 20:51:48 -06:00
parent d074f8a5d6
commit 3d4356ccfc

View file

@ -18,10 +18,14 @@ server.ClientJoined += async (c, type) => {
};
async Task ClientSyncShineBag(Client client) {
try {
foreach (int shine in shineBag.Except((ConcurrentBag<int>) client.Metadata["shineSync"]))
await client.Send(new ShinePacket {
ShineId = shine
});
} catch {
// errors that can happen when sending will crash the server :)
}
}
async void SyncShineBag() {
@ -130,12 +134,18 @@ CommandHandler.RegisterCommand("flip", args => {
});
CommandHandler.RegisterCommand("shine", args => {
const string optionUsage = "Valid options: list";
const string optionUsage = "Valid options: list, clear";
if (args.Length < 1)
return optionUsage;
switch (args[0]) {
case "list" when args.Length == 1:
return $"Shines: {string.Join(", ", shineBag)}";
case "clear" when args.Length == 1:
shineBag.Clear();
foreach (ConcurrentBag<int> playerBag in server.Clients.Select(serverClient => (ConcurrentBag<int>) serverClient.Metadata["shineSync"])) {
playerBag.Clear();
}
return "Cleared shine bags";
default:
return optionUsage;
}