server for my chess game
fix hosting as black
bendn 2022-09-26
parent e9ec0d7 · commit ba14c50
-rw-r--r--src/game.js1
-rw-r--r--src/index.js5
2 files changed, 4 insertions, 2 deletions
diff --git a/src/game.js b/src/game.js
index d8cb859..197880f 100644
--- a/src/game.js
+++ b/src/game.js
@@ -53,6 +53,7 @@ export class Game {
add_client(ws, data, is_white = this.clients.w.empty) {
this.clients.add(ws, data.name, data.id, data.country, is_white);
+ return is_white ? 0 : 1;
}
clean_clients(set_is_alive = true) {
diff --git a/src/index.js b/src/index.js
index 9e0b53c..e162943 100644
--- a/src/index.js
+++ b/src/index.js
@@ -190,8 +190,9 @@ function handle_joinrequest(data, ws) {
if (game !== undefined) {
if (game.players < 2) {
// hoster is waiting for someone to join
- game.add_client(ws, data);
- ws.send_packet({ idx: game.joinerIndex }, HEADERS.joinrequest); // tell them what team they are
+
+ const joiner_idx = game.add_client(ws, data);
+ ws.send_packet({ idx: joiner_idx }, HEADERS.joinrequest); // tell them what team they are
game.send_group_packet(game.pgn, HEADERS.loadpgn); // hoster doesnt send a joinrequest, so tell it to load pgn too
send_info();
console.log(`${data.name} joined ${data.gamecode}`);