- // 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);
- }
- break;
- }
- case "newgame":
- {
- // TODO: next line required ?!
- //ArrayFun.remove(this.challenges, c => c.id == data.cid);
- // New game just started: data contain all information
- if (this.classifyObject(data.gameInfo) == "live")
- this.startNewGame(data.gameInfo);
- else
+ // NOTE about next condition: see "askchallenge" case.
+ const chall = data.data;
+ if (!chall.to || (this.people[chall.from].id > 0 &&
+ (chall.from == this.st.user.sid || chall.to == this.st.user.name)))