X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fsockets.js;h=e791293e11175cab3f6a9dd4d8ae1f3b36ad0fdd;hb=5e1bc6519d4c81aeac40aec7390c64c913cbf566;hp=65e41635d1734ec76aa4182ef5b6656cb5277673;hpb=7ebc0408a76b4a966273190a2ade49e0f97099be;p=vchess.git diff --git a/server/sockets.js b/server/sockets.js index 65e41635..e791293e 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -124,13 +124,12 @@ module.exports = function(wss) { // From Game let sockIds = {}; Object.keys(clients[page]).forEach(k => { - // Avoid polling myself: no new information to get - if (k != sid) { - sockIds[k] = {}; - Object.keys(clients[page][k]).forEach(x => { + sockIds[k] = {}; + Object.keys(clients[page][k]).forEach(x => { + // Avoid polling my tmpId: no information to get + if (k != sid || x != tmpId) sockIds[k][x] = { focus: clients[page][k][x].focus }; - }); - } + }); }); send(socket, { code: "pollclients", sockIds: sockIds }); break; @@ -139,30 +138,30 @@ module.exports = function(wss) { // From Hall let sockIds = {}; Object.keys(clients["/"]).forEach(k => { - // Avoid polling myself: no new information to get - if (k != sid) { - sockIds[k] = {}; - Object.keys(clients[page][k]).forEach(x => { + sockIds[k] = {}; + Object.keys(clients[page][k]).forEach(x => { + // Avoid polling my tmpId: no information to get + if (k != sid || x != tmpId) { sockIds[k][x] = { page: "/", focus: clients[page][k][x].focus }; - }); - } + } + }); }); // NOTE: a "gamer" could also just be an observer Object.keys(clients).forEach(p => { if (p.indexOf("/game/") >= 0) { Object.keys(clients[p]).forEach(k => { - if (k != sid) { - if (!sockIds[k]) sockIds[k] = {}; - Object.keys(clients[p][k]).forEach(x => { + if (!sockIds[k]) sockIds[k] = {}; + Object.keys(clients[p][k]).forEach(x => { + if (k != sid || x != tmpId) { sockIds[k][x] = { page: p, focus: clients[p][k][x].focus }; - }); - } + } + }); }); } }); @@ -210,6 +209,9 @@ module.exports = function(wss) { clients[page][rid][rtmpId].socket, { code: "askfullgame", from: [sid,tmpId] } ); + } else { + // I'm the only person who have the game for the moment: + send(socket, { code: "fullgame", data: { empty: true } }); } } break; @@ -238,7 +240,8 @@ module.exports = function(wss) { case "rematchoffer": case "draw": // "newgame" message can provide a page (corr Game --> Hall) - notifyRoom(obj.page || page, obj.code, {data: obj.data}, obj.excluded); + notifyRoom( + obj.page || page, obj.code, {data: obj.data}, obj.excluded); break; case "rnewgame": @@ -334,8 +337,8 @@ module.exports = function(wss) { case "lastate": { const pg = obj.target[2] || page; //required for identity and game - // NOTE: if in game we ask identity to opponent still in Hall, - // but leaving Hall, clients[pg] or clients[pg][target] could be undefined + // NOTE: if in game we ask identity to opponent still in Hall, but + // leaving Hall, clients[pg] or clients[pg][target] could be undef. if (!!clients[pg] && !!clients[pg][obj.target[0]]) { send( clients[pg][obj.target[0]][obj.target[1]].socket,