From 93558b030497fb8f9760312408246e9de5116b59 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 6 Sep 2019 14:11:38 +0200 Subject: [PATCH] Handle player leaving on clients --- src/network/Client.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/network/Client.ts b/src/network/Client.ts index 1268a2d..e7c96ec 100644 --- a/src/network/Client.ts +++ b/src/network/Client.ts @@ -38,6 +38,16 @@ export abstract class Client extends EventEmitter { this.players.push(data.name); this.emit("player-joined", data.name); break; + case "player-left": + let idx = this.players.indexOf(data.name); + if (idx < 0) { + // Weird + console.warn( + `Someone (${data.name}) left but wasn't on the player list` + ); + break; + } + this.players.splice(idx, 1); default: // For most cases, we can just use the kind as event type this.emit(data.kind, data);