dsh-mc-server-ops 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +62 -9
  2. package/client.js +69 -0
  3. package/index.js +208 -7
  4. package/package.json +8 -1
package/README.md CHANGED
@@ -1,12 +1,26 @@
1
1
  # dsh-mc-server-ops
2
2
 
3
- 把一台 **Minecraft 服务器**托管到 [DeepSeek Harness](https://github.com/deepseek-ai) 里的插件:QQ 群里的群友可以直接查状态、看日志、绑定游戏名,服主可以启停服务器、改配置、修 KubeJS 配方。
3
+ [![npm version](https://img.shields.io/npm/v/dsh-mc-server-ops.svg)](https://www.npmjs.com/package/dsh-mc-server-ops)
4
+ [![npm downloads](https://img.shields.io/npm/dm/dsh-mc-server-ops.svg)](https://www.npmjs.com/package/dsh-mc-server-ops)
5
+ [![license](https://img.shields.io/npm/l/dsh-mc-server-ops.svg)](https://github.com/mogutofu/dsh-mc-server-ops/blob/main/LICENSE)
6
+ [![DSH](https://img.shields.io/badge/DeepSeek%20Harness-%E2%89%A50.2.0-blue)](https://github.com/deepseek-ai)
4
7
 
5
- > 插件本身只是「服务器操作 + 人设」这一层,**聊天通道由 QQ 机器人插件提供**。
6
- > 安装前请先装好并配置 `@tencent-connect/dsh-qqbot`(见下方「前置插件」),否则装上了也没有入口。
8
+ **在 QQ 群里管理 Minecraft 服务器。** 服主不用开电脑、不用记命令——群里发一句话,就能查状态、启停服务器、绑白名单、投票授权;游戏聊天还能直通 QQ 群,不经过 AI、不耗 token。
9
+
10
+ > 当前版本 **0.5.2** · 更新于 **2026-11-07** · 以本页和 [npm](https://www.npmjs.com/package/dsh-mc-server-ops) 为准
11
+
12
+ ## 它解决什么问题
13
+
14
+ - **服主不在电脑前**:群里问一句「服务器卡吗」,直接回 TPS、在线玩家、CPU、内存、磁盘
15
+ - **朋友想自己开服**:服务器确认关闭或假死时,群友也能重启,不用等服主
16
+ - **改东西怕手滑**:动 world / ops\data / 白名单要 2 位群友投票,凑不满就作废
17
+ - **群里看不到游戏里聊啥**:游戏聊天直通 QQ 群,不经过 AI、不耗 token
18
+ - **一条命令搞崩服**:`kill @a`、`whitelist off` 这类静态拦截,服主也发不出去
7
19
 
8
20
  ## 前置插件(必须)
9
21
 
22
+ 插件本身只是「服务器操作 + 人设」这一层,**聊天通道由 QQ 机器人插件提供**。安装前请先装好并配置 `@tencent-connect/dsh-qqbot`(见下方表格),否则装上了也没有入口。
23
+
10
24
  | 插件 | 作用 | 获取 |
11
25
  | --- | --- | --- |
12
26
  | `@tencent-connect/dsh-qqbot` | QQ 群/私聊通道:把群消息送进 Harness,把回复发回群里 | npm / DSH 插件市场 |
@@ -41,6 +55,22 @@ dsh plugin add /path/to/dsh-mc-server-ops
41
55
 
42
56
  安装后重启 DSH,在「设置 → 插件 → mc-server-ops」里填服务器目录。
43
57
 
58
+ ## 检查更新
59
+
60
+ 设置面板最上面有一条更新栏,**强制开启、没有开关**:
61
+
62
+ ```
63
+ 当前版本号为 0.5.1 [检查更新]
64
+ [新版本 v0.6.0] [检查更新]
65
+ ```
66
+
67
+ - 面板一打开就自动查一次,**npm 优先**(`registry.npmjs.org/<包名>/latest`),npm 不通才问 GitHub 的 `releases/latest`。
68
+ - 有新版本时按钮变成可点的「新版本 vX」。点一下自动更新:先走 npm,失败再走 GitHub 的 tag tarball,都失败才提示「下载失败,请手动更新」。
69
+ - 没有新版本时显示纯文本「当前版本号为 X」,不可点击。
70
+ - 右边的「检查更新」是手动重查,结果会以文字提示(「已经是最新版本」/「发现新版本」)。
71
+
72
+ 两个前提:更新用的是 DSH 自带的 pnpm,所以要有写 profile 目录的权限;如果是 `link:` 本地安装(开发模式),自动更新会断开链接,插件会直接提示手动更新。
73
+
44
74
  ## 配置(设置界面可改)
45
75
 
46
76
  | 字段 | 默认 | 说明 |
@@ -63,17 +93,17 @@ dsh plugin add /path/to/dsh-mc-server-ops
63
93
  | `vote.timeoutMinutes` | `15` | 多久没凑够门槛自动作废 |
64
94
  | `vote.vetoEnabled` | `true` | 是否允许一票否决;关掉后反对票只记录、不作废 |
65
95
  | `vote.protectedPaths` | `world, ops/data, whitelist` | 改动这些位置需要群友投票放行 |
66
- | `bridge.enabled` | `false` | 是否启用群服互通(游戏聊天 → QQ 群) |
96
+ | `bridge.enabled` | `true` | 是否启用群服互通(游戏聊天 → QQ 群) |
67
97
  | `bridge.mode` | `auto` | `auto` 有玩家在线才转发 / `on` 常开 / `off` 常关 |
68
98
  | `bridge.groups` | `[]` | 转发到哪些群(群 openid) |
69
- | `bridge.events` | `join/leave` 关、`death` 开 | 除聊天外还转发哪些事件 |
99
+ | `bridge.events` | 三项都关 | 除聊天外还转发哪些事件(进出服和死亡默认不转,防刷屏) |
70
100
  | `bridge.coalesceMs` | `3000` | 固定合并窗口(`coalesce.mode=fixed` 时用) |
71
101
  | `bridge.coalesce.mode` | `auto` | 合并窗口:`auto` 按最近发言节奏 + 在线人数自动调整 / `fixed` 固定 |
72
- | `bridge.coalesce.minMs` / `maxMs` | `1000` / `6000` | 自动模式的最短 / 最长等待 |
102
+ | `bridge.coalesce.minMs` / `maxMs` | `1000` / `60000` | 自动模式的最短 / 最长等待 |
73
103
  | `bridge.coalesce.sampleSize` | `3` | 用最近几条发言算节奏(2–6) |
74
- | `bridge.coalesce.quietMs` | `20000` | 超过这么久没说话算冷场,直接按最短等待 |
75
- | `bridge.coalesce.fullPlayers` | `6` | 在线人数达到这个值算「人多」 |
76
- | `bridge.coalesce.fastMs` | `2000` | 相邻两条发言间隔小于这个值算「话密」 |
104
+ | `bridge.coalesce.quietMs` | `60000` | 超过这么久没说话算冷场,直接按最短等待 |
105
+ | `bridge.coalesce.fullPlayers` | `2` | 在线人数达到这个值算「人多」 |
106
+ | `bridge.coalesce.fastMs` | `50000` | 相邻两条发言间隔小于这个值算「话密」 |
77
107
  | `bridge.maxPerDay` | `900` | 每群每天发送上限(官方上限 1000) |
78
108
  | `bridge.appId` / `appSecret` | 空 | 留空自动从本机 qqbot 插件配置读取 |
79
109
 
@@ -270,6 +300,29 @@ TPS 也是按服务端自动探测:`forge tps` → `tps`(Paper/Spigot)→
270
300
  - **投票超时**:已实现。`vote.timeoutMinutes`(默认 15)到点没凑够门槛会自动标成 `expired`,不再占「同时最多 3 个待确认投票」的名额。
271
301
  - **人设注入范围**:按会话 id 前缀判断(`session-*` 是本机界面),是启发式;如果 DSH 以后改会话 id 规则,这里要跟着调。
272
302
 
303
+ ## FAQ
304
+
305
+ **这是什么?**
306
+ 一个 DSH 插件,让服主和群友在 QQ 群里直接管理 Minecraft 服务器:查状态、启停、绑白名单、投票授权、群服互通。
307
+
308
+ **支持哪些服务端?**
309
+ Paper / Spigot / Purpur / Folia / Leaves、Forge / NeoForge / Fabric / Quilt、Arclight / Mohist / Cardboard / Youer / Banner、vanilla,以及任意 `run.bat` 启动的服。插件只看端口、RCON 和进程,不假设服务端类型。
310
+
311
+ **需要公网 IP 吗?**
312
+ 不需要。插件在本机连 RCON(默认 25575)和读日志,服务器不用暴露到公网;QQ 侧走官方机器人 API。
313
+
314
+ **安全吗?群友会不会乱来?**
315
+ 三层:静态命令拦截(`kill @a`、`whitelist off` 这类谁都发不了)、投票放行(动 world / ops\data / 白名单要 2 位群友同意,凑不满前 1 票反对就作废)、服主名单(高危操作只有名单里的 QQ 能做)。拦截在插件层和 PowerShell 层各生效一次。
316
+
317
+ **支持 Linux / macOS 吗?**
318
+ 只读操作和启停已经跨平台(`ops/rcon.mjs` 是纯 Node);投票、白名单、绑定、KubeJS 这些写数据的动作还在 Windows 上,在别的平台调用会明确提示,不会报「找不到 PowerShell」。
319
+
320
+ **和 Pterodactyl 面板什么关系?**
321
+ `adapter=panel` 时,start / stop / restart / cmd 走 Pterodactyl 客户端 API;只读操作不经过适配器。要接 Pelican / AMP / PufferPanel 只需再写一个适配器文件。
322
+
323
+ **群服互通会消耗 token 吗?**
324
+ 不会。桥直接读日志、直接调 QQ 开放平台,不创建 agent 会话、不调模型。只有群友真的问问题时才走 AI。
325
+
273
326
  ## License
274
327
 
275
328
  MIT
package/client.js CHANGED
@@ -5,6 +5,7 @@ window.__ModuleLoader__.load({
5
5
  const h = react.createElement
6
6
  const PACKAGE_NAME = "dsh-mc-server-ops"
7
7
  const ENDPOINT = "/mc-ops/config"
8
+ const UPDATE_ENDPOINT = "/mc-ops/update"
8
9
 
9
10
  const box = { display: "flex", flexDirection: "column", gap: 10 }
10
11
  const row = { display: "flex", flexDirection: "column", gap: 4 }
@@ -70,6 +71,7 @@ window.__ModuleLoader__.load({
70
71
  const [owners, setOwners] = react.useState([])
71
72
  const [bridgeState, setBridgeState] = react.useState(null)
72
73
  const [newOwner, setNewOwner] = react.useState("")
74
+ const [upd, setUpd] = react.useState({ checking: true, info: null, busy: false, msg: "" })
73
75
 
74
76
  react.useEffect(() => {
75
77
  void load()
@@ -78,6 +80,47 @@ window.__ModuleLoader__.load({
78
80
  return () => clearInterval(timer)
79
81
  }, [])
80
82
 
83
+ react.useEffect(() => { void checkUpdate(false) }, [])
84
+
85
+ // 强制开启的更新检查:面板一打开就问一次 npm(失败再问 GitHub)
86
+ async function checkUpdate(manual) {
87
+ setUpd((prev) => Object.assign({}, prev, { checking: true, msg: manual ? "" : prev.msg }))
88
+ try {
89
+ const res = await fetch(UPDATE_ENDPOINT, { cache: "no-store", headers: { "x-mc-ops-client": "1" } })
90
+ const data = await res.json()
91
+ if (!res.ok) throw new Error(data.error || ("HTTP " + res.status))
92
+ setUpd({
93
+ checking: false,
94
+ info: data,
95
+ busy: false,
96
+ msg: manual
97
+ ? (data.hasUpdate
98
+ ? "发现新版本 v" + data.latest + "(当前 " + data.current + ")"
99
+ : "已经是最新版本(" + data.current + ")")
100
+ : "",
101
+ })
102
+ } catch (err) {
103
+ setUpd({ checking: false, info: null, busy: false, msg: "检查更新失败:" + String(err && err.message ? err.message : err) })
104
+ }
105
+ }
106
+
107
+ async function doUpdate() {
108
+ const info = upd.info
109
+ if (!info || !info.latest) return
110
+ setUpd((prev) => Object.assign({}, prev, { busy: true, msg: "正在下载 v" + info.latest + " …" }))
111
+ try {
112
+ const res = await fetch(UPDATE_ENDPOINT, {
113
+ method: "POST",
114
+ headers: { "content-type": "application/json", "x-mc-ops-client": "1" },
115
+ body: JSON.stringify({ version: info.latest }),
116
+ })
117
+ const data = await res.json()
118
+ setUpd((prev) => Object.assign({}, prev, { busy: false, msg: data.text || (res.ok ? "已更新" : "更新失败,请手动更新。") }))
119
+ } catch (err) {
120
+ setUpd((prev) => Object.assign({}, prev, { busy: false, msg: "下载失败,请手动更新。" }))
121
+ }
122
+ }
123
+
81
124
  async function refreshState() {
82
125
  try {
83
126
  const res = await fetch(ENDPOINT, { cache: "no-store", headers: { "x-mc-ops-client": "1" } })
@@ -233,7 +276,33 @@ window.__ModuleLoader__.load({
233
276
  status.error ? h("span", { style: Object.assign({}, statusStyle, { color: "#d9534f" }) }, status.error) : null)
234
277
  }
235
278
 
279
+ const updateRow = h("div", {
280
+ style: {
281
+ display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap",
282
+ padding: "10px 12px", borderRadius: 8, background: "rgba(127,127,127,0.10)", marginBottom: 12,
283
+ },
284
+ },
285
+ upd.checking
286
+ ? h("span", { style: hintStyle }, "正在检查更新…")
287
+ : (upd.info && upd.info.hasUpdate)
288
+ ? h("button", {
289
+ type: "button",
290
+ style: Object.assign({}, buttonStyle, { background: "#2f7de1", color: "#fff", border: "1px solid #2f7de1", fontWeight: 600 }),
291
+ disabled: upd.busy,
292
+ onClick: () => void doUpdate(),
293
+ }, upd.busy ? "更新中…" : ("新版本 v" + upd.info.latest))
294
+ : h("span", { style: hintStyle }, "当前版本号为 " + ((upd.info && upd.info.current) || "?")),
295
+ h("button", {
296
+ type: "button",
297
+ style: Object.assign({}, buttonStyle, { padding: "3px 10px", fontSize: 12 }),
298
+ disabled: upd.busy || upd.checking,
299
+ onClick: () => void checkUpdate(true),
300
+ }, "检查更新"),
301
+ upd.msg ? h("span", { style: hintStyle }, upd.msg) : null,
302
+ )
303
+
236
304
  return h("div", { style: box },
305
+ updateRow,
237
306
  actions(),
238
307
  h("div", null,
239
308
  h("div", { style: titleStyle }, "服主绑定"),
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'node:child_process'
2
- import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from 'node:fs'
2
+ import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, lstatSync } from 'node:fs'
3
3
  import { dirname, join } from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import Schema from '@deepseek-ai/schemastery'
@@ -206,6 +206,8 @@ export const name = 'mc-server-ops'
206
206
  export const inject = ['tools']
207
207
  // 诊断/测试用:判断某个路径是否落在受保护区域,以及临时改一份受保护清单
208
208
  export { isProtectedPath, setProtectedPaths }
209
+ // 诊断/测试用:版本比较与「查最新版本」
210
+ export { compareVersions, checkLatestVersion }
209
211
 
210
212
  const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
211
213
  // 跨平台的只读动作:Windows 上走 PowerShell(信息更全),其它平台走 Node 核心
@@ -263,7 +265,7 @@ export const Config = Schema.object({
263
265
  }).description('Pterodactyl 面板(adapter 选 panel 时才用)'),
264
266
 
265
267
  bridge: Schema.object({
266
- enabled: Schema.boolean().default(false)
268
+ enabled: Schema.boolean().default(true)
267
269
  .description('群服互通:把游戏内聊天直接转发到 QQ 群。不经过 AI,不消耗 token'),
268
270
  mode: Schema.union(['auto', 'on', 'off']).default('auto')
269
271
  .description('auto=有玩家在线才转发(默认);on=常开;off=常关'),
@@ -274,7 +276,7 @@ export const Config = Schema.object({
274
276
  events: Schema.object({
275
277
  join: Schema.boolean().default(false).description('转发玩家加入(默认关,容易刷屏)'),
276
278
  leave: Schema.boolean().default(false).description('转发玩家离开(默认关,容易刷屏)'),
277
- death: Schema.boolean().default(true).description('转发死亡消息(默认开)'),
279
+ death: Schema.boolean().default(false).description('转发死亡消息(默认关)'),
278
280
  }).description('除聊天外还要转发哪些事件'),
279
281
  coalesceMs: Schema.number().default(3000)
280
282
  .description('固定合并窗口(毫秒);合并模式选「固定」时用这个值'),
@@ -282,16 +284,210 @@ export const Config = Schema.object({
282
284
  mode: Schema.union(['auto', 'fixed']).default('auto')
283
285
  .description('合并窗口:auto=按最近发言节奏和在线人数自动调整(默认);fixed=固定用 coalesceMs'),
284
286
  minMs: Schema.number().default(1000).description('自动模式最短等待(毫秒),冷场时用'),
285
- maxMs: Schema.number().default(6000).description('自动模式最长等待(毫秒),最多攒这么久就发'),
287
+ maxMs: Schema.number().default(60000).description('自动模式最长等待(毫秒),最多攒这么久就发'),
286
288
  sampleSize: Schema.number().default(3).description('参考最近几条发言算节奏(2-6)'),
287
- quietMs: Schema.number().default(20000).description('超过这么久没说话就算冷场(毫秒)'),
288
- fullPlayers: Schema.number().default(6).description('在线人数达到这个值算满档'),
289
- fastMs: Schema.number().default(2000).description('相邻两条发言间隔小于这个值算满活跃(毫秒)'),
289
+ quietMs: Schema.number().default(60000).description('超过这么久没说话就算冷场(毫秒)'),
290
+ fullPlayers: Schema.number().default(2).description('在线人数达到这个值算满档'),
291
+ fastMs: Schema.number().default(50000).description('相邻两条发言间隔小于这个值算满活跃(毫秒)'),
290
292
  }).description('合并窗口自动调整:人少话稀就快发,人多话密就多攒一会儿'),
291
293
  maxPerDay: Schema.number().default(900).description('每个群每天最多发几条(官方上限 1000,留余量)'),
292
294
  }).description('群服互通'),
293
295
  })
294
296
 
297
+ // ─────────────────────── 检查更新 / 自更新 ───────────────────────
298
+
299
+ const PKG_NAME = 'dsh-mc-server-ops'
300
+ const GH_REPO = 'mogutofu/dsh-mc-server-ops'
301
+ const NPM_LATEST_URL = 'https://registry.npmjs.org/' + PKG_NAME + '/latest'
302
+ const GH_LATEST_URL = 'https://api.github.com/repos/' + GH_REPO + '/releases/latest'
303
+
304
+ function homeDir() { return process.env.USERPROFILE || process.env.HOME || '' }
305
+
306
+ /** 当前安装的版本(读包内 package.json)。 */
307
+ function localVersion() {
308
+ try {
309
+ return String(JSON.parse(readFileSync(join(SCRIPT_DIR, 'package.json'), 'utf8')).version || '')
310
+ } catch { return '' }
311
+ }
312
+
313
+ /** 语义化版本比较:a>b 返回 1,a<b 返回 -1,相等 0。只处理 x.y.z[-pre]。 */
314
+ function compareVersions(a, b) {
315
+ const parse = (v) => {
316
+ const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(String(v || '').trim())
317
+ return m ? { n: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] || '' } : null
318
+ }
319
+ const pa = parse(a), pb = parse(b)
320
+ if (!pa || !pb) return 0
321
+ for (let i = 0; i < 3; i++) {
322
+ if (pa.n[i] !== pb.n[i]) return pa.n[i] > pb.n[i] ? 1 : -1
323
+ }
324
+ if (pa.pre === pb.pre) return 0
325
+ if (!pa.pre) return 1
326
+ if (!pb.pre) return -1
327
+ return pa.pre > pb.pre ? 1 : -1
328
+ }
329
+
330
+ async function fetchJson(url, ms = 8000) {
331
+ const res = await fetch(url, {
332
+ headers: { 'user-agent': PKG_NAME, accept: 'application/json' },
333
+ signal: AbortSignal.timeout ? AbortSignal.timeout(ms) : undefined,
334
+ })
335
+ if (!res.ok) throw new Error('HTTP ' + res.status)
336
+ return res.json()
337
+ }
338
+
339
+ /** 依次问 npm / GitHub,返回最新版本。npm 优先。 */
340
+ async function checkLatestVersion() {
341
+ const current = localVersion()
342
+ const errors = []
343
+ let latest = ''
344
+ let source = ''
345
+ try {
346
+ const doc = await fetchJson(NPM_LATEST_URL)
347
+ latest = String(doc.version || '')
348
+ if (latest) source = 'npm'
349
+ } catch (error) {
350
+ errors.push('npm ' + (error && error.message ? error.message : String(error)))
351
+ }
352
+ if (!latest) {
353
+ try {
354
+ const doc = await fetchJson(GH_LATEST_URL)
355
+ latest = String(doc.tag_name || '').replace(/^v/i, '')
356
+ if (latest) source = 'github'
357
+ } catch (error) {
358
+ errors.push('github ' + (error && error.message ? error.message : String(error)))
359
+ }
360
+ }
361
+ return {
362
+ current,
363
+ latest,
364
+ source,
365
+ hasUpdate: !!latest && compareVersions(latest, current) > 0,
366
+ error: latest ? '' : ('检查失败:' + errors.join(';')),
367
+ }
368
+ }
369
+
370
+ /** 找到装着本插件的 profile 目录。 */
371
+ function findProfileDir() {
372
+ const self = SCRIPT_DIR.replace(/\\/g, '/')
373
+ const m = /\/profiles\/([^/]+)\/node_modules\//.exec(self)
374
+ const home = homeDir()
375
+ if (m && home) return { name: m[1], dir: join(home, '.dsh', 'profiles', m[1]) }
376
+ const root = home ? join(home, '.dsh', 'profiles') : ''
377
+ if (!root || !existsSync(root)) return null
378
+ try {
379
+ for (const name of readdirSync(root)) {
380
+ const file = join(root, name, 'cordis.patch.yml')
381
+ if (!existsSync(file)) continue
382
+ if (readFileSync(file, 'utf8').includes(PKG_NAME)) return { name, dir: join(root, name) }
383
+ }
384
+ } catch { /* 扫不动就算了 */ }
385
+ return null
386
+ }
387
+
388
+ function findDshCli() {
389
+ const dir = dirname(process.execPath)
390
+ const candidates = [
391
+ join(dir, 'resources', 'runtime', 'cli', 'bin', 'dsh.cmd'),
392
+ join(dir, 'resources', 'runtime', 'cli', 'bin', 'dsh'),
393
+ ]
394
+ return candidates.find((p) => existsSync(p)) || ''
395
+ }
396
+
397
+ function findPnpmRunner() {
398
+ const dir = dirname(process.execPath)
399
+ const home = homeDir()
400
+ const candidates = [
401
+ join(dir, 'resources', 'runtime', 'primary-runtime', 'dependencies', 'pnpm', 'bin', 'pnpm.mjs'),
402
+ join(home, '.dsh', 'dsh-runtimes', 'dsh-primary-runtime', 'dependencies', 'pnpm', 'bin', 'pnpm.mjs'),
403
+ ]
404
+ return candidates.find((p) => existsSync(p)) || ''
405
+ }
406
+
407
+ function runCommand(file, args, timeoutMs) {
408
+ return new Promise((resolve) => {
409
+ let child
410
+ try {
411
+ const isCmd = /\.cmd$/i.test(file)
412
+ child = isCmd
413
+ ? spawn('cmd.exe', ['/c', file, ...args], { windowsHide: true })
414
+ : spawn(file, args, { windowsHide: true })
415
+ } catch (error) {
416
+ resolve({ ok: false, text: String(error && error.message ? error.message : error) })
417
+ return
418
+ }
419
+ const out = []
420
+ const err = []
421
+ const timer = setTimeout(() => { try { child.kill() } catch { } }, timeoutMs)
422
+ child.stdout.on('data', (d) => out.push(Buffer.from(d)))
423
+ child.stderr.on('data', (d) => err.push(Buffer.from(d)))
424
+ child.on('error', (e) => { clearTimeout(timer); resolve({ ok: false, text: String(e && e.message ? e.message : e) }) })
425
+ child.on('close', (code) => {
426
+ clearTimeout(timer)
427
+ const text = (Buffer.concat(err).toString('utf8') + '\n' + Buffer.concat(out).toString('utf8')).trim()
428
+ resolve({ ok: code === 0, text: text.slice(-600) })
429
+ })
430
+ })
431
+ }
432
+
433
+ /**
434
+ * 执行更新:先 npm,失败再 GitHub 的 tag tarball。
435
+ * 本机是 link: 安装(开发模式)时不动,避免把链接换掉。
436
+ */
437
+ async function performUpdate(targetVersion) {
438
+ const version = String(targetVersion || '').trim()
439
+ if (!version) return { ok: false, text: '没有可用的版本号,请先点「检查更新」。' }
440
+ const profile = findProfileDir()
441
+ if (!profile) return { ok: false, text: '找不到安装目录,请手动更新。' }
442
+ try {
443
+ const target = join(profile.dir, 'node_modules', PKG_NAME)
444
+ if (existsSync(target) && lstatSync(target).isSymbolicLink()) {
445
+ return { ok: false, text: '当前是本地链接安装(开发模式),自动更新会断开链接,请手动更新。' }
446
+ }
447
+ } catch { /* 判断不了就继续尝试 */ }
448
+
449
+ const attempts = [
450
+ { label: 'npm', spec: PKG_NAME + '@' + version },
451
+ { label: 'github', spec: 'https://codeload.github.com/' + GH_REPO + '/tar.gz/refs/tags/v' + version },
452
+ ]
453
+ const cli = findDshCli()
454
+ const pnpm = findPnpmRunner()
455
+ if (!cli && !pnpm) return { ok: false, text: '找不到 DSH 自带的包管理器,请手动更新。' }
456
+
457
+ let lastError = ''
458
+ for (const attempt of attempts) {
459
+ const result = cli
460
+ ? await runCommand(cli, ['plugin', '--profile', profile.name, 'add', attempt.spec], 240000)
461
+ : await runCommand(process.execPath, ['--expose-internals', pnpm, 'add', attempt.spec, '--dir', profile.dir], 240000)
462
+ if (result.ok) {
463
+ return { ok: true, text: '已更新到 ' + version + '(来源 ' + attempt.label + '),重启 DSH 生效。' }
464
+ }
465
+ lastError = attempt.label + ': ' + String(result.text || '').replace(/\s+/g, ' ').slice(0, 160)
466
+ }
467
+ return { ok: false, text: '下载失败,请手动更新。(' + lastError + ')' }
468
+ }
469
+
470
+ /** /mc-ops/update:GET 检查版本,POST 执行更新。 */
471
+ async function handleUpdateRoute(req, res) {
472
+ const send = (code, obj) => {
473
+ try {
474
+ res.statusCode = code
475
+ res.setHeader('content-type', 'application/json; charset=utf-8')
476
+ res.end(JSON.stringify(obj))
477
+ } catch { }
478
+ }
479
+ if (String(req.headers['x-mc-ops-client'] || '') !== '1') return send(403, { error: '只接受来自设置面板的请求' })
480
+ if (req.method === 'GET') {
481
+ try { return send(200, await checkLatestVersion()) }
482
+ catch (error) { return send(500, { error: String(error && error.message ? error.message : error) }) }
483
+ }
484
+ if (req.method !== 'POST') return send(405, { error: '只支持 GET / POST' })
485
+ const body = await readJsonBody(req)
486
+ if (!body) return send(400, { error: '请求体不是合法 JSON' })
487
+ const result = await performUpdate(body.version)
488
+ return send(result.ok ? 200 : 500, result)
489
+ }
490
+
295
491
  export function apply(ctx, config) {
296
492
  const perms = Object.assign({
297
493
  voteEscalation: true,
@@ -424,6 +620,11 @@ export function apply(ctx, config) {
424
620
  path: '/mc-ops/config',
425
621
  handler: (req, res) => handleConfigRoute(req, res, { settings: scope.get('settings'), editor: scope.get('configEditor') }, memoryConfig),
426
622
  }))
623
+ scope.effect(() => webServer.register({
624
+ kind: 'prefix',
625
+ path: '/mc-ops/update',
626
+ handler: (req, res) => handleUpdateRoute(req, res),
627
+ }))
427
628
  })
428
629
  }
429
630
  const tools = ctx.get('tools')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mc-server-ops",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),并把人设注入 QQ 会话。需要先安装 QQ 机器人插件。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -31,13 +31,20 @@
31
31
  "dsh",
32
32
  "dsh-plugin",
33
33
  "minecraft",
34
+ "minecraft-server",
35
+ "minecraft-server-manager",
34
36
  "server",
37
+ "server-management",
38
+ "game-server",
35
39
  "rcon",
36
40
  "pterodactyl",
37
41
  "qqbot",
42
+ "qq-group",
43
+ "kubejs",
38
44
  "cordis"
39
45
  ],
40
46
  "license": "MIT",
47
+ "author": "mogutofu (https://github.com/mogutofu)",
41
48
  "engines": {
42
49
  "node": ">=20.3.0",
43
50
  "dsh": ">=0.2.0-0"