+ 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, obj.oppsid]);
+ notifyAllBut("/", "newgame", {data: obj.data}, [sid, obj.oppsid]);
+ notifyRoom("/mygames", "newgame", {data: obj.data});
+ break;
+
+ case "newmove": {
+ const dataWithFrom = { from: [sid,tmpId], data: obj.data };
+ // Special case re-send newmove only to opponent:
+ if (!!obj.target && !!clients[page][obj.target]) {
+ Object.keys(clients[page][obj.target]).forEach(x => {
+ send(
+ clients[page][obj.target][x].socket,
+ Object.assign({ code: "newmove" }, dataWithFrom)
+ );
+ });
+ } else {
+ // NOTE: data.from is useful only to opponent
+ notifyRoom(page, "newmove", dataWithFrom);
+ }
+ break;
+ }
+ case "gotmove":
+ if (
+ !!clients[page][obj.target[0]] &&
+ !!clients[page][obj.target[0]][obj.target[1]]
+ ) {
+ send(
+ clients[page][obj.target[0]][obj.target[1]].socket,
+ { code: "gotmove" }
+ );
+ }
+ break;
+
+ case "result":
+ // Special case: notify all, 'transroom': Game --> Hall
+ notifyRoom("/", "result", { gid: obj.gid, score: obj.score });
+ break;
+
+ case "mconnect":
+ // Special case: notify some game rooms that
+ // I'm watching game state from MyGames
+ // TODO: this code is ignored for now
+ obj.gids.forEach(gid => {
+ const pg = "/game/" + gid;
+ Object.keys(clients[pg]).forEach(s => {
+ Object.keys(clients[pg][s]).forEach(x => {
+ send(
+ clients[pg][s][x].socket,
+ { code: "mconnect", from: sid }
+ );
+ });
+ });
+ });
+ break;
+ case "mdisconnect":
+ // TODO
+ // Also TODO: pass newgame to MyGames, and gameover (result)
+ break;
+ case "mabort": {
+ const gamePg = "/game/" + obj.gid;
+ if (!!clients[gamePg] && !!clients[gamePg][obj.target]) {
+ Object.keys(clients[gamePg][obj.target]).forEach(x => {
+ send(
+ clients[gamePg][obj.target][x].socket,
+ { code: "abort" }
+ );
+ });
+ }
+ break;
+ }
+
+ case "getfocus":
+ case "losefocus":
+ if (page == "/") notifyAllBut("/", obj.code, { page: "/" }, [sid]);
+ else {
+ // Notify game room + Hall:
+ notifyAllBut(page, obj.code, {}, [sid]);
+ notifyAllBut("/", obj.code, { page: page }, [sid]);
+ }