From e173e8abcd15a0a64a4055f72c55989c1d24280c Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Wed, 13 Dec 2023 17:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86=E6=8C=89=E9=9C=80?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=9B=A0=E4=B8=BAsocket=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=AF=BC=E8=87=B4=E5=81=87=E6=AD=BB=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=94=A4=E9=86=92=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entity/instance/on_demand.ts | 13 ++++++------- src/i18n/language/en_us.json | 1 + src/i18n/language/zh_cn.json | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/entity/instance/on_demand.ts b/src/entity/instance/on_demand.ts index 49994b5..f2ef14c 100644 --- a/src/entity/instance/on_demand.ts +++ b/src/entity/instance/on_demand.ts @@ -67,14 +67,13 @@ export class OnDemandRunner { // create socket server this.socketServer = this.startSocketServer(port); // waiting for player connect then close socket server - await new Promise((ok, reject) => { - this.socketServer.on('close', () => { - ok(); + while (this.socketServer.listening) { + await new Promise((ok) => { + setTimeout(ok, 2000); }); - this.socketServer.on('error', (error: any) => { - reject(error); - }); - }); + } + logger.info(`${this.instance.instanceUuid} `, $t("on_demand.playerConnected")); + this.instance.println("INFO", $t("on_demand.playerConnected")); this.socketServer = null; } resolve(); diff --git a/src/i18n/language/en_us.json b/src/i18n/language/en_us.json index f0a8cc0..02068e2 100755 --- a/src/i18n/language/en_us.json +++ b/src/i18n/language/en_us.json @@ -228,6 +228,7 @@ "cantStartOnDemand": "May not a Minecraft server, unable to start on demand.", "over30minClose": "Instance has been vancant for more than 30 minutes, going to sleep...", "instanceSleeping": "Instance is sleeping, waiting for player to wake it up.", + "playerConnected": "Connection recived, waking up instance...", "start": "On demand sequence started.", "stop": "On demand sequence stopped." } diff --git a/src/i18n/language/zh_cn.json b/src/i18n/language/zh_cn.json index cd23eab..a37aa8a 100755 --- a/src/i18n/language/zh_cn.json +++ b/src/i18n/language/zh_cn.json @@ -228,6 +228,7 @@ "cantStartOnDemand": "可能由于不是Minecraft服务器,无法使用按需启动功能。", "over30minClose": "实例超过30分钟不活跃,正在进入休眠状态。", "instanceSleeping": "实例已休眠,等待玩家唤醒。", + "playerConnected": "检测到连接请求,正在唤醒实例。", "start": "已进入按需启动模式,实例将在超过30分钟不活跃后自动关闭并在玩家进入时自动开启。", "stop": "已退出按需启动模式。" }