- // NOTE: for live games only (all on server for corr)
- update: function(gameId, obj) //colorIdx, nextIdx, move, fen, addTime, score
- {
- dbOperation((db) => {
- let objectStore = db.transaction("games", "readwrite").objectStore("games");
- objectStore.get(gameId).onsuccess = function(event) {
- const game = event.target.result;
- if (!!obj.move)
- {
- game.moves.push(obj.move);
- game.fen = obj.fen;
- game.clocks[obj.colorIdx] += obj.addTime;
- game.initime[obj.nextIdx] = Date.now();
+ // obj: chat, move, fen, clocks, score[Msg], initime, ...
+ update: function(gameId, obj) {
+ if (Number.isInteger(gameId) || !isNaN(parseInt(gameId))) {
+ // corr: only move, fen and score
+ ajax("/games", "PUT", {
+ gid: gameId,
+ newObj: {
+ // Some fields may be undefined:
+ chat: obj.chat,
+ move: obj.move,
+ fen: obj.fen,
+ score: obj.score,
+ scoreMsg: obj.scoreMsg,
+ drawOffer: obj.drawOffer