Fix game.started not firing when Jackbox room is full

The waitForGameStart() function checked roomStatus.full before
roomStatus.locked, causing it to short-circuit when a room was full
but the game hadn't started yet. This meant game.started was never
broadcast and watchGameAsAudience() was never called for full games.

Now only locked=true triggers game start detection. When full=true
but locked=false, the poller continues until the game actually starts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cottongin
2026-02-15 22:46:16 -05:00
parent 52e00e56f6
commit 4747aa9632

View File

@@ -406,24 +406,20 @@ async function startPlayerCountCheck(sessionId, gameId, roomCode, maxPlayers = 8
return false; return false;
} }
// If full, we know the count immediately
if (roomStatus.full) {
console.log(`[Player Count] Room is FULL - ${roomStatus.maxPlayers} players`);
updatePlayerCount(sessionId, gameId, roomStatus.maxPlayers, 'completed');
stopPlayerCountCheck(sessionId, gameId);
return false;
}
// If locked, game has started - ready to watch // If locked, game has started - ready to watch
if (roomStatus.locked) { if (roomStatus.locked) {
console.log(`[Player Count] Room is LOCKED - game in progress, starting watch`); console.log(`[Player Count] Room is LOCKED - game in progress, starting watch`);
// Return both status and real maxPlayers from Jackbox
return { ready: true, maxPlayers: roomStatus.maxPlayers }; return { ready: true, maxPlayers: roomStatus.maxPlayers };
} }
// Not ready yet // Log if full but not yet started
if (roomStatus.full) {
console.log(`[Player Count] Room is FULL but not locked yet - waiting for game start`);
} else {
console.log(`[Player Count] Room not ready yet (lobby still open)`); console.log(`[Player Count] Room not ready yet (lobby still open)`);
return null; }
return null; // Not ready, keep polling
}; };
// Wait 10 seconds before first check // Wait 10 seconds before first check