- case "newmove":
- if (!!data.move.cancelDrawOffer) //opponent refuses draw
- this.drawOffer = "";
- this.$set(this.game, "moveToPlay", data.move);
+ case "askfullgame":
+ this.send("fullgame", { data: this.game, target: data.from });
+ break;
+ case "fullgame":
+ // Callback "roomInit" to poll clients only after game is loaded
+ this.loadGame(data.data, this.roomInit);
+ break;
+ case "asklastate":
+ // Sending last state if I played a move or score != "*"
+ if (
+ (this.game.moves.length > 0 && this.vr.turn != this.game.mycolor) ||
+ this.game.score != "*" ||
+ this.drawOffer == "sent"
+ ) {
+ // Send our "last state" informations to opponent
+ const L = this.game.moves.length;
+ const myIdx = ["w", "b"].indexOf(this.game.mycolor);
+ const myLastate = {
+ // NOTE: lastMove (when defined) includes addTime
+ lastMove: L > 0 ? this.game.moves[L - 1] : undefined,
+ // Since we played a move (or abort or resign),
+ // only drawOffer=="sent" is possible
+ drawSent: this.drawOffer == "sent",
+ score: this.game.score,
+ movesCount: L,
+ initime: this.game.initime[1 - myIdx] //relevant only if I played
+ };
+ this.send("lastate", { data: myLastate, target: data.from });
+ }