projects
/
xogo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix animation + Rifle
[xogo.git]
/
server.js
diff --git
a/server.js
b/server.js
index
72d285c
..
0382e37
100644
(file)
--- a/
server.js
+++ b/
server.js
@@
-17,7
+17,7
@@
function send(sid, code, data) {
// If a player deletes local infos and then tries to resume a game,
// sockets[oppSid] will probably not exist anymore:
if (socket)
// If a player deletes local infos and then tries to resume a game,
// sockets[oppSid] will probably not exist anymore:
if (socket)
- socket.send(JSON.stringify(Object.assign({
code: code
}, data)));
+ socket.send(JSON.stringify(Object.assign({
code: code
}, data)));
}
function initializeGame(vname, players, options) {
}
function initializeGame(vname, players, options) {
@@
-63,9
+63,9
@@
wss.on("connection", (socket, req) => {
switch (obj.code) {
// Send challenge (may trigger game creation)
case "seekgame": {
switch (obj.code) {
// Send challenge (may trigger game creation)
case "seekgame": {
- let opp
onent = undefined,
- choice = undefined;
- const vname = obj.vname,
+ let opp
Index = undefined, //variant name
+ choice = undefined;
//variant finally played
+ const vname = obj.vname,
//variant requested
randvar = (obj.vname == "_random");
if (vname == "_random") {
// Pick any current challenge if possible
randvar = (obj.vname == "_random");
if (vname == "_random") {
// Pick any current challenge if possible
@@
-73,22
+73,28
@@
wss.on("connection", (socket, req) => {
if (currentChalls.length >= 1) {
choice =
currentChalls[Math.floor(Math.random() * currentChalls.length)];
if (currentChalls.length >= 1) {
choice =
currentChalls[Math.floor(Math.random() * currentChalls.length)];
- opp
onent = challenges[choice]
;
+ opp
Index = choice
;
}
}
else if (challenges[vname]) {
}
}
else if (challenges[vname]) {
- opponent = challenges[vname];
+ // Anyone wanting to play the same variant ?
choice = vname;
choice = vname;
+ oppIndex = vname;
}
}
- if (opponent) {
- delete challenges[choice];
+ else if (challenges["_random"]) {
+ // Anyone accepting any variant (including vname) ?
+ choice = vname;
+ oppIndex = "_random";
+ }
+ if (oppIndex) {
if (choice == "_random")
choice = getRandomVariant();
// Launch game
let players = [
{sid: sid, name: obj.name, randvar: randvar},
if (choice == "_random")
choice = getRandomVariant();
// Launch game
let players = [
{sid: sid, name: obj.name, randvar: randvar},
- opponent
+ Object.assign({}, challenges[oppIndex])
];
];
+ delete challenges[oppIndex];
if (Math.random() < 0.5)
players = players.reverse();
// Empty options = default
if (Math.random() < 0.5)
players = players.reverse();
// Empty options = default