From: Benjamin Auder Date: Tue, 10 Sep 2019 15:11:28 +0000 (+0200) Subject: Some thoughts in views/Hall.js X-Git-Url: https://git.auder.net/doc/current/bundles/framework/css/config.php?a=commitdiff_plain;h=25996aedafba5e983f324ada3db1da59206bec0a;p=vchess.git Some thoughts in views/Hall.js --- diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 2c9b4831..59d544fc 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -130,7 +130,10 @@ export default { "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) @@ -312,7 +315,7 @@ export default { 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; } @@ -401,6 +404,15 @@ export default { 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)); @@ -482,8 +494,6 @@ export default { 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 = { @@ -492,9 +502,6 @@ export default { 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})); @@ -511,12 +518,12 @@ export default { }, // 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], diff --git a/server/routes/all.js b/server/routes/all.js index 45eb21ba..fbf3433e 100644 --- a/server/routes/all.js +++ b/server/routes/all.js @@ -7,7 +7,7 @@ router.get("/", access.ajax, (req,res) => { }); router.use("/", require("./challenges")); -//router.use("/", require("./games")); +router.use("/", require("./games")); router.use("/", require("./messages")); router.use("/", require("./problems")); router.use("/", require("./users")); diff --git a/server/routes/challenges.js b/server/routes/challenges.js index faa38c53..2ae1327a 100644 --- a/server/routes/challenges.js +++ b/server/routes/challenges.js @@ -42,17 +42,6 @@ router.post("/challenges", access.logged, access.ajax, (req,res) => { 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 => { diff --git a/server/routes/games.js b/server/routes/games.js index ec824f73..c1fa9765 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -1,7 +1,3 @@ -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'); @@ -25,14 +21,14 @@ function tryNotify(uid, gid, vname, subject) )}; } -// 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)