From ba46c18fc1d7638977892e42f22bcab6681f8144 Mon Sep 17 00:00:00 2001 From: 3944Realms Date: Tue, 26 Aug 2025 00:04:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20rconPlayerListModule=E7=9A=84Fallback?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 2 +- .../ltdmanager/module/RconPlayerListModule.kt | 10 +++++++--- src/main/kotlin/top/r3944realms/ltdmanager/test.kt | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.MD b/README.MD index 502cf9f..8149bac 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,5 @@ # 基于NapCat Http/Websocket Server API开发 -## 目标1:实现白名单申请通过后加群自动通过 +## 目标1:实现白名单申请通过后加群自动通过 (模块) ### 拆分目标: 轮询 1. 获取指定加群请求 diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/module/RconPlayerListModule.kt b/src/main/kotlin/top/r3944realms/ltdmanager/module/RconPlayerListModule.kt index 01678a5..5e08955 100644 --- a/src/main/kotlin/top/r3944realms/ltdmanager/module/RconPlayerListModule.kt +++ b/src/main/kotlin/top/r3944realms/ltdmanager/module/RconPlayerListModule.kt @@ -111,16 +111,18 @@ class RconPlayerListModule( CmdUtil.runExeCommand(rconPath, "-c", rconConfigPath, "-T", (timeout / 1000).toString() + "s", "forge tps") }.getOrElse { ex -> LoggerUtil.logger.warn("[$name] 执行 forge tps 失败: ${ex.message}") - "" + throw ex } val listOutput = runCatching { CmdUtil.runExeCommand(rconPath, "-c", rconConfigPath, "-T", (timeout / 1000).toString() + "s", "list") }.getOrElse { ex -> LoggerUtil.logger.warn("[$name] 执行 list 失败: ${ex.message}") - "" + throw ex + } + if (tpsOutput.contains("i/o timeout") || listOutput.contains("i/o timeout")) { + throw TimeoutException() } - // 合并输出,再解析 buildString { appendLine(tpsOutput.trim()) @@ -129,9 +131,11 @@ class RconPlayerListModule( } } .onFailure { ex -> if (ex is TimeoutException) { + lastSuccessTime = now // ✅ 成功后记录冷却开始时间 LoggerUtil.logger.warn("[$name] RCON 连接超时: ${ex.message}") sendFailedMessage(napCatClient, triggerMsg.realId, triggerMsg.time) } else { + lastSuccessTime = now // ✅ 成功后记录冷却开始时间 LoggerUtil.logger.error("[$name] RCON 命令执行失败", ex) sendFailedMessage( napCatClient, diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/test.kt b/src/main/kotlin/top/r3944realms/ltdmanager/test.kt index 0712644..59d8dcc 100644 --- a/src/main/kotlin/top/r3944realms/ltdmanager/test.kt +++ b/src/main/kotlin/top/r3944realms/ltdmanager/test.kt @@ -3,7 +3,6 @@ package top.r3944realms.ltdmanager import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import top.r3944realms.ltdmanager.module.GroupRequestHandlerModule -import top.r3944realms.ltdmanager.module.RconPlayerListModule import top.r3944realms.ltdmanager.utils.LoggerUtil import java.util.concurrent.atomic.AtomicBoolean