Fix rename messages assuming having joined
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Hamcha 2019-10-15 14:36:29 +02:00
parent 3a5989ea0d
commit 07d5e9b2ba
Signed by: hamcha
GPG Key ID: 44AD3571EB09A39E
1 changed files with 14 additions and 9 deletions

View File

@ -29,16 +29,21 @@ export abstract class Client extends EventEmitter {
this.metadata.name = data.newname;
}
let idx = this.players.indexOf(data.oldname);
if (idx < 0) {
// Weird
console.warn(
`Someone (${data.oldname}) changed name but wasn't on the player list`
);
this.players.push(data.newname);
break;
// Only mutate player list if we have one
// This is because rename messages can be received during the initial
// handshake, to signal a forced name change before joining.
if (this.players) {
let idx = this.players.indexOf(data.oldname);
if (idx < 0) {
// Weird
console.warn(
`Someone (${data.oldname}) changed name but wasn't on the player list`
);
this.players.push(data.newname);
break;
}
Vue.set(this.players, idx, data.newname);
}
Vue.set(this.players, idx, data.newname);
this.emit("rename", data.oldname, data.newname);
break;
// A new player joined the room (this includes us)