From ce4d142b2d1ed418d0b3a88f4fbda593c2862a8e Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 9 Dec 2020 15:36:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E8=BF=9E=E6=8E=A5=E6=97=B6,=20=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E8=8E=B7=E5=BE=97=E7=9A=84client=E4=B8=BA=E7=A9=BA,=20?= =?UTF-8?q?=E5=88=99=E8=AE=B0=E5=BD=95=E8=AF=A5=E6=AC=A1=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 9aa17d5..f8f19d4 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -106,12 +106,17 @@ export class GeneralRoom extends Room { this.dispatcher.stop(); } - getClient(player: string | Player) { + getClient(player: string | Player): Client { + let result: Client; if (typeof player == 'string') { - return this.clients.find(client => client.sessionId == player ); + result = this.clients.find(client => client.sessionId == player ); } else { - return this.clients.find(client => client.sessionId == player.id ); + result = this.clients.find(client => client.sessionId == player.id ); } + if (!result) { + error(`无法获取id为: ${typeof player == 'string' ? player : player.id} 的客户端`) + } + return result; } /** From 8669961942f243c7b8cc034fee7af9587f61a042 Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 9 Dec 2020 15:47:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9A=82=E6=97=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=8E=89=E7=BA=BF=E9=87=8D=E8=BF=9E=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index f8f19d4..2687ab5 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -88,18 +88,18 @@ export class GeneralRoom extends Room { } //TODO: 掉线逻辑 async onLeave (client: Client, consented: boolean) { - this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE; - - try { - if (consented) { - throw new Error("consented leave"); - } - await this.allowReconnection(client, 60); - this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL; - - } catch (e) { - this.state.players.delete(client.sessionId); - } + // this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE; + // + // try { + // if (consented) { + // throw new Error("consented leave"); + // } + // await this.allowReconnection(client, 60); + // this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL; + // + // } catch (e) { + // this.state.players.delete(client.sessionId); + // } } onDispose() {