+ case "askgame":
+ // Send current (live) game if not asked by any of the players
+ if (
+ this.game.type == "live" &&
+ this.game.players.every(p => p.sid != data.from[0])
+ ) {
+ const myGame = {
+ id: this.game.id,
+ fen: this.game.fen,
+ players: this.game.players,
+ vid: this.game.vid,
+ cadence: this.game.cadence,
+ score: this.game.score,
+ rid: this.st.user.sid //useful in Hall if I'm an observer
+ };
+ this.send("game", { data: myGame, target: data.from });
+ }
+ break;
+ 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 });
+ }