X-Git-Url: https://git.cworth.org/git?p=empires-server;a=blobdiff_plain;f=empires.js;h=839f5f8be8dc56460b4c6165d4378d99de56f095;hp=881a2c0dbdd41409bec91c6c1707323a14637e3c;hb=HEAD;hpb=f27cdf8b57b41a91dd7ab67be407d803dcaad1a3 diff --git a/empires.js b/empires.js index 881a2c0..839f5f8 100644 --- a/empires.js +++ b/empires.js @@ -38,9 +38,6 @@ class Empires extends Game { this.next_player_id = 1; this.characters_to_reveal = null; this.phase = GamePhase.JOIN; - - /* Send a comment to every connected client every 15 seconds. */ - setInterval(() => {this.broadcast_string(":");}, 15000); } add_spectator(name, session_id) { @@ -68,7 +65,7 @@ class Empires extends Game { this.broadcast_event("spectator-leave", `{"id": ${id}}`); } - add_player(name, character) { + register_player(name, character) { const new_player = {id: this.next_player_id, name: name, character: character, @@ -179,7 +176,14 @@ class Empires extends Game { })); } - get players() { + /* The base class recently acquired Game.players which works like + * Empires.spectators, (and meanwhile the Empires._players + * functionality could perhaps be reworked into + * Game.players[].team). Until we do that rework, lets use + * .registered_players as the getter for the Empires-specific + * ._players property to avoid mixing it up with the distinct + * Game.players property. */ + get registered_players() { return this._players.map(player => ({id: player.id, name: player.name })); } @@ -225,7 +229,7 @@ class Empires extends Game { } if (this._players.length > 0) { - const players_json = JSON.stringify(this.players); + const players_json = JSON.stringify(this.registered_players); const players_data = `event: players\ndata: ${players_json}\n\n`; response.write(players_data); } @@ -274,7 +278,7 @@ router.post('/register', (request, response) => { if (request.body.name) name = request.body.name; - const player = game.add_player(name, request.body.character); + const player = game.register_player(name, request.body.character); response.send(JSON.stringify(player.id)); }); @@ -337,7 +341,7 @@ router.get('/spectators', (request, response) => { router.get('/players', (request, response) => { const game = request.game; - response.send(game.players); + response.send(game.registered_players); }); Empires.meta = {