mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-19 15:51:42 +00:00
Clean up abandoned games on disconnect
When a client disconnects without ever having joined a game, it leaves behind an empty game on the server. Remove these when a player disconnects. Co-Authored-By: js6pak <me@6pak.dev>
This commit is contained in:
1 parent
792c9626e4
commit
a7c37b6bcf
2 files changed
+10
No files matched your search
@@ -373,6 +373,7 @@ namespace Impostor.Server.Net
|
||||
|
||||
_logger.LogInformation("Client {0} disconnecting, reason: {1}", Id, reason);
|
||||
_clientManager.Remove(this);
|
||||
await _gameManager.OnClientDisconnectAsync(this);
|
||||
}
|
||||
|
||||
private bool IsPacketAllowed(IMessageReader message, bool hostOnly)
|
||||
|
||||
@@ -142,5 +142,14 @@ namespace Impostor.Server.Net.Manager
|
||||
|
||||
return (true, game);
|
||||
}
|
||||
|
||||
internal async ValueTask OnClientDisconnectAsync(IClient client)
|
||||
{
|
||||
if (_gamesCreatedBy.TryRemove(client, out var game) && game is { PlayerCount: 0, GameState: not GameStates.Destroyed })
|
||||
{
|
||||
_logger.LogWarning("Client {Name}({ClientId}) left empty game open when disconnecting", client.Name, client.Id);
|
||||
await RemoveAsync(game.Code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user