server for my chess game
fix exists() function and rename to alive()
| -rw-r--r-- | src/clients.js | 4 | ||||
| -rw-r--r-- | src/game.js | 2 | ||||
| -rw-r--r-- | src/index.js | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/src/clients.js b/src/clients.js index f018a12..3e64702 100644 --- a/src/clients.js +++ b/src/clients.js @@ -61,8 +61,8 @@ export class Clients { else this.b = create_data(ws, id, name, country); } - exists(color) { - return color === "w" ? !this.w.empty : !this.b.empty; + alive(color) { + return color === "w" ? !!this.w.ws : !!this.b.ws; } // fake function overloading diff --git a/src/game.js b/src/game.js index 197880f..1ef79fe 100644 --- a/src/game.js +++ b/src/game.js @@ -18,7 +18,7 @@ export class Game { this.get_info = this.clients.get_info.bind(this.clients); this.get_ws = this.clients.get_ws.bind(this.clients); this.color_of = this.clients.color_of.bind(this.clients); - this.exists = this.clients.exists.bind(this.clients); + this.alive = this.clients.alive.bind(this.clients); this.remove_client = this.clients.erase.bind(this.clients); this.add_spectator = this.spectators.push; diff --git a/src/index.js b/src/index.js index e162943..0fd4578 100644 --- a/src/index.js +++ b/src/index.js @@ -177,7 +177,7 @@ function handle_joinrequest(data, ws) { const us = game.clients.color_of(ws); const them = flip_color(us); // in a ideal world, clients dont disconnect and stop existing. we do not live in a ideal world. (sadly) (or they just left the game :/) - if (game.exists(them) && !they_know_about_me) + if (game.alive(them) && !they_know_about_me) game.get_ws(them).send_packet(game.get_info(us), HEADERS.info); // send a packet to us |