when leaving, game is destroyed
authorLaurent Mazet <mazet@softndesign.org>
Mon, 3 Feb 2025 05:55:24 +0000 (06:55 +0100)
committerRaphaël Jakse <raph@jakse.fr>
Fri, 14 Feb 2025 07:13:19 +0000 (08:13 +0100)
server/trivabble-server.js

index 1fcc6349dee4b7bd878ba4de09f0fa5242c82377..898d274f0f627a626a4b145eabc58b7b9c68838f 100644 (file)
@@ -345,8 +345,13 @@ Game.prototype.playerLeft = function (playerName) {
         writeMessage(listeningPlayer,
             JSON.stringify({players: [{player: playerName, leave: "yes"}]}));
     }
-    if (this.listeningPlayers.length == 1) {
-        delete (this);
+    if (Object.keys(this.racks).length == 0) {
+        for (const gameID of Object.keys(games)) {
+            if (games[gameID] === this) {
+                delete (games[gameID]);
+                break;
+            }
+        }
     }
 };