- this.st.conn.send(JSON.stringify({code:"asklastate", target:data.user.sid}));
- }
- 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);
- this.st.conn.send(JSON.stringify({
- code: "lastate",
- target: data.from,
- state:
- {
- // 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
- }
- }));