- this.st.conn.send(JSON.stringify({code:"challenge",
- chall:myChallenge, target:data.from}));
- }
- break;
- }
- case "challenge":
- {
- // Receive challenge from some player (+sid)
- let newChall = data.chall;
- newChall.type = this.classifyObject(data.chall);
- newChall.from =
- Object.assign({sid:data.from}, this.people[data.from]);
- newChall.added = Date.now(); //TODO: this is reception timestamp, not creation
- newChall.vname = this.getVname(newChall.vid);
- this.challenges.push(newChall);
- break;
- }
- case "game":
- {
- // Receive game from some player (+sid)
- // NOTE: it may be correspondance (if newgame while we are connected)
- // If duplicate found: select rid (remote ID) at random
- let game = this.games.find(g => g.id == data.game.id);
- if (!!game && Math.random() < 0.5)
- game.rid = data.from;
- else
- {
- let newGame = data.game;
- newGame.type = this.classifyObject(data.game);
- newGame.vname = this.getVname(data.game.vid);
- newGame.rid = data.from;
- newGame.score = "*";
- this.games.push(newGame);