const id = query["id"];
const tmpId = query["tmpId"];
const page = query["page"];
- const notifyRoom = (page,code,obj={}) => {
- if (!clients[page]) return;
- Object.keys(clients[page]).forEach(k => {
- Object.keys(clients[page][k]).forEach(x => {
- if (k == sid && x == tmpId) return;
- send(
- clients[page][k][x].socket,
- Object.assign({ code: code, from: sid }, obj)
- );
- });
- });
- };
- // For focus events: no need to target self
- const notifyAllBut = (page,code,obj={},except) => {
+ const notifyRoom = (page, code, obj={}, except) => {
if (!clients[page]) return;
+ except = except || [];
Object.keys(clients[page]).forEach(k => {
if (except.includes(k)) return;
Object.keys(clients[page][k]).forEach(x => {
+ if (k == sid && x == tmpId) return;
send(
clients[page][k][x].socket,
Object.assign({ code: code, from: sid }, obj)
// but the requested resource can be from any tmpId (except current!)
case "askidentity":
case "asklastate":
- case "askchallenge":
+ case "askchallenges":
case "askgame":
case "askfullgame": {
const pg = obj.page || page; //required for askidentity and askgame
// Notify all room: mostly game events
case "newchat":
case "newchallenge":
- case "deletechallenge":
+ case "deletechallenge_s":
case "newgame":
case "resign":
case "abort":
case "drawoffer":
case "rematchoffer":
case "draw":
- 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});
+ notifyRoom(page, obj.code, {data: obj.data}, obj.excluded);
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});
+ // A rematch game started:
+ notifyRoom(page, "newgame", {data: obj.data});
+ // Explicitely notify Hall if gametype == corr.
+ // Live games will be polled from Hall after gconnect event.
+ if (obj.data.cadence.indexOf('d') >= 0)
+ notifyRoom("/", "newgame", {data: obj.data});
break;
case "newmove": {
case "notifynewgame":
if (!!clients["/mygames"]) {
obj.targets.forEach(t => {
- const k = t.sid || idToSid[t.uid];
+ const k = t.sid || idToSid[t.id];
if (!!clients["/mygames"][k]) {
Object.keys(clients["/mygames"][k]).forEach(x => {
send(
case "getfocus":
case "losefocus":
- if (page == "/") notifyAllBut("/", obj.code, { page: "/" }, [sid]);
+ if (page == "/") notifyRoom("/", obj.code, { page: "/" }, [sid]);
else {
// Notify game room + Hall:
- notifyAllBut(page, obj.code, {}, [sid]);
- notifyAllBut("/", obj.code, { page: page }, [sid]);
+ notifyRoom(page, obj.code, {}, [sid]);
+ notifyRoom("/", obj.code, { page: page }, [sid]);
}
break;
// Passing, relaying something: from isn't needed,
// but target is fully identified (sid + tmpId)
- case "challenge":
+ case "challenges":
case "fullgame":
case "game":
case "identity":