game workflow corrected

This commit is contained in:
magdo
2025-11-05 20:20:22 +01:00
parent 666a2d3e87
commit 5a4be5b7d3
12 changed files with 193 additions and 298 deletions
@@ -68,8 +68,6 @@ export class StartGameCommandHandler {
orgid: command.orgid || null,
gamedecks,
players: [],
started: false,
finished: false,
winner: null,
state: GameState.WAITING,
startdate: null,
@@ -65,7 +65,6 @@ export class StartGamePlayCommandHandler {
// Update game state in database
const updatedGame = await this.gameRepository.update(game.id, {
started: true,
state: GameState.ACTIVE,
startdate: new Date()
});
@@ -111,11 +110,6 @@ export class StartGamePlayCommandHandler {
throw new Error('Game is not in waiting state and cannot be started');
}
// Check if game is already started
if (game.started) {
throw new Error('Game has already been started');
}
// Check if there are enough players (at least 2)
if (game.players.length < 2) {
throw new Error('Game needs at least 2 players to start');
@@ -1222,14 +1222,13 @@ export class GameWebSocketService {
if (!game) return;
// Only clean up games that haven't finished yet
if (!game.finished) {
if (game.state !== GameState.FINISHED && game.state !== GameState.CANCELLED) {
logOther(`Handling abandoned game ${gameCode}`, { gameId: game.id });
// Mark game as abandoned in database
// Mark game as cancelled in database
await this.gameRepository.update(game.id, {
finished: true,
state: GameState.CANCELLED,
enddate: new Date(),
// Could add an 'abandoned' flag if the database schema supports it
});
// Clean up all Redis data for this abandoned game
@@ -2236,7 +2235,7 @@ export class GameWebSocketService {
const game = await this.gameRepository.findByGameCode(gameCode);
if (game) {
await this.gameRepository.update(game.id, {
finished: true,
state: GameState.FINISHED,
winner: winnerId,
enddate: new Date()
});