diff --git a/backend/src/events/events.gateway.ts b/backend/src/events/events.gateway.ts index 8d15b462..258012da 100644 --- a/backend/src/events/events.gateway.ts +++ b/backend/src/events/events.gateway.ts @@ -26,7 +26,8 @@ type Status = | 'friend-left' | 'won' | 'lost' - | 'finish'; + | 'finish' + | 'game-already-started'; type Scores = { [key: string]: number; @@ -112,14 +113,19 @@ export class EventsGateway implements OnGatewayDisconnect { client.join(gameId); if (!isPlayer) { + const players = Object.keys(this.players[gameId] || {}).map( + (socketId, playerNumber) => ({ + playerNumber, + user: this.users[socketId], + lostPoint: this.lostPoints[socketId], + }), + ); this.emitUpdateStatus(client, 'joined-as-viewer', { - players: Object.keys(this.players[gameId] || {}).map( - (socketId, playerNumber) => ({ - playerNumber, - user: this.users[socketId], - }), - ), + players: players, }); + if (players.some((p) => p.lostPoint == 0)) { + this.emitUpdateStatus(client, 'game-already-started'); + } return; } diff --git a/frontend/app/lib/hooks/game/useGameSocket.ts b/frontend/app/lib/hooks/game/useGameSocket.ts index aadd3366..a0950666 100644 --- a/frontend/app/lib/hooks/game/useGameSocket.ts +++ b/frontend/app/lib/hooks/game/useGameSocket.ts @@ -16,7 +16,8 @@ type Status = | "friend-left" | "won" | "lost" - | "finish"; + | "finish" + | "game-already-started"; interface HandleActionProps { playerNumber: number; @@ -44,6 +45,8 @@ const getLogFromStatus = (status: Status): string => { return "You lost!"; case "finish": return "The game has finished"; + case "game-already-started": + return "The game is already started. Wait for the next round"; } };