- // Request only one client out of 2 (TODO: this is a bit heavy)
- // Alt: ask game to all, and filter later?
- Object.keys(gameSids).forEach(gid => {
- const L = gameSids[gid].length;
- const sidIdx = L > 1
- ? Math.floor(Math.random() * Math.floor(L))
- : 0;
- const tmpIdx = Object.values(gameSids[gid][sidIdx]
- const rid = gameSids[gid][sidIdx][tmpIdx];
- clients[sidIdx][tmpIdx].sock.send(JSON.stringify(
- {code:"askgame", from: [sid,tmpId]}));
- });
- break;
- }
- case "askgame":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askgame", from:sid}));
- break;
- case "askfullgame":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"askfullgame", from:sid}));
- break;
- case "fullgame":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"fullgame", game:obj.game}));
- break;
- case "identity":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"identity",user:obj.user}));
- break;
- case "refusechallenge":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"refusechallenge", cid:obj.cid, from:sid}));
- break;
- case "deletechallenge":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"deletechallenge", cid:obj.cid, from:sid}));
- break;
- case "newgame":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"newgame", gameInfo:obj.gameInfo, cid:obj.cid}));
- break;
- case "challenge":
- clients[obj.target].sock.send(JSON.stringify(
- {code:"challenge", chall:obj.chall, from:sid}));
- break;
- case "game":
- if (!!obj.target)
- {
- clients[obj.target].sock.send(JSON.stringify(
- {code:"game", game:obj.game, from:sid}));
- }
- else
- {
- // Notify all room except opponent and me:
- notifyRoom("/", "game", {game:obj.game}, [obj.oppsid]);
- }