- const elapsed = Date.now() - GameStorage.getInitime();
- this.game.players.forEach(p => {
- if (p.sid != this.st.user.sid)
- this.st.conn.send("newmove",
- {
- target: p.sid,
- move: Object.assign({}, filtered_move, {elapsed: elapsed}),
- });
+ if (this.game.moves.length >= 2) //after first move
+ {
+ const elapsed = Date.now() - this.game.initime[colorIdx];
+ // elapsed time is measured in milliseconds
+ addTime = this.game.increment - elapsed/1000;
+ }
+ let sendMove = Object.assign({}, filtered_move, {addTime: addTime});
+ if (this.game.type == "corr")
+ sendMove.message = this.corrMsg;
+ const oppsid = this.getOppSid();
+ if (!!oppsid)
+ {
+ this.st.conn.send(JSON.stringify({
+ code: "newmove",
+ target: oppsid,
+ move: sendMove,
+ }));
+ }
+ if (this.game.type == "corr" && this.corrMsg != "")
+ {
+ // Add message to last move in BaseGame:
+ // TODO: not very good style...
+ this.$refs["basegame"].setCurrentMessage(this.corrMsg);
+ }
+ }
+ else
+ addTime = move.addTime; //supposed transmitted
+ const nextIdx = ["w","b"].indexOf(this.vr.turn);
+ // Since corr games are stored at only one location, update should be
+ // done only by one player for each move:
+ if (this.game.type == "live" || move.color == this.game.mycolor)
+ {
+ GameStorage.update(this.gameRef.id,
+ {
+ fen: move.fen,
+ move:
+ {
+ squares: filtered_move,
+ message: this.corrMsg,
+ played: Date.now(), //TODO: on server?
+ idx: this.game.moves.length,
+ },
+ clocks: this.game.clocks.map((t,i) => i==colorIdx
+ ? this.game.clocks[i] + addTime
+ : this.game.clocks[i]),
+ initime: this.game.initime.map((t,i) => i==nextIdx
+ ? Date.now()
+ : this.game.initime[i]),