X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=caa15c39579c992c1e474cfa294147726a6edd24;hb=584f81b93154313a3856112400b7df98e0eb2632;hp=fc48591065f67813a992122dcea465c039ebd2aa;hpb=aae89b49a846b2c101d74db7dff9151392d6db34;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index fc485910..caa15c39 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -39,7 +39,7 @@ const GameModel = g.cadence.match(/^[0-9dhms +]+$/) && g.fen.match(/^[a-zA-Z0-9, /-]*$/) && g.players.length == 2 && - g.players.every(p => p.id.toString().match(/^[0-9]+$/)) + g.players.every(p => p.uid.toString().match(/^[0-9]+$/)) ); }, @@ -60,7 +60,7 @@ const GameModel = const color = (idx==0 ? "w" : "b"); query = "INSERT INTO Players VALUES " + - "(" + this.lastID + "," + p.id + ",'" + color + "')"; + "(" + this.lastID + "," + p.uid + ",'" + color + "')"; db.run(query); }); cb(null, {gid: this.lastID}); @@ -99,7 +99,8 @@ const GameModel = "FROM Chats " + "WHERE gid = " + id; db.all(query, (err4, chats) => { - const game = Object.assign({}, + const game = Object.assign( + {}, gameInfo, { players: players, @@ -140,7 +141,8 @@ const GameModel = "FROM Moves " + "WHERE gid = " + id; db.get(query, (err,ret) => { - const game = Object.assign({}, + const game = Object.assign( + {}, gameInfo, { players: players, @@ -212,6 +214,8 @@ const GameModel = ) ) && ( !obj.drawOffer || !!(obj.drawOffer.match(/^[wbtn]$/)) + ) && ( + !obj.rematchOffer || !!(obj.rematchOffer.match(/^[wbn]$/)) ) && ( !obj.fen || !!(obj.fen.match(/^[a-zA-Z0-9, /-]*$/)) ) && ( @@ -234,12 +238,18 @@ const GameModel = let modifs = ""; // NOTE: if drawOffer is set, we should check that it's player's turn // A bit overcomplicated. Let's trust the client on that for now... - if (obj.drawOffer) + if (!!obj.drawOffer) { - if (obj.drawOffer == "n") //Special "None" update + if (obj.drawOffer == "n") //special "None" update obj.drawOffer = ""; modifs += "drawOffer = '" + obj.drawOffer + "',"; } + if (!!obj.rematchOffer) + { + if (obj.rematchOffer == "n") //special "None" update + obj.rematchOffer = ""; + modifs += "rematchOffer = '" + obj.rematchOffer + "',"; + } if (!!obj.fen) modifs += "fen = '" + obj.fen + "',"; if (!!obj.score)