projects
/
xogo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some improvements + simplify TODOs
[xogo.git]
/
server.js
diff --git
a/server.js
b/server.js
index
9c85eeb
..
37a343e
100644
(file)
--- a/
server.js
+++ b/
server.js
@@
-22,9
+22,7
@@
function launchGame(vname, players, options) {
Crypto.randomBytes(randstrSize).toString("hex").slice(0, randstrSize);
games[gid] = {
vname: vname,
Crypto.randomBytes(randstrSize).toString("hex").slice(0, randstrSize);
games[gid] = {
vname: vname,
- players: players.map(p => {
- return (!p ? null : {sid: p.sid, name: p.name});
- }),
+ players: players,
options: options,
time: Date.now()
};
options: options,
time: Date.now()
};
@@
-127,8
+125,10
@@
wss.on("connection", (socket, req) => {
if (games[obj.gid].rematch[1-myIndex]) {
// Launch new game, colors reversed
let vname = games[obj.gid].vname;
if (games[obj.gid].rematch[1-myIndex]) {
// Launch new game, colors reversed
let vname = games[obj.gid].vname;
- if (games[obj.gid].rematch.every(r => r == 2))
- vname = getRandomVariant();
+ const allrand = games[obj.gid].rematch.every(r => r == 2);
+ if (allrand) vname = getRandomVariant();
+ games[obj.gid].players.forEach(p =>
+ p.randvar = allrand ? true : false);
launchGame(vname,
games[obj.gid].players.reverse(),
games[obj.gid].options);
launchGame(vname,
games[obj.gid].players.reverse(),
games[obj.gid].options);
@@
-201,6
+201,13
@@
wss.on("connection", (socket, req) => {
break; //only one challenge per player
}
}
break; //only one challenge per player
}
}
+ for (let g of Object.values(games)) {
+ const myIndex = g.players.findIndex(p => p.sid == sid);
+ if (myIndex >= 0) {
+ if (g.rematch && g.rematch[myIndex] > 0) g.rematch[myIndex] = 0;
+ break; //only one game per player
+ }
+ }
});
});
});
});