X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Fsockets.js;h=1cc47aeb454eb2bb6889a00cac891d4574a9d5bb;hp=3fb7ea2a8c3fe69f9b1bb12516073f826d31670b;hb=910d631b73cad5ffef1b4461157b704e7e7057d8;hpb=6808d7a16ec1e761c6a2dffec2281c96953e4d89 diff --git a/server/sockets.js b/server/sockets.js index 3fb7ea2a..1cc47aeb 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -152,15 +152,22 @@ module.exports = function(wss) { case "askfullgame": { const pg = obj.page || page; //required for askidentity and askgame - const tmpIds = Object.keys(clients[pg][obj.target]); - if (obj.target == sid) //targetting myself + // In cas askfullgame to wrong SID for example, would crash: + if (!!clients[pg][obj.target]) { - const idx_myTmpid = tmpIds.findIndex(x => x == tmpId); - if (idx_myTmpid >= 0) - tmpIds.splice(idx_myTmpid, 1); + const 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); + } + const tmpId_idx = Math.floor(Math.random() * tmpIds.length); + send( + clients[pg][obj.target][tmpIds[tmpId_idx]], + {code:obj.code, from:[sid,tmpId,page]} + ); } - const tmpId_idx = Math.floor(Math.random() * tmpIds.length); - send(clients[pg][obj.target][tmpIds[tmpId_idx]], {code:obj.code, from:[sid,tmpId,page]}); break; }