From: Benjamin Auder Date: Sat, 29 Feb 2020 14:37:32 +0000 (+0100) Subject: Fixes. TODO: autofocus on forms, and understand why email autofill in name field X-Git-Url: https://git.auder.net/variants/Chakart/pieces/img/doc/scripts/%24%7BgetWhatsApp%28link%29%7D?a=commitdiff_plain;h=23ecf00824691b5622b468e0409fc543c87d75dc;p=vchess.git Fixes. TODO: autofocus on forms, and understand why email autofill in name field --- diff --git a/TODO b/TODO new file mode 100644 index 00000000..7a614c48 --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +newmove received on mygames page should be added to storage if gtype == "live" +and, on game page "mconnect" events => send newmove to them (better than current setup) +also, mygames page should ask lastate infos to connected players if any (where it's not my turn) +(maybe in component GameList, if g.type == "live" ...) diff --git a/client/src/utils/gameStorage.js b/client/src/utils/gameStorage.js index 4eb6bc73..dfbd6394 100644 --- a/client/src/utils/gameStorage.js +++ b/client/src/utils/gameStorage.js @@ -96,7 +96,7 @@ export const GameStorage = { }, // Retrieve all local games (running, completed, imported...) - // light: do not retrieve moves or players or clocks (TODO: this is the only usage) + // light: do not retrieve moves or clocks (TODO: this is the only usage) getAll: function(light, callback) { dbOperation((err,db) => { let objectStore = db.transaction("games").objectStore("games"); @@ -111,7 +111,6 @@ export const GameStorage = { delete g.moves; delete g.clocks; delete g.initime; - delete g.players; } games.push(g); cursor.continue(); diff --git a/client/src/variants/Allmate.js b/client/src/variants/Allmate.js index 2fa56b57..5636f568 100644 --- a/client/src/variants/Allmate.js +++ b/client/src/variants/Allmate.js @@ -290,12 +290,11 @@ export const VariantRules = class AllmateRules extends ChessRules { getNotation(move) { let notation = super.getNotation(move); // Add a capture mark (not describing what is captured...): - if (move.vanish.length > 1 && move.appear[0].p != V.KING) { - if (notation.match(/^[a-h]/)) - // Pawn capture: remove "bx" in bxc4 for example - notation = notation.substr(2); - else - notation = notation.replace("x","") + "X"; + if (move.vanish.length > 1 && move.appear.length == 1) { + if (notation.match(/^[a-h]x/)) + // Pawn capture: remove initial "b" in bxc4 for example + notation = notation.substr(1); + notation = notation.replace("x","") + "X"; } return notation; } diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index b52de829..709cccc4 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -70,6 +70,7 @@ import Chat from "@/components/Chat.vue"; import { store } from "@/store"; import { GameStorage } from "@/utils/gameStorage"; import { ppt } from "@/utils/datetime"; +import { ajax } from "@/utils/ajax"; import { extractTime } from "@/utils/timeControl"; import { getRandString } from "@/utils/alea"; import { processModalClick } from "@/utils/modalClick"; @@ -206,16 +207,11 @@ export default { }, clearChat: function() { // Nothing more to do if game is live (chats not recorded) - if (this.game.mycolor && this.game.type == "corr") { - ajax( - "/chats", - "DELETE", - {gid: this.game.id}, - () => { - // TODO: this.game.pastChats = [] could be enough here? - this.$set(this.game, "pastChats", []); - } - ); + if (this.game.type == "corr") { + if (this.game.mycolor) + ajax("/chats", "DELETE", {gid: this.game.id}); + // TODO: this.game.chats = [] could be enough here? + this.$set(this.game, "chats", []); } }, socketMessageListener: function(msg) { diff --git a/client/src/views/MyGames.vue b/client/src/views/MyGames.vue index e0914f67..c9c65659 100644 --- a/client/src/views/MyGames.vue +++ b/client/src/views/MyGames.vue @@ -23,6 +23,8 @@ main import { store } from "@/store"; import { GameStorage } from "@/utils/gameStorage"; import { ajax } from "@/utils/ajax"; +import params from "@/parameters"; +import { getRandString } from "@/utils/alea"; import GameList from "@/components/GameList.vue"; export default { name: "my-my-games", @@ -67,12 +69,16 @@ export default { const showType = localStorage.getItem("type-myGames") || "live"; this.setDisplay(showType); }, + beforeDestroy: function() { + this.conn.send(JSON.stringify({code: "disconnect"})); + }, methods: { setDisplay: function(type, e) { this.display = type; localStorage.setItem("type-myGames", type); let elt = e ? e.target : document.getElementById(type + "Games"); elt.classList.add("active"); + elt.classList.remove("somethingnew"); //in case of if (elt.previousElementSibling) elt.previousElementSibling.classList.remove("active"); else elt.nextElementSibling.classList.remove("active"); @@ -94,6 +100,14 @@ export default { // NOTE: new move itself is not received, because it wouldn't be used. let g = games.find(g => g.id == data.gid); this.$set(g, "movesCount", g.movesCount + 1); + if ( + (g.type == "live" && this.display == "corr") || + (g.type == "corr" && this.display == "live") + ) { + document + .getElementById(g.type + "Games") + .classList.add("somethingnew"); + } } }, socketCloseListener: function() { @@ -114,4 +128,7 @@ export default { table.game-list max-height: 100% + +.somethingnew + background-color: #c5fefe !important diff --git a/server/models/Game.js b/server/models/Game.js index 3fde91f8..d72f51a1 100644 --- a/server/models/Game.js +++ b/server/models/Game.js @@ -242,6 +242,7 @@ const GameModel = query += modifs + " WHERE id = " + id; db.run(query); } + // NOTE: move, chat and delchat are mutually exclusive if (obj.move) { // Security: only update moves if index is right @@ -275,7 +276,7 @@ const GameModel = "DELETE " + "FROM Chats " + "WHERE gid = " + id; - db.run(query, cb); + db.run(query); } }); }, diff --git a/server/routes/games.js b/server/routes/games.js index 607ab39e..4000ac78 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -90,8 +90,8 @@ router.delete("/chats", access.logged, access.ajax, (req,res) => { GameModel.getPlayers(gid, (err,players) => { if (players.some(p => p.uid == req.userId)) { - GameModel.update(gid, {delchat: true}, (err) => { - res.json(err || {}); + GameModel.update(gid, {delchat: true}, () => { + res.json({}); }); } }); diff --git a/server/sockets.js b/server/sockets.js index cf5ea1b8..206c780f 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -197,16 +197,14 @@ module.exports = function(wss) { { // Relay newmove info to myGames page // NOTE: the move itself is not needed (for now at least) - const newmoveForMygames = { - gid: page.split("/")[2] //format is "/game/gid" - }; + const gid = page.split("/")[2]; //format is "/game/gid" obj.data.players.forEach(pSid => { if (clients[mygamesPg][pSid]) { Object.keys(clients[mygamesPg][pSid]).forEach(x => { send( clients[mygamesPg][pSid][x], - {code:"newmove", data:newmoveForMygames} + {code:"newmove", gid:gid} ); }); }