- let newGame = data.game;
- newGame.type = this.classifyObject(data.game);
- newGame.vname = newGame.vname;
- this.games.push(newGame);
- break;
- }
-// * - receive "new game": if live, store locally + redirect to game
-// * If corr: notify "new game has started", give link, but do not redirect
- case "newgame":
- {
- // Delete corresponding challenge:
- ArrayFun.remove(this.challenges, c => c.id == data.cid);
- // New game just started: data contain all informations
- this.newGame(data.gameInfo);
- break;
- }
-// * - receive "accept/withdraw/cancel challenge": apply action to challenges list
- // NOTE: challenge "socket" actions accept+withdraw only for live challenges
- case "acceptchallenge":
- {
- // Someone accept an open (or targeted) challenge
- const cIdx = this.challenges.findIndex(c => c.id == data.cid);
- let c = this.challenges[cIdx];
- if (!c.seats)
- c.seats = [...Array(c.to.length)];
- const pIdx = this.players.findIndex(p => p.sid == data.from);
- // Put this player in the first empty seat we find:
- let sIdx = 0;
- for (; sIdx<c.seats.length; sIdx++)
- {
- if (!c.seats[sIdx])
- {
- c.seats[sIdx] = this.players[pIdx];
- break;
- }
- }
- if (sIdx == c.seats.length - 1)