From d7b96ee0316021fa7a5e428950e2d8a9d8754582 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 27 Jun 2020 10:26:29 -0700 Subject: [PATCH] Don't send a re-connecting player a player-enter event for themself It's rather ugly that we've got these semantics where the client doesn't want to see a player-enter event for itself. This is causing too many special cases in the code (such as the current commit). So we'll want to change that at some point. But for now we make the case of a player reconnecting match the semantics. Specifically we move the add_connection call down _after_ the broadcast of the player-enter event. This fixes the current client so that it doesn't display its own name twice when reclaiming a pre-existing player. --- game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.js b/game.js index 5386cd2..0023257 100644 --- a/game.js +++ b/game.js @@ -165,7 +165,6 @@ class Game { /* First see if we already have a player object for this session. */ const existing = this.players_by_session[session.id]; if (existing) { - existing.add_connection(connection); if (! existing.active) { /* If we're re-activating a previously idled player, then we * need to alert everyone that this player is now back. @@ -174,6 +173,7 @@ class Game { this.active_players++; this.broadcast_event("player-enter", existing.info_json()); } + existing.add_connection(connection); return existing; } -- 2.43.0