]> git.cworth.org Git - empires-server/commitdiff
Implement a more correct response to /reset
authorCarl Worth <cworth@cworth.org>
Mon, 11 May 2020 23:03:54 +0000 (16:03 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 11 May 2020 23:03:54 +0000 (16:03 -0700)
Specifically, we fix things here to clear some internal state that was
previously being missed (the "characters_to_reveal" field) and we also
fix things to report to the clients the new game state and the emptty
list of players.

server.js

index 244e6da0bf26026b83329309868c5b2cbf6d0376..b0fc79ea2fb664c52246549f6c720a81b2f93391 100644 (file)
--- a/server.js
+++ b/server.js
@@ -68,9 +68,14 @@ class Game {
     this.broadcast_event("player-leave", `{"id": ${id}}`);
   }
 
-  remove_all_players() {
+  reset() {
     this._players = [];
+    this.characters_to_reveal = null;
     this.next_player_id = 1;
+
+    this.change_state(GameState.JOIN);
+
+    this.broadcast_event("players", "{}");
   }
 
   reveal_next() {
@@ -264,7 +269,7 @@ app.post('/start', (request, response) => {
 });
 
 app.post('/reset', (request, response) => {
-  game.remove_all_players();
+  game.reset();
   response.send();
 });