{
// Minimal game informations: (fen+clock not required)
id: localStorage["gid"],
- players: JSON.parse(localStorage["players"]), //array sid+name
- vid: localStorage["vid"],
+ players: JSON.parse(localStorage["players"]), //array sid+id+name
+ vname: localStorage["vname"],
timeControl: localStorage["timeControl"],
};
this.st.conn.send(JSON.stringify({code:"game",
// NOTE: it may be correspondance (if newgame while we are connected)
let newGame = data.game;
newGame.type = this.classifyObject(data.game);
- newGame.vname = this.getVname(newGame.vid);
+ newGame.vname = newGame.vname;
this.games.push(newGame);
break;
}
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
this.newGame(gameInfo); //also!
},
- // NOTE: for live games only (corr games are laucnhed on server)
+ // NOTE: for live games only (corr games are launched on server)
newGame: function(gameInfo) {
+ localStorage["gid"] = getRandString();
// Extract times (in [milli]seconds), set clocks, store in localStorage
const tc = extractTime(gameInfo.timeControl);
- dddddddd
- // TODO: [in game] send move + elapsed time (in milliseconds); in case of "lastate" message too
- // //setStorage(game); //TODO
-// if (this.settings.sound >= 1)
-// new Audio("/sounds/newgame.mp3").play().catch(err => {});
+ localStorage["timeControl"] = gameInfo.timeControl;
+ localStorage["clocks"] = JSON.stringify(
+ [...Array(gameInfo.players.length)].fill(tc.mainTime));
+ localStorage["increment"] = tc.increment;
+ localStorage["started"] = JSON.stringify(
+ [...Array(gameInfo.players.length)].fill(false));
+ localStorage["mysid"] = this.st.user.sid;
+ localStorage["vname"] = this.getVname(gameInfo.vid);
+ localStorage["fenInit"] = gameInfo.fen;
+ localStorage["players"] = JSON.stringify(gameInfo.players);
+ if (this.st.settings.sound >= 1)
+ new Audio("/sounds/newgame.mp3").play().catch(err => {});
},
},
};
const error = ChallengeModel.checkChallenge(req.body.chall);
// TODO: treat "to" field separately (search users by name)
// --> replace "to" by an array of uid (in chall), then call:
+ const from = req.userId;
+// let to = !!req.body.to ? ObjectID(req.body.to) : undefined;
+// let nameTo = !!req.body.nameTo ? req.body.nameTo : undefined;
+// let vid = ObjectID(req.body.vid);
+// if (!to && !!nameTo)
+// {
+// UserModel.getByName(nameTo, (err,user) => {
+// access.checkRequest(res, err, user, "Opponent not found", () => {
+// createChallenge(vid, from, user._id, res);
+// });
+// });
+// }
+// else if (!!to)
+// createChallenge(vid, from, to, res);
+// else
+// createChallenge(vid, from, undefined, res); //automatch
ChallengeModel.create(req.body.chall, (err,lastId) => {
res.json(err || {cid: lastId["rowid"]});
});
// });
//}
//
-//// from[, to][,nameTo]
-//router.post("/challenges", access.logged, access.ajax, (req,res) => {
-// if (req.body.from != req.user._id)
-// return res.json({errmsg: "Identity usurpation"});
-// let from = ObjectID(req.body.from);
-// let to = !!req.body.to ? ObjectID(req.body.to) : undefined;
-// let nameTo = !!req.body.nameTo ? req.body.nameTo : undefined;
-// let vid = ObjectID(req.body.vid);
-// if (!to && !!nameTo)
-// {
-// UserModel.getByName(nameTo, (err,user) => {
-// access.checkRequest(res, err, user, "Opponent not found", () => {
-// createChallenge(vid, from, user._id, res);
-// });
-// });
-// }
-// else if (!!to)
-// createChallenge(vid, from, to, res);
-// else
-// createChallenge(vid, from, undefined, res); //automatch
-//});
-//
//router.delete("/challenges", access.logged, access.ajax, (req,res) => {
// let cid = ObjectID(req.query.cid);
// ChallengeModel.getById(cid, (err,chall) => {