- if (players.every(p => p)) {
- const gameInfo = Object.assign(
- // Provide seed so that both players initialize with same FEN
- {seed: Math.floor(Math.random() * 1984), gid: gid},
- games[gid]);
- for (const p of players) {
- send(p.sid,
- "gamestart",
- Object.assign({randvar: p.randvar}, gameInfo));
- }
- }
- else {
- // Incomplete players array: do not start game yet
- send(sid, "gamecreated", {gid: gid});
- // If nobody joins within 5 minutes, delete game
- setTimeout(
- () => {
- if (games[gid] && games[gid].players.some(p => !p))
- delete games[gid];
- },
- 5 * 60000
- );
+ return gid;
+}
+
+// Provide seed in case of, so that both players initialize with same FEN
+function launchGame(gid) {
+ const gameInfo = Object.assign(
+ {seed: Math.floor(Math.random() * 1984), gid: gid},
+ games[gid]
+ );
+ // players array is supposed to be full:
+ for (const p of games[gid].players) {
+ send(p.sid,
+ "gamestart",
+ Object.assign({randvar: p.randvar}, gameInfo));