+ // 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 "askchallenges":
+ // Send my current challenges
+ const myChallenges = this.challenges
+ .filter(c => c.from.sid == this.st.user.sid)
+ .map(c => {
+ // Minimal challenge informations: (from not required)
+ to: c.to,
+ fen: c.fen,
+ vid: c.vid,
+ timeControl: c.timeControl
+ });
+ if (myChallenges.length > 0)
+ {
+ this.st.conn.send(JSON.stringify({code:"challenges",
+ challenges:myChallenges, target:data.from})
+ }
+ break;
+ case "askgame":
+ // TODO: Send my current live game (if any)
+ 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 "challenges":
+ // Receive challenges from some player
+ break;
+ case "games":
+ // Receive live game from some player
+ break;