+ // 0.2] Receive clients list (just socket IDs)
+ case "pollclients":
+ data.sockIds.forEach(sid => {
+ this.players.push({sid:sid, id:0, name:""});
+ // Ask identity, challenges and game(s)
+ this.st.conn.send(JSON.stringify({code:"askidentity", target:sid}));
+ this.st.conn.send(JSON.stringify({code:"askchallenges", target:sid}));
+ this.st.conn.send(JSON.stringify({code:"askgame", target:sid}));
+ });
+ break;
+ case "askidentity":
+ // Request for identification
+ this.st.conn.send(JSON.stringify(
+ {code:"identity", user:this.st.user, target:data.from}));
+ break;
+ case "askchallenge":
+ // Send my current live challenge
+ const cIdx = this.challenges
+ .findIndex(c => c.from.sid == this.st.user.sid && c.liveGame);
+ if (cIdx >= 0)
+ {
+ const c = this.challenges[cIdx];
+ const myChallenge =
+ {
+ // Minimal challenge informations: (from not required)
+ to: c.to,
+ fen: c.fen,
+ vid: c.vid,
+ timeControl: c.timeControl
+ };
+ this.st.conn.send(JSON.stringify({code:"challenge",
+ challenge:myChallenge, target:data.from})
+ }
+ break;
+ case "askgame":
+ // TODO: Send my current live game (if any): variant, players, movesCount
+ break;
+ case "identity":
+ if (data.user.id > 0) //otherwise "anonymous", nothing to retrieve
+ {
+ const pIdx = this.players.findIndex(p => p.sid == data.user.sid);
+ this.players[pIdx].id = data.user.id;
+ this.players[pIdx].name = data.user.name;
+ }
+ break;
+ case "challenge":
+ // Receive challenge from some player (+sid)
+ break;
+ case "game":
+ // Receive live game from some player (+sid)
+ break;