X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=sockets.js;h=e411050dbde2c6f58a8da437f4cb8bb97d1225b3;hp=11fe91ccc8079e07c91e899c7c62608b1d217fcb;hb=edcd679ab1fe609641451586ef1e9484925c4f83;hpb=d5dd0008aeca931c74645aa294b13fe2805ebfe8 diff --git a/sockets.js b/sockets.js index 11fe91cc..e411050d 100644 --- a/sockets.js +++ b/sockets.js @@ -100,20 +100,21 @@ module.exports = function(wss) { // Start a new game const oppId = games[page]["id"]; const fen = games[page]["fen"]; + const gameId = games[page]["gameid"]; delete games[page]; - const mycolor = Math.random() < 0.5 ? 'w' : 'b'; + const mycolor = (Math.random() < 0.5 ? 'w' : 'b'); socket.send(JSON.stringify( - {code:"newgame",fen:fen,oppid:oppId,color:mycolor})); + {code:"newgame",fen:fen,oppid:oppId,color:mycolor,gameid:gameId})); if (!!clients[page][oppId]) { clients[page][oppId].send( JSON.stringify( - {code:"newgame",fen:fen,oppid:sid,color:mycolor=="w"?"b":"w"}), + {code:"newgame",fen:fen,oppid:sid,color:mycolor=="w"?"b":"w",gameid:gameId}), noop); } } else - games[page] = {id:sid, fen:obj.fen}; //wait for opponent + games[page] = {id:sid, fen:obj.fen, gameid:obj.gameid}; //wait for opponent break; case "cancelnewgame": //if a user cancel his seek delete games[page];