remove players on disconnect

This commit is contained in:
Gavin McDonald
2025-04-21 16:13:30 -04:00
parent 3c986fc7fa
commit 626094cc2c
2 changed files with 22 additions and 4 deletions

View File

@@ -7,10 +7,12 @@ const deck = new Deck();
export default class GameStore {
private dms: Map<string, GameState>;
private spectators: Map<string, GameState>;
private players: Map<string, string>;
constructor() {
this.dms = new Map();
this.spectators = new Map();
this.players = new Map();
}
createGameIDs() {
@@ -61,6 +63,7 @@ export default class GameStore {
game.players.add(playerID);
game.lastUpdated = Date.now();
this.players.set(playerID, gameID);
return this.gameUpdate(game);
}
@@ -108,6 +111,15 @@ export default class GameStore {
return { dmID, spectatorID, cards, settings };
}
playerExit(playerID: string): GameState {
const gameID = this.players.get(playerID);
if (!gameID) throw new Error(`Player ${playerID} not found`);
this.players.delete(playerID);
return this.leaveGame(gameID, playerID);
}
deleteGame(gameID: string): void {
this.dms.delete(gameID);
this.spectators.delete(gameID);