X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=0d59d6e32c54a88a3599ba5976848144ac53f09e;hb=2bb4666e276e837add0958554a11b38f7f4d9357;hp=516c4bc52982b2c3a4237777772a23ee445160d2;hpb=b49527c46ed89115a253f2965e198d06c9a26e9a;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 516c4bc5..0d59d6e3 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -128,12 +128,13 @@ const GameModel = db.serialize(function() { let query = "SELECT id, vid, cadence, created, score, white, black " + - "FROM Games "; - if (uid > 0) query += - "WHERE " + - " created < " + cursor + " AND " + - " white <> " + uid + " AND " + - " black <> " + uid + " "; + "FROM Games " + + "WHERE created < " + cursor + " "; + if (uid > 0) { + query += + " AND white <> " + uid + " " + + " AND black <> " + uid + " "; + } query += "ORDER BY created DESC " + "LIMIT 20"; //TODO: 20 hard-coded... @@ -309,7 +310,8 @@ const GameModel = ) && ( !obj.rematchOffer || !!(obj.rematchOffer.match(/^[wbn]$/)) ) && ( - !obj.fen || !!(obj.fen.match(/^[a-zA-Z0-9, /-]*$/)) + // TODO: check if commas are still used (probably not) + !obj.fen || !!(obj.fen.match(/^[a-zA-Z0-9,. /-]*$/)) ) && ( !obj.score || !!(obj.score.match(/^[012?*\/-]+$/)) ) && ( @@ -379,8 +381,10 @@ const GameModel = "(" + id + ",?," + Date.now() + "," + obj.move.idx + ")"; db.run(query, JSON.stringify(obj.move.squares)); finishAndSendQuery(); - } else cb({ errmsg: "Wrong move index" }); - } else { + } + else cb({ errmsg: "Wrong move index" }); + } + else { if (ret.maxIdx < 2) cb({ errmsg: "Time not over" }); else { // We also need the game cadence @@ -397,14 +401,16 @@ const GameModel = } } }); - } else finishAndSendQuery(); + } + else finishAndSendQuery(); // NOTE: chat and delchat are mutually exclusive if (!!obj.chat) { const query = "INSERT INTO Chats (gid, msg, name, added) VALUES (" + id + ",?,'" + obj.chat.name + "'," + Date.now() + ")"; db.run(query, obj.chat.msg); - } else if (obj.delchat) { + } + else if (obj.delchat) { const query = "DELETE " + "FROM Chats " +