- 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)
- {
- // All seats are taken: game can start
- this.launchGame(c);
- }
- break;
- }
- case "withdrawchallenge":
- {
- const cIdx = this.challenges.findIndex(c => c.id == data.cid);
- let seats = this.challenges[cIdx].seats;
- const sIdx = seats.findIndex(s => s.sid == data.sid);
- seats[sIdx] = undefined;