]> git.cworth.org Git - lmno-server/blobdiff - game.js
Mark players as active:false when they drop all connections
[lmno-server] / game.js
diff --git a/game.js b/game.js
index 4649b56704a41f8c103e492c09560344cfadb299..7ca150735269d0c0b6c4bc0681e70302d4a41813 100644 (file)
--- a/game.js
+++ b/game.js
@@ -9,6 +9,7 @@ class Player {
     this.name = name;
     this.connections = [connection];
     this.team = no_team;
+    this.active = true;
   }
 
   add_connection(connection) {
@@ -214,9 +215,8 @@ class Game {
   remove_player_connection(player, connection) {
     const remaining = player.remove_connection(connection);
     if (remaining === 0) {
+      player.active = false;
       const player_data = JSON.stringify({ id: player.id });
-      this.players.filter(p => p !== player);
-      delete this.players_by_session[player.session_id];
       this.broadcast_event("player-exit", player_data);
     }
   }
@@ -266,8 +266,8 @@ class Game {
     /* And the player-info event. */
     response.write(`event: player-info\ndata: ${player.info_json()}\n\n`);
 
-    /* As well as player-enter events for all existing players. */
-    this.players.filter(p => p !== player).forEach(p => {
+    /* As well as player-enter events for all existing, active players. */
+    this.players.filter(p => p !== player && p.active).forEach(p => {
       response.write(`event: player-enter\ndata: ${p.info_json()}\n\n`);
     });