+ clickRematch: function() {
+ if (!this.game.mycolor) return; //I'm just spectator
+ if (this.rematchOffer == "received") {
+ // Start a new game!
+ let gameInfo = {
+ id: getRandString(), //ignored if corr
+ fen: V.GenRandInitFen(this.game.randomness),
+ players: this.game.players.reverse(),
+ vid: this.game.vid,
+ cadence: this.game.cadence
+ };
+ let oppsid = this.getOppsid(); //may be null
+ this.send("rnewgame", { data: gameInfo, oppsid: oppsid });
+ if (this.game.type == "live") {
+ const game = Object.assign(
+ {},
+ gameInfo,
+ {
+ // (other) Game infos: constant
+ fenStart: gameInfo.fen,
+ vname: this.game.vname,
+ created: Date.now(),
+ // Game state (including FEN): will be updated
+ moves: [],
+ clocks: [-1, -1], //-1 = unstarted
+ initime: [0, 0], //initialized later
+ score: "*"
+ }
+ );
+ GameStorage.add(game, (err) => {
+ // No error expected.
+ if (!err) {
+ if (this.st.settings.sound)
+ new Audio("/sounds/newgame.flac").play().catch(() => {});
+ this.$router.push("/game/" + gameInfo.id);
+ }
+ });
+ }
+ else {
+ // corr game
+ ajax(
+ "/games",
+ "POST",
+ {
+ // cid is useful to delete the challenge:
+ data: { gameInfo: gameInfo },
+ success: (response) => {
+ gameInfo.id = response.gameId;
+ this.$router.push("/game/" + response.gameId);
+ }
+ }
+ );
+ }
+ } else if (this.rematchOffer == "") {
+ this.rematchOffer = "sent";
+ this.send("rematchoffer", { data: true });
+ if (this.game.type == "live") {
+ GameStorage.update(
+ this.gameRef.id,
+ { rematchOffer: this.game.mycolor }
+ );
+ } else this.updateCorrGame({ rematchOffer: this.game.mycolor });
+ } else if (this.rematchOffer == "sent") {
+ // Toggle rematch offer (on --> off)
+ this.rematchOffer = "";
+ this.send("rematchoffer", { data: false });
+ if (this.game.type == "live") {
+ GameStorage.update(
+ this.gameRef.id,
+ { rematchOffer: '' }
+ );
+ } else this.updateCorrGame({ rematchOffer: 'n' });
+ }
+ },