- clients[obj.target[0]][obj.target[1]].sock.send(JSON.stringify(
- {code:"asklastate",from:[sid,tmpId]}));
- break;
- case "askchallenge":
- clients[obj.target[0]][obj.target[1]].sock.send(JSON.stringify(
- {code:"askchallenge",from:[sid,tmpId]}));
- break;
- case "askgames":
- {
- // Check all clients playing, and send them a "askgame" message
- // game ID --> [ sid1 --> array of tmpIds, sid2 --> array of tmpIds]
- let gameSids = {};
- const regexpGid = /\/[a-zA-Z0-9]+$/;
- Object.keys(clients).forEach(k => {
- Object.keys(clients[k]).forEach(x => {
- if ((k != sid || x != tmpId)
- && clients[k][x].page.indexOf("/game/") >= 0)
- {
- const gid = clients[k][x].page.match(regexpGid)[0];
- if (!gameSids[gid])
- gameSids[gid] = [{k: [x]}];
- else if (k == Object.keys(gameSids[gid][0])[0])
- gameSids[gid][0][k].push(x);
- else if (gameSids[gid].length == 1)
- gameSids[gid].push({k: [x]});
- else
- Object.values(gameSids[gid][1]).push(x);
+ case "askchallenges":
+ case "askgame": {
+ const pg = obj.page || page; //required for askidentity and askgame
+ if (!!clients[pg] && !!clients[pg][obj.target]) {
+ let tmpIds = Object.keys(clients[pg][obj.target]);
+ if (obj.target == sid) {
+ // Targetting myself
+ const idx_myTmpid = tmpIds.findIndex(x => x == tmpId);
+ if (idx_myTmpid >= 0) tmpIds.splice(idx_myTmpid, 1);