- const online = (data.code == "connect");
- // If this is an opponent ?
- if (!!this.opponents[data.id])
- this.opponents[data.id].online = online;
- else
- {
- // Or an observer ?
- if (!online)
- delete this.people[data.id];
- else
- this.people[data.id] = data.name;
- }
- }
+ // Minimal game informations:
+ id: this.game.id,
+ players: this.game.players.map(p => { return {name:p.name}; }),
+ vid: this.game.vid,
+ timeControl: this.game.timeControl,
+ };
+ this.st.conn.send(JSON.stringify({code:"game",
+ game:myGame, target:data.from}));
+ break;
+ case "newmove":
+ // NOTE: this call to play() will trigger processMove()
+ this.$refs["basegame"].play(data.move,
+ "receive", this.game.vname!="Dark" ? "animate" : null);
+ break;
+ case "lastate": //got opponent infos about last move
+ {
+ this.lastate = data;
+ if (!!this.game.type) //game is loaded
+ this.processLastate();
+ //else: will be processed when game is ready
+ break;
+ }
+ case "resign":
+ this.$refs["basegame"].endGame(
+ (data.side=="b" ? "1-0" : "0-1"), "Resign");
+ break;
+ case "abort":
+ this.$refs["basegame"].endGame("?", "Abort");
+ break;
+ case "draw":
+ this.$refs["basegame"].endGame("1/2", "Mutual agreement");
+ break;
+ case "drawoffer":
+ this.drawOffer = "received"; //TODO: observers don't know who offered draw
+ break;
+ case "askfullgame":
+ this.st.conn.send(JSON.stringify({code:"fullgame", game:this.game, target:data.from}));
+ break;
+ case "fullgame":
+ // Callback "roomInit" to poll clients only after game is loaded
+ this.loadGame(data.game, this.roomInit);
+ break;
+ case "connect":
+ {
+ this.people.push({name:"", id:0, sid:data.from});
+ this.st.conn.send(JSON.stringify({code:"askidentity", target:data.from}));
+ break;
+ }
+ case "disconnect":
+ ArrayFun.remove(this.people, p => p.sid == data.from);