"GET",
{uid: this.st.user.id, excluded: true},
response => {
- this.games = this.games.concat(response.games);
+ this.games = this.games.concat(response.games.map(g => {
+ const tc =
+ return Object.assign({}, g, {mainT
+ });
}
);
// Also ask for corr challenges (open + sent to me)
const pIdx = this.people.findIndex(p => p.sid == data.from);
newChall.from = this.people[pIdx]; //may be anonymous
newChall.added = Date.now(); //TODO: this is reception timestamp, not creation
- newChall.vname = this.getVname(newChall.vid); //TODO: just send vname?
+ newChall.vname = this.getVname(newChall.vid);
this.challenges.push(newChall);
break;
}
chall.added = Date.now();
chall.type = ctype;
chall.vname = vname;
+
+
+
+
+// TODO: vname and type are redundant (can be deduced from timeControl + vid)
+
+
+
+
chall.from = this.st.user;
this.challenges.push(chall);
localStorage.setItem("challenge", JSON.stringify(chall));
const vname = this.getVname(c.vid);
const vModule = await import("@/variants/" + vname + ".js");
window.V = vModule.VariantRules;
- // Extract times (in [milli]seconds), set clocks
- const tc = extractTime(c.timeControl);
// These game informations will be sent to other players
const gameInfo =
{
players: shuffle([c.from, c.seat]), //white then black
vid: c.vid,
timeControl: tc.timeControl,
- mainTime: tc.mainTime,
- increment: tc.increment,
- type: c.type,
};
this.st.conn.send(JSON.stringify({code:"newgame",
gameInfo:gameInfo, target:c.seat.sid}));
},
// NOTE: for live games only (corr games are launched on server)
startNewGame: function(gameInfo) {
- const game = Object.assign(gameInfo, {
- // More game infos: constant
- vname: this.getVname(gameInfo.vid),
+ // Extract times (in [milli]seconds), set clocks
+ const tc = extractTime(c.timeControl);
+ const game = Object.assign({}, gameInfo, {
+ // (other) Game infos: constant
fenStart: gameInfo.fen,
- mode: "live", //function for live games only
- // Game state: will be updated
+ // Game state (including FEN): will be updated
moves: [],
clocks: [tc.mainTime, tc.mainTime],
initime: [Date.now(), 0],
insertChallenge();
});
-// TODO: either like that, or remove challenge in /games POST ?
-// "Challenge update" --> someone accepted a challenge
-router.put("/challenges", access.logged, access.ajax, (req,res) => {
- // launchGame(cid, uid) //req.body.chall
- // TODO: gather challenge infos
- // Then create game, and remove challenge:
- ChallengeModel.remove(cid, req.userId, err => {
- res.json(err || {});
- });
-});
-
router.delete("/challenges", access.logged, access.ajax, (req,res) => {
const cid = req.query.id;
ChallengeModel.remove(cid, req.userId, err => {
-router.get("/games", access.logged, access.ajax, (req,res) => {
- const excluded = req.query["excluded"]; //TODO: think about query params here
-});
-
var router = require("express").Router();
var UserModel = require("../models/User");
var sendEmail = require('../utils/mailer');
)};
}
-// From main hall, start game between player 0 and 1
+// From main hall, start game between players 0 and 1
router.post("/games", access.logged, access.ajax, (req,res) => {
const gameInfo = JSON.parse(req.body.gameInfo);
if (!gameInfo.players.some(p => p.id == req.user.id))
return res.json({errmsg: "Cannot start someone else's game"});
let fen = req.body.fen;
- GameModel.create(gameInfo.vid,
- gameInfo.fen, gameInfo.mainTime, gameInfo.increment, gameInfo.players,
+ GameModel.create(
+ gameInfo.vid, gameInfo.fen, gameInfo.timeControl, gameInfo.players,
(err,game) => {
access.checkRequest(res, err, game, "Cannot create game", () => {
if (!!req.body.offlineOpp)