X-Git-Url: https://git.auder.net/doc/index.css?a=blobdiff_plain;f=server%2Fmodels%2FGame.js;h=f175164470502c61c04e1975d62bf30be003f7d3;hb=1ad003fffabb4c95b9fd2d76a2e7ae1f20302cda;hp=16c050cd02cf8677238128072fdda3c6dd92230c;hpb=714680114508183fba2c07231dbe8f90b5631b81;p=vchess.git diff --git a/server/models/Game.js b/server/models/Game.js index 16c050cd..f1751644 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -36,8 +36,6 @@ const GameModel = checkGameInfo: function(g) { if (!g.vid.toString().match(/^[0-9]+$/)) return "Wrong variant ID"; - if (!g.vname.match(/^[a-zA-Z0-9]+$/)) - return "Wrong variant name"; if (!g.cadence.match(/^[0-9dhms +]+$/)) return "Wrong characters in time control"; if (!g.fen.match(/^[a-zA-Z0-9, /-]*$/)) @@ -168,7 +166,7 @@ const GameModel = { db.serialize(function() { const query = - "SELECT id " + + "SELECT uid " + "FROM Players " + "WHERE gid = " + id; db.all(query, (err,players) => { @@ -277,28 +275,21 @@ const GameModel = const day = 86400000; db.serialize(function() { let query = - "SELECT id,score,created " + + "SELECT id, created " + "FROM Games "; db.all(query, (err,games) => { games.forEach(g => { query = - "SELECT max(played) AS lastMaj " + + "SELECT count(*) as nbMoves, max(played) AS lastMaj " + "FROM Moves " + "WHERE gid = " + g.id; - db.get(query, (err2,updated) => { - if (!updated.lastMaj) + db.get(query, (err2,mstats) => { + // Remove games still not really started, + // with no action in the last 3 months: + if ((mstats.nbMoves == 0 && tsNow - g.created > 91*day) || + (mstats.nbMoves == 1 && tsNow - mstats.lastMaj > 91*day)) { - if (tsNow - g.created > 7*day) - return GameModel.remove(g.id); - } - else //at least one move - { - const lastMaj = updated.lastMaj; - if (g.score != "*" && tsNow - lastMaj > 7*day || - g.score == "*" && tsNow - lastMaj > 91*day) - { - GameModel.remove(g.id); - } + GameModel.remove(g.id); } }); });