- const move = data.data;
- if (move.cancelDrawOffer) {
- // Opponent refuses draw
- this.drawOffer = "";
- // NOTE for corr games: drawOffer reset by player in turn
- if (this.game.type == "live" && !!this.game.mycolor)
- GameStorage.update(this.gameRef.id, { drawOffer: "" });
+ const movePlus = data.data;
+ const movesCount = this.game.moves.length;
+ if (movePlus.index > movesCount) {
+ // This can only happen if I'm an observer and missed a move.
+ if (this.gotMoveIdx < movePlus.index)
+ this.gotMoveIdx = movePlus.index;
+ if (!this.gameIsLoading) this.askGameAgain();
+ }
+ else {
+ if (
+ movePlus.index < movesCount ||
+ this.gotMoveIdx >= movePlus.index
+ ) {
+ // Opponent re-send but we already have the move:
+ // (maybe he didn't receive our pingback...)
+ this.send("gotmove", {data: movePlus.index, target: data.from});
+ } else {
+ this.gotMoveIdx = movePlus.index;
+ const receiveMyMove = (movePlus.color == this.game.mycolor);
+ if (!receiveMyMove && !!this.game.mycolor)
+ // Notify opponent that I got the move:
+ this.send("gotmove", {data: movePlus.index, target: data.from});
+ if (movePlus.cancelDrawOffer) {
+ // Opponent refuses draw
+ this.drawOffer = "";
+ // NOTE for corr games: drawOffer reset by player in turn
+ if (
+ this.game.type == "live" &&
+ !!this.game.mycolor &&
+ !receiveMyMove
+ ) {
+ GameStorage.update(this.gameRef.id, { drawOffer: "" });
+ }
+ }
+ this.$refs["basegame"].play(movePlus.move, "received", null, true);
+ this.processMove(
+ movePlus.move,
+ {
+ addTime: movePlus.addTime,
+ receiveMyMove: receiveMyMove
+ }
+ );
+ }