+ case "connect":
+ case "gconnect":
+ // NOTE: player could have been polled earlier, but might have logged in then
+ // So it's a good idea to ask identity if he was anonymous.
+ // But only ask game / challenge if currently disconnected.
+ if (!this.people[data.from])
+ {
+ this.$set(this.people, data.from, {name:"", id:0, pages:[data.page]});
+ if (data.code == "connect")
+ this.send("askchallenge", {target:data.from});
+ else
+ this.send("askgame", {target:data.from});
+ }
+ else
+ {
+ // append page if not already in list
+ if (this.people[data.from].pages.indexOf(data.page) < 0)
+ this.people[data.from].pages.push(data.page);
+ }
+ if (this.people[data.from].id == 0)
+ this.send("askidentity", {target:data.from});
+ break;
+ case "disconnect":
+ case "gdisconnect":
+ // Disconnect means no more tmpIds:
+ if (data.code == "disconnect")
+ {
+ this.$delete(this.people, data.from);
+ // Also remove all challenges sent by this player:
+ ArrayFun.remove(this.challenges, c => c.from.sid == data.from);
+ }
+ else
+ {
+ const pidx = this.people[data.from].pages.indexOf(data.page);
+ this.people[data.from].pages.splice(pageIdx, 1);
+ if (this.people[data.from].pages.length == 0)
+ {
+ this.$delete(this.people, data.from);
+ // And all live games where he plays and no other opponent is online
+ ArrayFun.remove(this.games, g =>
+ g.type == "live" && (g.players.every(p => p.sid == data.from
+ || !this.people[p.sid])), "all");
+ }
+ }
+ break;