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=3fde91f8cb03b9b6fdcec573995777a35c53ce15;hpb=db1f1f9adb920605c7a16b060a7737e54636ee08;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 3fde91f8..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}) ) @@ -242,7 +242,8 @@ const GameModel = query += modifs + " WHERE id = " + id; db.run(query); } - if (obj.move) + // NOTE: move, chat and delchat are mutually exclusive + if (!!obj.move) { // Security: only update moves if index is right query = @@ -275,7 +276,7 @@ const GameModel = "DELETE " + "FROM Chats " + "WHERE gid = " + id; - db.run(query, cb); + db.run(query); } }); },