+ // If repetition detected, consider that a draw offer was received:
+ const fenObj = V.ParseFen(move.fen);
+ let repIdx = fenObj.position + "_" + fenObj.turn;
+ if (!!fenObj.flags)
+ repIdx += "_" + fenObj.flags;
+ this.repeat[repIdx] = (!!this.repeat[repIdx]
+ ? this.repeat[repIdx]+1
+ : 1);
+ if (this.repeat[repIdx] >= 3)
+ this.drawOffer = "threerep";
+ else if (this.drawOffer == "threerep")
+ this.drawOffer = "";
+ // Since corr games are stored at only one location, update should be
+ // done only by one player for each move:
+ if (!!this.game.mycolor &&
+ (this.game.type == "live" || move.color == this.game.mycolor))
+ {
+ let drawCode = "";
+ switch (this.drawOffer)
+ {
+ case "threerep":
+ drawCode = "t";
+ break;
+ case "sent":
+ drawCode = this.game.mycolor;
+ break;
+ case "received":
+ drawCode = this.vr.turn;
+ break;
+ }
+ if (this.game.type == "corr")
+ {
+ GameStorage.update(this.gameRef.id,
+ {
+ fen: move.fen,
+ move:
+ {
+ squares: filtered_move,
+ played: Date.now(), //TODO: on server?
+ idx: this.game.moves.length - 1,
+ },
+ drawOffer: drawCode,
+ });
+ }
+ else //live
+ {
+ GameStorage.update(this.gameRef.id,
+ {
+ fen: move.fen,
+ move: filtered_move,
+ clocks: this.game.clocks,
+ initime: this.game.initime,
+ drawOffer: drawCode,
+ });
+ }
+ }
+ },
+ resetChatColor: function() {
+ // TODO: this is called twice, once on opening an once on closing
+ document.getElementById("chatBtn").style.backgroundColor = "#e2e2e2";