]> git.cworth.org Git - empires-server/commitdiff
Stream player-enter events for existing players to a new player
authorCarl Worth <cworth@cworth.org>
Fri, 5 Jun 2020 23:35:12 +0000 (16:35 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 5 Jun 2020 23:35:12 +0000 (16:35 -0700)
So they can be informed of all players that are already in the game.

game.js

diff --git a/game.js b/game.js
index 24e36adbc4106db5df835ddcfcc3ea403f575988..34a0d13b4168868a4ed6e55d275c2139b0774dbc 100644 (file)
--- a/game.js
+++ b/game.js
@@ -223,6 +223,11 @@ 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 => {
+      response.write(`event: player-enter\ndata: ${p.info_json()}\n\n`);
+    });
+
     /* Finally, if this game class has a "state" property, stream that
      * current state to the client. */
     if (this.state) {