Remove client-side game over check to prevent premature game end

The client was checking activePlayers.length <= 1 and calling endGame()
prematurely, before the server's authoritative game-over event.

Now the client only ends the game when the server explicitly sends the
'game-over' event.

Added server-side logging to track active player count and winner.
This commit is contained in:
2026-03-21 03:13:08 +00:00
parent ada9ce73fa
commit 1b11a60acc
2 changed files with 4 additions and 7 deletions
+2 -7
View File
@@ -70,13 +70,8 @@ function setupNetworkListeners() {
localGame.loadState(localState); localGame.loadState(localState);
} }
// Check for game over // Game over is handled by the server via 'game-over' event
const allStates = network.getAllGameStates(); // Don't check locally to avoid premature game end
const activePlayers = Object.values(allStates).filter(s => !s.eliminated);
if (activePlayers.length <= 1) {
endGame(allStates);
}
}); });
// Game over // Game over
+2
View File
@@ -590,7 +590,9 @@ function getStates() {
function checkGameOver() { function checkGameOver() {
const activePlayers = Array.from(lobby.players.values()).filter(p => !p.eliminated); const activePlayers = Array.from(lobby.players.values()).filter(p => !p.eliminated);
console.log(`[GAMEOVER CHECK] Active players: ${activePlayers.length} (${activePlayers.map(p => p.name).join(', ')})`);
if (activePlayers.length <= 1) { if (activePlayers.length <= 1) {
console.log(`[GAME OVER] ${activePlayers.length === 1 ? `Winner: ${activePlayers[0].name}` : 'No winner (all eliminated)'}`);
io.to(LOBBY_ROOM).emit('game-over', { states: getStates() }); io.to(LOBBY_ROOM).emit('game-over', { states: getStates() });
if (lobby.gameInterval) { if (lobby.gameInterval) {
clearInterval(lobby.gameInterval); clearInterval(lobby.gameInterval);