X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fsockets.js;h=d1489f71c394685ee45431d525c2c0d4dfb630fa;hb=584f81b93154313a3856112400b7df98e0eb2632;hp=39cf260bf44929ca9b50d07b107ee8114ea44c2f;hpb=a041d5d84031f29fc001597a9ac958d6a3e6de76;p=vchess.git diff --git a/server/sockets.js b/server/sockets.js index 39cf260b..d1489f71 100644 --- a/server/sockets.js +++ b/server/sockets.js @@ -42,10 +42,10 @@ module.exports = function(wss) { }); }; // For focus events: no need to target self - const notifyAllButMe = (page,code,obj={}) => { + const notifyAllBut = (page,code,obj={},except) => { if (!clients[page]) return; Object.keys(clients[page]).forEach(k => { - if (k == sid) return; + if (except.includes(k)) return; Object.keys(clients[page][k]).forEach(x => { send( clients[page][k][x].socket, @@ -190,13 +190,24 @@ module.exports = function(wss) { // Notify all room: mostly game events case "newchat": case "newchallenge": - case "newgame": case "deletechallenge": + case "newgame": case "resign": case "abort": case "drawoffer": + case "rematchoffer": case "draw": - notifyRoom(page, obj.code, {data: obj.data}); + if (!!obj.oppsid) + // "newgame" message from Hall: do not target players + notifyAllBut(page, "newgame", {data: obj.data}, [sid, obj.oppsid]); + else notifyRoom(page, obj.code, {data: obj.data}); + break; + + case "rnewgame": + // A rematch game started: players are already informed + notifyAllBut(page, "newgame", {data: obj.data}, [sid]); + notifyAllBut("/", "newgame", {data: obj.data}, [sid, obj.oppsid]); + notifyRoom("/mygames", "newgame", {data: obj.data}); break; case "newmove": { @@ -267,11 +278,11 @@ module.exports = function(wss) { case "getfocus": case "losefocus": - if (page == "/") notifyAllButMe("/", obj.code, { page: "/" }); + if (page == "/") notifyAllBut("/", obj.code, { page: "/" }, [sid]); else { // Notify game room + Hall: - notifyAllButMe(page, obj.code); - notifyAllButMe("/", obj.code, { page: page }); + notifyAllBut(page, obj.code, {}, [sid]); + notifyAllBut("/", obj.code, { page: page }, [sid]); } break;