projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Draft or user bio support (ready in Hall, TODO in Game)
[vchess.git]
/
server
/
models
/
Game.js
diff --git
a/server/models/Game.js
b/server/models/Game.js
index
080cab3
..
1d2cd68
100644
(file)
--- a/
server/models/Game.js
+++ b/
server/models/Game.js
@@
-18,6
+18,8
@@
const UserModel = require("./User");
* randomness: integer
* deletedByWhite: boolean
* deletedByBlack: boolean
* randomness: integer
* deletedByWhite: boolean
* deletedByBlack: boolean
+ * chatReadWhite: datetime
+ * chatReadBlack: datetime
*
* Structure table Moves:
* gid: ref game id
*
* Structure table Moves:
* gid: ref game id
@@
-74,6
+76,7
@@
const GameModel =
"SELECT " +
"g.id, g.fen, g.fenStart, g.cadence, g.created, " +
"g.white, g.black, g.score, g.scoreMsg, " +
"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 " +
"g.drawOffer, g.rematchOffer, v.name AS vname " +
"FROM Games g " +
"JOIN Variants v " +
@@
-125,12
+128,13
@@
const GameModel =
db.serialize(function() {
let query =
"SELECT id, vid, cadence, created, score, white, black " +
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...
query +=
"ORDER BY created DESC " +
"LIMIT 20"; //TODO: 20 hard-coded...
@@
-232,11
+236,18
@@
const GameModel =
"JOIN Variants v " +
" ON g.vid = v.id " +
"WHERE " +
"JOIN Variants v " +
" ON g.vid = v.id " +
"WHERE " +
- " score <> '*' AND
" +
- " created < " + cursor + " AND
" +
+ " score <> '*' AND" +
+ " created < " + cursor + " AND" +
" (" +
" (" +
- " (" + uid + " = white AND NOT deletedByWhite) OR " +
- " (" + uid + " = black AND NOT deletedByBlack)" +
+ " (" +
+ " white = " + uid + " AND" +
+ " (deletedByWhite IS NULL OR NOT deletedByWhite)" +
+ " )" +
+ " OR " +
+ " (" +
+ " black = " + uid + " AND" +
+ " (deletedByBlack IS NULL OR NOT deletedByBlack)" +
+ " )" +
" ) ";
query +=
"ORDER BY created DESC " +
" ) ";
query +=
"ORDER BY created DESC " +
@@
-293,18
+304,18
@@
const GameModel =
// Check all that is possible (required) in obj:
return (
(
// 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.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.score || !!(obj.score.match(/^[012?*\/-]+$/))
+ ) && (
+ !obj.chatRead || ['w','b'].includes(obj.chatRead)
) && (
!obj.scoreMsg || !!(obj.scoreMsg.match(/^[a-zA-Z ]+$/))
) && (
) && (
!obj.scoreMsg || !!(obj.scoreMsg.match(/^[a-zA-Z ]+$/))
) && (
@@
-339,6
+350,10
@@
const GameModel =
const myColor = obj.deletedBy == 'w' ? "White" : "Black";
modifs += "deletedBy" + myColor + " = true,";
}
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 + "',";
if (!!obj.score) {
modifs += "score = '" + obj.score + "'," +
"scoreMsg = '" + obj.scoreMsg + "',";
@@
-376,7
+391,7
@@
const GameModel =
"FROM Games " +
"WHERE id = " + id;
db.get(query, (err2, ret2) => {
"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" });
if (Date.now() - ret.lastPlayed > daysTc * 24 * 3600 * 1000)
finishAndSendQuery();
else cb({ errmsg: "Time not over" });
@@
-450,7
+465,7
@@
const GameModel =
"SELECT gid, count(*) AS nbMoves, MAX(played) AS lastMaj " +
"FROM Moves " +
"GROUP BY gid";
"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 => {
// Reorganize moves data to avoid too many array lookups:
let movesGroups = {};
mstats.forEach(ms => {
@@
-460,18
+475,19
@@
const GameModel =
};
});
// Remove games still not really started,
};
});
// Remove games still not really started,
- // with no action in the last
3 month
s:
+ // with no action in the last
2 week
s:
let toRemove = [];
games.forEach(g => {
if (
(
!movesGroups[g.id] &&
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 &&
movesGroups[g.id].nbMoves == 1 &&
- tsNow - movesGroups[g.id].lastMaj >
91
*day
+ tsNow - movesGroups[g.id].lastMaj >
14
*day
)
) {
toRemove.push(g.id);
)
) {
toRemove.push(g.id);