* randomness: integer
* deletedByWhite: boolean
* deletedByBlack: boolean
+ * chatReadWhite: datetime
+ * chatReadBlack: datetime
*
* Structure table Moves:
* gid: ref game id
"SELECT " +
"g.id, g.fen, g.fenStart, g.cadence, g.created, " +
"g.white, g.black, g.score, g.scoreMsg, " +
+ "g.chatReadWhite, g.chatReadBlack, " +
"g.drawOffer, g.rematchOffer, v.name AS vname " +
"FROM Games g " +
"JOIN Variants v " +
// 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]$/))
) && (
!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?*\/-]+$/))
+ ) && (
+ !obj.chatRead || ['w','b'].includes(obj.chatRead)
) && (
!obj.scoreMsg || !!(obj.scoreMsg.match(/^[a-zA-Z ]+$/))
) && (
const myColor = obj.deletedBy == 'w' ? "White" : "Black";
modifs += "deletedBy" + myColor + " = true,";
}
+ if (!!obj.chatRead) {
+ const myColor = obj.chatRead == 'w' ? "White" : "Black";
+ modifs += "chatRead" + myColor + " = " + Date.now() + ",";
+ }
if (!!obj.score) {
modifs += "score = '" + obj.score + "'," +
"scoreMsg = '" + obj.scoreMsg + "',";
"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" });
"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 => {
};
});
// 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] &&
movesGroups[g.id].nbMoves == 1 &&
- tsNow - movesGroups[g.id].lastMaj > 91*day
+ tsNow - movesGroups[g.id].lastMaj > 14*day
)
) {
toRemove.push(g.id);