From: Raphaƫl Jakse Date: Sun, 5 Apr 2020 16:13:13 +0000 (+0200) Subject: fix stopped game count when stopping the server X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=fa22a07af8addf706a67b17654681677e4b3d66e;p=trivabble.git fix stopped game count when stopping the server --- diff --git a/trivabble-server.js b/trivabble-server.js index 25bfb3d..bd3005a 100644 --- a/trivabble-server.js +++ b/trivabble-server.js @@ -157,16 +157,21 @@ function stop() { console.log("Closing connections and saving the game state..."); let listeningPlayerCount = 0; + let gamesCount = 0; for (const gameID of Object.keys(games)) { const game = games[gameID]; for (const listeningPlayer of game.listeningPlayers) { writeResponse(listeningPlayer, '{"stopping": 2000}', true); } - listeningPlayerCount += game.listeningPlayers.length; + + if (game.listeningPlayers.length) { + listeningPlayerCount += game.listeningPlayers.length; + gamesCount++; + } } - console.log("Stopped", games.length, "games and ", listeningPlayerCount, " player connections."); + console.log("Stopped", gamesCount, "games and", listeningPlayerCount, "player connections."); saveGames(true); }