X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Froutes%2Fgames.js;h=a86a76ddedce9301a40c44232774252373f45356;hb=5c026d9a2c5546aa5b0d6882ae54cdb7bb36bdeb;hp=57656f41893371923baec642eef92054f378000b;hpb=aae89b49a846b2c101d74db7dff9151392d6db34;p=vchess.git diff --git a/server/routes/games.js b/server/routes/games.js index 57656f41..a86a76dd 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -8,14 +8,15 @@ const params = require("../config/parameters"); // From main hall, start game between players 0 and 1 router.post("/games", access.logged, access.ajax, (req,res) => { const gameInfo = req.body.gameInfo; + // Challenge ID is provided if game start from Hall: const cid = req.body.cid; if ( Array.isArray(gameInfo.players) && - gameInfo.players.some(p => p.id == req.userId) && - cid.toString().match(/^[0-9]+$/) && + gameInfo.players.some(p => p.uid == req.userId) && + (!cid || cid.toString().match(/^[0-9]+$/)) && GameModel.checkGameInfo(gameInfo) ) { - ChallengeModel.remove(cid); + if (!!cid) ChallengeModel.remove(cid); GameModel.create( gameInfo.vid, gameInfo.fen, gameInfo.cadence, gameInfo.players, (err,ret) => {