X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Fsockets.js;h=9fa09bce2cd2b949974798915523f5df7286b6f2;hp=d00b3c898c1d5f3ce41edb5740e847c96b04896b;hb=2bb4666e276e837add0958554a11b38f7f4d9357;hpb=c7550017d88ff6eb32e2c76a271a7f9edc4a3bf6 diff --git a/server/sockets.js b/server/sockets.js index d00b3c89..9fa09bce 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -1,7 +1,4 @@ -const url = require('url'); - // Node version in Ubuntu 16.04 does not know about URL class -// NOTE: url is already transformed, without ?xxx=yyy... parts function getJsonFromUrl(url) { const query = url.substr(2); //starts with "/?" let result = {}; @@ -90,36 +87,6 @@ module.exports = function(wss) { // When page changes: doDisconnect(); break; - case "killme": { - // Self multi-connect: manual removal + disconnect - const doKill = (pg) => { - Object.keys(clients[pg][obj.sid]).forEach(x => { - send(clients[pg][obj.sid][x].socket, { code: "killed" }); - }); - delete clients[pg][obj.sid]; - }; - const disconnectFromOtherConnexion = (pg,code,o={}) => { - Object.keys(clients[pg]).forEach(k => { - if (k != obj.sid) { - Object.keys(clients[pg][k]).forEach(x => { - send( - clients[pg][k][x].socket, - Object.assign({ code: code, from: obj.sid }, o) - ); - }); - } - }); - }; - Object.keys(clients).forEach(pg => { - if (clients[pg][obj.sid]) { - doKill(pg); - disconnectFromOtherConnexion(pg, "disconnect"); - if (pg.indexOf("/game/") >= 0 && clients["/"]) - disconnectFromOtherConnexion("/", "gdisconnect", { page: pg }); - } - }); - break; - } case "pollclients": { // From Game let sockIds = {}; @@ -240,7 +207,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": @@ -318,7 +286,13 @@ module.exports = function(wss) { case "getfocus": case "losefocus": - clients[page][sid][tmpId].focus = (obj.code == "getfocus"); + if ( + !!clients[page] && + !!clients[page][sid] && + !!clients[page][sid][tmpId] + ) { + clients[page][sid][tmpId].focus = (obj.code == "getfocus"); + } if (page == "/") notifyRoom("/", obj.code, { page: "/" }, [sid]); else { // Notify game room + Hall: @@ -336,8 +310,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,