X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=game.js;h=7ca150735269d0c0b6c4bc0681e70302d4a41813;hb=3586642fb026f5caa5da24ec8a68862509f0d4d1;hp=5a49b6bdd52b5aaf753ca3469e14618cd1548c9a;hpb=c748592a7db27adebd48b45970b5f0ffbedb3300;p=lmno-server diff --git a/game.js b/game.js index 5a49b6b..7ca1507 100644 --- 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) { @@ -23,7 +24,7 @@ class Player { /* Returns the number of remaining connections after this one is removed. */ remove_connection(connection) { - this.connections.filter(c => c !== connection); + this.connections = this.connections.filter(c => c !== connection); return this.connections.length; } @@ -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`); });