X-Git-Url: https://git.auder.net/images/pieces/Cwda/bt.svg?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=39459176acfbe534c002dbca46e69a1de184c262;hb=188b4a8f2e3edfa86c4e9169ddac9a14ebc12689;hp=cfaddfefbe306d0adecb617d06a4a22bcbe1feb5;hpb=e4b6e2850770c0511ddd17d29adf6a903b4792b1;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index cfaddfef..39459176 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -197,17 +197,17 @@ const GameModel = return ( ( !obj.move || ( - obj.move.played.toString().match(/^[0-9]+$/) && - obj.move.idx.toString().match(/^[0-9]+$/) + !!(obj.move.played.toString().match(/^[0-9]+$/)) && + !!(obj.move.idx.toString().match(/^[0-9]+$/)) ) ) && ( - !obj.drawOffer || obj.drawOffer.match(/^[wbtn]$/) + !obj.drawOffer || !!(obj.drawOffer.match(/^[wbtn]$/)) ) && ( - !obj.fen || obj.fen.match(/^[a-zA-Z0-9, /-]*$/) + !obj.fen || !!(obj.fen.match(/^[a-zA-Z0-9, /-]*$/)) ) && ( - !obj.score || obj.score.match(/^[012?*\/-]+$/) + !obj.score || !!(obj.score.match(/^[012?*\/-]+$/)) ) && ( - !obj.scoreMsg || obj.scoreMsg.match(/^[a-zA-Z ]+$/) + !obj.scoreMsg || !!(obj.scoreMsg.match(/^[a-zA-Z ]+$/)) ) && ( !obj.chat || UserModel.checkNameEmail({name: obj.chat.name}) ) @@ -243,7 +243,7 @@ const GameModel = db.run(query); } // NOTE: move, chat and delchat are mutually exclusive - if (obj.move) + if (!!obj.move) { // Security: only update moves if index is right query = @@ -252,14 +252,10 @@ const GameModel = "WHERE gid = " + id; db.get(query, (err,ret) => { const m = obj.move; - - - if (!ret.maxIdx || ret.maxIdx + 1 == m.idx) { query = "INSERT INTO Moves (gid, squares, played, idx) VALUES " + "(" + id + ",?," + m.played + "," + m.idx + ")"; -return cb({errmsg: (!ret.maxIdx || ret.maxIdx + 1 == m.idx) + " " + query}); db.run(query, JSON.stringify(m.squares)); cb(null); }