X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=aec80a015d9d0106de3735fbf5bbcd5289893b90;hb=1112f1fdd39a4599cebc4b0b03bee1d28f1236ee;hp=641c0dcee365ca7d1d38f566cc505f2159d809ec;hpb=11589e7c4bb1b69473588d133db8b6d1d37b8fee;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 641c0dce..aec80a01 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -300,10 +300,7 @@ const GameModel = // Check all that is possible (required) in obj: return ( ( - !obj.move || ( - !!(obj.move.played.toString().match(/^[0-9]+$/)) && - !!(obj.move.idx.toString().match(/^[0-9]+$/)) - ) + !obj.move || !!(obj.move.idx.toString().match(/^[0-9]+$/)) ) && ( !obj.drawOffer || !!(obj.drawOffer.match(/^[wbtn]$/)) ) && ( @@ -383,7 +380,7 @@ const GameModel = "FROM Games " + "WHERE id = " + id; db.get(query, (err2, ret2) => { - const daysTc = parseInt(ret2.cadence.match(/\(^[0-9]+\)/)[0]); + const daysTc = parseInt(ret2.cadence.match(/^[0-9]+/)[0]); if (Date.now() - ret.lastPlayed > daysTc * 24 * 3600 * 1000) finishAndSendQuery(); else cb({ errmsg: "Time not over" }); @@ -457,7 +454,7 @@ const GameModel = "SELECT gid, count(*) AS nbMoves, MAX(played) AS lastMaj " + "FROM Moves " + "GROUP BY gid"; - db.get(query, (err2, mstats) => { + db.all(query, (err2, mstats) => { // Reorganize moves data to avoid too many array lookups: let movesGroups = {}; mstats.forEach(ms => { @@ -467,18 +464,18 @@ const GameModel = }; }); // Remove games still not really started, - // with no action in the last 3 months: + // with no action in the last 2 weeks: let toRemove = []; games.forEach(g => { if ( ( !movesGroups[g.id] && - tsNow - g.created > 91*day + tsNow - g.created > 14*day ) || ( movesGroups[g.id].nbMoves == 1 && - tsNow - movesGroups[g.id].lastMaj > 91*day + tsNow - movesGroups[g.id].lastMaj > 14*day ) ) { toRemove.push(g.id);