- this.vr.re_init(game.fen);
- });
-// // Poll all players except me (if I'm playing) to know online status.
-// // --> Send ping to server (answer pong if players[s] are connected)
-// if (this.gameInfo.players.some(p => p.sid == this.st.user.sid))
-// {
-// this.game.players.forEach(p => {
-// if (p.sid != this.st.user.sid)
-// this.st.conn.send(JSON.stringify({code:"ping", oppid:p.sid}));
-// });
-// }
- },
- // TODO: refactor this old "oppConnected" logic
- oppConnected: function(uid) {
- return this.opponents.some(o => o.id == uid && o.online);
+ if (gtype == "live" && game.clocks[0] < 0) //game unstarted
+ {
+ game.clocks = [tc.mainTime, tc.mainTime];
+ game.initime[0] = Date.now();
+ if (myIdx >= 0)
+ {
+ // I play in this live game; corr games don't have clocks+initime
+ GameStorage.update(game.id,
+ {
+ clocks: game.clocks,
+ initime: game.initime,
+ });
+ }
+ }
+ this.game = Object.assign({},
+ game,
+ // NOTE: assign mycolor here, since BaseGame could also be VS computer
+ {
+ type: gtype,
+ increment: tc.increment,
+ mycolor: [undefined,"w","b"][myIdx+1],
+ // opponent sid not strictly required (or available), but easier
+ // at least oppsid or oppid is available anyway:
+ oppsid: (myIdx < 0 ? undefined : game.players[1-myIdx].sid),
+ oppid: (myIdx < 0 ? undefined : game.players[1-myIdx].uid),
+ }
+ );
+ };
+ if (!!game)
+ return afterRetrival(game);
+ if (!!this.gameRef.rid)
+ {
+ // Remote live game
+ this.st.conn.send(JSON.stringify(
+ {code:"askfullgame", target:this.gameRef.rid}));
+ // (send moves updates + resign/abort/draw actions)
+ }
+ else
+ {
+ // Local or corr game
+ GameStorage.get(this.gameRef.id, afterRetrieval);
+ }