- const L = this.game.moves.length;
- if (this.gameRef.id != data.gameId)
- break; //games IDs don't match: nothing we can do...
- // OK, opponent still in game (which might be over)
- if (data.movesCount > L)
- {
- // Just got last move from him
- this.$refs["basegame"].play(data.lastMove, "receive");
- if (data.score != "*" && this.game.score == "*")
- {
- // Opponent resigned or aborted game, or accepted draw offer
- // (this is not a stalemate or checkmate)
- this.$refs["basegame"].endGame(data.score, "Opponent action");
- }
- this.game.clocks = data.clocks;
- this.drawOffer = data.drawOffer;
- }
- else if (data.movesCount < L)
- {
- // We must tell last move to opponent
- this.st.conn.send(JSON.stringify({
- code: "lastate",
- target: this.getOppSid(), //we know he is connected
- gameId: this.gameRef.id,
- lastMove: (L>0 ? this.game.moves[L-1] : undefined),
- score: this.game.score,
- movesCount: L,
- drawOffer: this.drawOffer,
- clocks: this.game.clocks,
- }));
- }