dsh-mc-server-ops 0.0.0-stage → 0.3.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-mc-server-ops contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,215 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # dsh-mc-server-ops
2
+
3
+ 把一台 **Minecraft 服务器**托管到 [DeepSeek Harness](https://github.com/deepseek-ai) 里的插件:QQ 群里的群友可以直接查状态、看日志、绑定游戏名,服主可以启停服务器、改配置、修 KubeJS 配方。
4
+
5
+ > 插件本身只是「服务器操作 + 人设」这一层,**聊天通道由 QQ 机器人插件提供**。
6
+ > 安装前请先装好并配置 `@tencent-connect/dsh-qqbot`(见下方「前置插件」),否则装上了也没有入口。
7
+
8
+ ## 前置插件(必须)
9
+
10
+ | 插件 | 作用 | 获取 |
11
+ | --- | --- | --- |
12
+ | `@tencent-connect/dsh-qqbot` | QQ 群/私聊通道:把群消息送进 Harness,把回复发回群里 | npm / DSH 插件市场 |
13
+
14
+ 没有它,本插件仍然会加载 `mc_server` 工具(本地 GUI 会话里可以用),但群里没人能触发它。
15
+
16
+ ## 它做什么
17
+
18
+ - **状态**:进程、在线玩家、CPU、内存、TPS、磁盘、运行时长,并给出「正常 / 卡顿 / 无响应假死 / 启动中」判定
19
+ - **启停**:start / stop / restart;假死自动强杀重启;确认关闭或假死时玩家也能重启
20
+ - **日志**:最近日志(过滤 RCON 噪音)、最近一次崩溃的上下文
21
+ - **白名单**:QQ ↔ 游戏名绑定,自动写入 `whitelist.json`(保留大小写,避免离线 UUID 不匹配)
22
+ - **配方**:`kubejs` 脚本备份 / 重载
23
+ - **授权**:动受保护区域(world、ops\data、白名单)要 2 位群友投票;**凑满 2 票之前任何人反对就作废**
24
+ - **人设**:默认「小铜」,名字和语气都能在设置里改
25
+
26
+ ## 安装
27
+
28
+ ```bash
29
+ # 1) 先装 QQ 机器人插件并配好 AppID / AppSecret
30
+ dsh plugin add @tencent-connect/dsh-qqbot
31
+
32
+ # 2) 再装本插件
33
+ dsh plugin add dsh-mc-server-ops
34
+ ```
35
+
36
+ 本地开发可以直接指向目录:
37
+
38
+ ```bash
39
+ dsh plugin add /path/to/dsh-mc-server-ops
40
+ ```
41
+
42
+ 安装后重启 DSH,在「设置 → 插件 → mc-server-ops」里填服务器目录。
43
+
44
+ ## 配置(设置界面可改)
45
+
46
+ | 字段 | 默认 | 说明 |
47
+ | --- | --- | --- |
48
+ | `server.dir` | 空 | 服务器目录(含 `server.properties`、`mods`、`java`)。留空则读环境变量 `MC_SERVER_DIR`,再不行用 `D:\server` |
49
+ | `server.rconPort` | `25575` | RCON 端口,需在 `server.properties` 里 `enable-rcon=true` |
50
+ | `server.rconPassword` | 空 | 留空则从 `server.properties` 读取 |
51
+ | `persona.enabled` | `true` | 是否注入人设 |
52
+ | `persona.name` | `小铜` | 助手在群里的名字 |
53
+ | `persona.text` | 空 | 人设正文;留空用内置默认(小铜)。**改人设就改这里,不用动代码** |
54
+ | `persona.scope` | `qq` | `qq` 只注入 QQ 群/私聊;`all` 所有会话;`none` 关闭 |
55
+ | `ops.allowPlayerWrite` | `true` | 允许玩家改服务器目录下非敏感文件 |
56
+ | `ops.grantHours` | `12` | 服主确认后可编辑文件/执行命令的有效时长 |
57
+ | `adapter` | `local` | 写操作走哪条路:`local` 本机脚本;`panel` Pterodactyl 面板 HTTP API |
58
+ | `panel.url` | 空 | 面板地址,`adapter=panel` 时必填 |
59
+ | `panel.serverId` | 空 | 面板里该服务器 URL 最后一段(8 位短 ID) |
60
+ | `panel.clientApiKey` | 空 | 客户端 API Key(`ptlc_` 开头) |
61
+ | `vote.approveNeed` | `2` | 通过需要几位群友同意 |
62
+ | `vote.rejectNeed` | `1` | 几位反对就作废(1 = 一票否决) |
63
+ | `vote.timeoutMinutes` | `15` | 多久没凑够门槛自动作废 |
64
+ | `vote.vetoEnabled` | `true` | 是否允许一票否决;关掉后反对票只记录、不作废 |
65
+ | `vote.protectedPaths` | `world, ops/data, whitelist` | 改动这些位置需要群友投票放行 |
66
+
67
+ ## 目录结构
68
+
69
+ ```
70
+ dsh-mc-server-ops/
71
+ ├── index.js # 插件宿主代码:mc_server 工具、权限守卫、人设注入
72
+ ├── cordis.patch.yml # 安装时自动插入的加载行
73
+ └── ops/
74
+ ├── command-guard.mjs # 静态命令拦截:出网前掐掉“一条命令搞崩整个服”的类型
75
+ ├── rcon.mjs # 跨平台核心:RCON、进程探测、日志、状态汇总
76
+ ├── adapters/ # 写操作适配器:local(本机脚本)/ panel(Pterodactyl)
77
+ ├── mcadmin.ps1 # 运维入口(status/start/stop/投票/白名单…)
78
+ ├── watchdog.ps1 # 看门狗:崩溃自动拉起
79
+ └── server-console.ps1 # 带日志着色的服务器控制台
80
+ ```
81
+
82
+ 首次运行时插件会把 `ops/*.ps1` 复制到 `<服务器目录>\ops\`(`rcon.mjs` 留在包里直接调用,不复制),运行期数据(`bindings.json`、`votes.json`、`state.json`、`owners.json`)也生成在那里,**不会**写进本仓库。
83
+
84
+ ## 服主和群友:怎么区分、怎么绑定
85
+
86
+ 默认**所有人都是群友**:只能查状态、看日志、问问题。
87
+ 服主名单存在 `<服务器目录>\ops\data\owners.json`,只有名单里的 QQ 能执行高危动作(stop / restart / cmd / 白名单 / 导出等)。
88
+
89
+ ### 绑定服主(只在设置面板里做)
90
+
91
+ 1. 打开「设置 → MC 服务器 → 服主绑定」
92
+ 2. 在输入框里填对方的 QQ openid,点「添加为服主」
93
+ 3. 名单会立刻刷新,每行右边有「移除」
94
+
95
+ **QQ openid 怎么拿:** 群消息开头都是 `[昵称 (ID)]`,括号里那串就是(例如 `[蘑菇来吃鱼 (34EB...CB)]`)。群友自己不知道的话,在群里 @ 机器人 问一句「我的 ID 是多少」,它会原样念出来——这串 ID 本来在群里就可见,不算秘密。
96
+
97
+ 服务器本机的等价命令:
98
+
99
+ ```
100
+ powershell -File <服务器目录>\ops\mcadmin.ps1 -Action owner-add -Arg <openid> -Actor LOCAL-CONSOLE
101
+ ```
102
+
103
+ 名单为空时这条命令不需要权限(引导用),一旦有了服主就只有服主能加人;群聊、私聊里都不能自行提权。
104
+
105
+ ### 其他
106
+
107
+ - `owner-list` 查看名单、`owner-del` 移除(后两个仅服主)
108
+ - 群友无法通过任何方式给自己提权;改 world / ops\data / 白名单这种受保护区域必须走投票
109
+
110
+ ## 功能开关(设置界面里逐项开关)
111
+
112
+ 权限分成两层:**基础权限**(授权窗口、玩家能不能改文件)和**功能开关**(下面这 9 项)。关掉的那一项,玩家调用时插件会直接拒绝并说明原因,不会走到脚本;服主不受影响。
113
+
114
+ | 开关 | 默认 | 关掉之后 |
115
+ | --- | --- | --- |
116
+ | `voteEscalation` 投票放权 | 开 | 只有服主能改 world / ops\data / 白名单 |
117
+ | `kubejsEdit` 改 KubeJS 配方 | 开 | 玩家改 `kubejs/` 被拒 |
118
+ | `configEdit` 改配置 | 开 | 玩家改 `config` / `defaultconfigs` / `server.properties` 被拒 |
119
+ | `playerStart` 玩家开服 | 开 | 服务器关着也只有服主能开 |
120
+ | `playerRestart` 玩家重启 | 开 | 崩溃/假死时也只有服主能重启 |
121
+ | `playerStop` 玩家停服 | **关** | 玩家永远不能停服 |
122
+ | `gamemodeSwitch` 切模式 | 开 | 玩家不能把自己切生存/旁观 |
123
+ | `say` 游戏内广播 | 开 | 玩家不能 `say` |
124
+ | `fileSend` 发文件到群 | 开 | 玩家不能把文件发到群里 |
125
+
126
+ 投票门槛也能改:`vote.approveNeed`(默认 2 位同意)、`vote.rejectNeed`(默认 1 位反对即作废)、`vote.timeoutMinutes`(默认 15 分钟)、`vote.vetoEnabled`(关掉后反对票只记录、不作废)、`vote.protectedPaths`(哪些位置算受保护区域,默认 world / ops/data / whitelist)。保存后会写进 `ops\data\vote-config.json`,脚本每次调用时读它。
127
+
128
+ ## 命令拦截(静态,绕不过去)
129
+
130
+ `ops/command-guard.mjs` 是 RCON 出网前的最后一道闸,只拦“一条命令就能把服搞崩”的类型:
131
+
132
+ | 拦截项 | 谁能发 |
133
+ | --- | --- |
134
+ | `kill @a` / `kill @e` / `kill @r` / `kill *` | 谁都发不了 |
135
+ | `kick @a` / `kick @e` | 谁都发不了 |
136
+ | `whitelist off` / `whitelist clear` | 谁都发不了 |
137
+ | `execute ... run kill @a` | 谁都发不了(换个写法也绕不过) |
138
+ | `stop` | 只有服主 |
139
+
140
+ `op` / `deop` / `execute` / `ban` 这类**正常管理指令不拦**——它们本来就是 `cmd` 的用途,只在插件层限制“只有服主能发”。`say` / `tell` / `msg` / `title` 等聊天类前缀直接放行,避免把聊天内容误判成指令。
141
+
142
+ 同一套规则在两处生效:插件层(`index.js`)判身份,PowerShell 层(`mcadmin.ps1` 的 `Assert-CommandSafe`)兜底——直接调脚本也拦得住。
143
+
144
+ ## 连接方式:本机 / Pterodactyl 面板
145
+
146
+ `adapter` 决定 `start` / `stop` / `restart` / `cmd` 这四个写操作走哪里:
147
+
148
+ - **`local`(默认)** — 本机直接跑 `ops/mcadmin.ps1`(Windows)或 `ops/rcon.mjs`(其它平台),行为和以前完全一致。
149
+ - **`panel`** — 走 Pterodactyl 客户端 API:`POST /api/client/servers/{id}/power`(`signal` = `start` / `stop` / `restart` / `kill`)、`POST /api/client/servers/{id}/command`,鉴权头 `Authorization: Bearer <clientApiKey>`。
150
+
151
+ 只读操作(`status` / `players` / `logs` / `crashinfo`)不经过适配器。要接别的面板(Pelican、AMP、PufferPanel)只需再写一个适配器文件,接口就五个方法:`start` / `stop` / `restart` / `sendCommand` / `getStatus`。
152
+
153
+ ## 安全模型
154
+
155
+ - 仓库和 npm 包里**不含任何口令、QQ 号、记忆数据或整合包**。
156
+ - 服主名单在 `owners.json`,只通过本机面板或命令行修改,不经过 QQ 聊天。
157
+ - 玩家默认只能读文件、跑只读命令;写文件、执行命令、联网下载需要服主授权(`ops.grantHours`)。
158
+ - 发文件到群里时,`server.properties`、`ops\data\*`、密钥类文件一律拦截。
159
+ - 设置面板的读写接口要求自定义请求头(浏览器会先发预检),跨站页面伪造不了;只改配置,不碰存档。
160
+ - `export-data` / `import-data` 仅服主可用;导入时会拒绝含 `..` 或绝对路径的压缩包条目(防 zip slip)。
161
+ - `cmd`(op/ban/kick 这类后台指令)在插件层就拦下非服主,不依赖脚本再判一次。
162
+ - `kill @a` / `kick @a` / `whitelist off` 这类“一条命令清场”的指令由静态拦截器直接拒绝,服主也发不出去;拦截在两处生效(插件层 + PowerShell 层)。
163
+
164
+ ## 运行环境
165
+
166
+ - Windows + PowerShell 5.1(脚本用 `powershell.exe -File` 调用)
167
+ - Node.js ≥ 20(DSH 自带)
168
+
169
+ **服务端不限类型**,插件只看端口、RCON 和进程,不假设你跑的是哪一家:
170
+
171
+ | 类型 | 例子 | 识别方式 |
172
+ | --- | --- | --- |
173
+ | 插件服 | Paper / Spigot / Purpur / Folia / Leaves | 根目录 `*.jar` |
174
+ | 模组服 | Forge / NeoForge / Fabric / Quilt | `libraries/**/win_args.txt` 或 `fabric-server-launch.jar` |
175
+ | 混合服 | Arclight / Mohist / Cardboard / Youer / Banner | 走它自己的 `win_args.txt` 或启动 jar |
176
+ | 原版 | vanilla `server.jar` | 根目录 `*.jar` |
177
+ | 脚本启动 | 任意 `run.bat` | 前两者都没有时兜底执行 |
178
+
179
+ 启动顺序:`libraries/**/win_args.txt` → 优先的 loader jar(fabric/quilt)→ 根目录最新 `*.jar` → `run.bat`。
180
+ 内存和 JVM 参数:存在 `user_jvm_args.txt` 就自动带上(`@user_jvm_args.txt`),否则用服务端默认。
181
+
182
+ TPS 也是按服务端自动探测:`forge tps` → `tps`(Paper/Spigot)→ `spark tps` → `carpet tps`,都没有就显示 `-`,不影响其它状态项。
183
+
184
+ 需要强制指定时可以设环境变量:`MC_JAR`(指定 jar)、`MC_JVM_ARGS`(覆盖 JVM 参数)、`MC_LAUNCH_ARGS`(覆盖整条启动参数)、`MC_SERVER_DIR`(服务器目录)。
185
+
186
+ ## 进程检测(多层降级)
187
+
188
+ 状态里的「运行」按下面这个顺序判断,任何一层可用就行,并在输出里标明用了哪层:
189
+
190
+ 1. `ops\data\server.pid` + `tasklist` 校验进程名(最准,能拿到 pid)
191
+ 2. 命令行匹配服务器目录:`wmic` → PowerShell `Get-CimInstance` → Linux `/proc`
192
+ 3. 端口探测:直接连 `server-port`(默认 25565),能连上就认为服务活着
193
+
194
+ 输出示例:`pid: 7544(pidfile)`、`pid: -(端口探测)`。两层都拿不到才算「未运行」,不会静默误报。
195
+
196
+ 没有引入第三方原生进程模块(`windows-process-tree` 这类):它们要按 Node ABI 预编译、随 Node 升级失效,供应链风险也高;端口探测已经能在「wmic 被移除 + pid 文件丢失」这种极端情况下给出正确判断。
197
+
198
+ ## 数据迁移
199
+
200
+ 运行期数据都在 `<服务器目录>\ops\data\`(绑定、投票、服主名单、投票门槛)。换机器或换目录时用两个工具动作搬运:
201
+
202
+ - `mc_server export-data`,arg 为目标 zip 路径 → 打包整个 `ops\data`
203
+ - `mc_server import-data`,arg 为 zip 路径 → 解压覆盖回 `ops\data`
204
+
205
+ 两个动作都只有服主能调用。
206
+
207
+ ## 路线图 / 已知限制
208
+
209
+ - **跨平台**:核心已抽到纯 Node 的 `ops/rcon.mjs`。`status` / `players` / `say` / `cmd` / `logs` / `start` / `stop` / `restart` 在 Linux、macOS 上直接可用(Windows 仍走 PowerShell,CPU 等指标更全)。还剩投票、白名单、绑定、KubeJS 这些写数据的动作只在 Windows 上;在别的平台调用会明确提示,而不是报 PowerShell 找不到。
210
+ - **投票超时**:已实现。`vote.timeoutMinutes`(默认 15)到点没凑够门槛会自动标成 `expired`,不再占「同时最多 3 个待确认投票」的名额。
211
+ - **人设注入范围**:按会话 id 前缀判断(`session-*` 是本机界面),是启发式;如果 DSH 以后改会话 id 规则,这里要跟着调。
212
+
213
+ ## License
214
+
215
+ MIT
package/client.js ADDED
@@ -0,0 +1,300 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-mc-server-ops",
3
+ factory: (require) => {
4
+ const react = require("react")
5
+ const h = react.createElement
6
+ const PACKAGE_NAME = "dsh-mc-server-ops"
7
+ const ENDPOINT = "/mc-ops/config"
8
+
9
+ const box = { display: "flex", flexDirection: "column", gap: 10 }
10
+ const row = { display: "flex", flexDirection: "column", gap: 4 }
11
+ const labelStyle = { fontSize: 12, fontWeight: 600, opacity: 0.85 }
12
+ const hintStyle = { fontSize: 11, opacity: 0.6, lineHeight: 1.5 }
13
+ const inputStyle = {
14
+ width: "100%",
15
+ boxSizing: "border-box",
16
+ padding: "6px 8px",
17
+ borderRadius: 6,
18
+ border: "1px solid rgba(127,127,127,0.35)",
19
+ background: "transparent",
20
+ color: "inherit",
21
+ font: "inherit",
22
+ fontSize: 13,
23
+ }
24
+ const textareaStyle = Object.assign({}, inputStyle, { minHeight: 120, fontFamily: "inherit", resize: "vertical" })
25
+ const groupStyle = { border: "1px solid rgba(127,127,127,0.22)", borderRadius: 8, padding: "12px 14px", display: "flex", flexDirection: "column", gap: 12 }
26
+ const titleStyle = { fontSize: 13, fontWeight: 700, marginBottom: 2 }
27
+ const buttonStyle = { padding: "6px 14px", borderRadius: 6, border: "1px solid rgba(127,127,127,0.35)", background: "rgba(127,127,127,0.12)", color: "inherit", cursor: "pointer", fontSize: 13 }
28
+ const statusStyle = { fontSize: 12, opacity: 0.75 }
29
+
30
+ function Field({ label, hint, children }) {
31
+ return h("label", { style: row }, h("span", { style: labelStyle }, label), children, hint ? h("span", { style: hintStyle }, hint) : null)
32
+ }
33
+
34
+ function TextInput({ value, onChange, placeholder }) {
35
+ return h("input", { style: inputStyle, value: value == null ? "" : String(value), placeholder: placeholder || "", onChange: (e) => onChange(e.target.value) })
36
+ }
37
+
38
+ function NumberInput({ value, onChange }) {
39
+ return h("input", { style: inputStyle, type: "number", value: value == null ? "" : String(value), onChange: (e) => onChange(e.target.value === "" ? "" : Number(e.target.value)) })
40
+ }
41
+
42
+ function Toggle({ value, onChange, label }) {
43
+ return h("label", { style: { display: "flex", alignItems: "center", gap: 8, fontSize: 13, cursor: "pointer" } },
44
+ h("input", { type: "checkbox", checked: !!value, onChange: (e) => onChange(e.target.checked) }),
45
+ label)
46
+ }
47
+
48
+ function ConfigPanel() {
49
+ const [status, setStatus] = react.useState({ loading: true, error: "", saved: "", saving: false })
50
+ const [form, setForm] = react.useState(null)
51
+ const [owners, setOwners] = react.useState([])
52
+ const [newOwner, setNewOwner] = react.useState("")
53
+
54
+ react.useEffect(() => { void load() }, [])
55
+
56
+ async function load() {
57
+ try {
58
+ const res = await fetch(ENDPOINT, { cache: "no-store", headers: { "x-mc-ops-client": "1" } })
59
+ const data = await res.json()
60
+ if (!res.ok) throw new Error(data.error || ("HTTP " + res.status))
61
+ const v = data.value || {}
62
+ setForm({
63
+ server: { dir: (v.server || {}).dir || "", rconPort: (v.server || {}).rconPort ?? 25575, rconPassword: (v.server || {}).rconPassword || "" },
64
+ persona: { enabled: (v.persona || {}).enabled !== false, name: (v.persona || {}).name || "", text: (v.persona || {}).text || "", scope: (v.persona || {}).scope || "qq" },
65
+ ops: {
66
+ allowPlayerWrite: (v.ops || {}).allowPlayerWrite !== false,
67
+ grantHours: (v.ops || {}).grantHours ?? 12,
68
+ riskApprovalSeconds: (v.ops || {}).riskApprovalSeconds ?? 30,
69
+ },
70
+ adapter: v.adapter === "panel" ? "panel" : "local",
71
+ panel: {
72
+ url: (v.panel || {}).url || "",
73
+ serverId: (v.panel || {}).serverId || "",
74
+ clientApiKey: (v.panel || {}).clientApiKey || "",
75
+ },
76
+ vote: {
77
+ approveNeed: (v.vote || {}).approveNeed ?? 2,
78
+ rejectNeed: (v.vote || {}).rejectNeed ?? 1,
79
+ timeoutMinutes: (v.vote || {}).timeoutMinutes ?? 15,
80
+ vetoEnabled: (v.vote || {}).vetoEnabled !== false,
81
+ protectedPaths: Array.isArray((v.vote || {}).protectedPaths) && (v.vote || {}).protectedPaths.length
82
+ ? (v.vote || {}).protectedPaths.join(", ")
83
+ : "world, ops/data, whitelist",
84
+ },
85
+ permissions: {
86
+ voteEscalation: (v.permissions || {}).voteEscalation !== false,
87
+ kubejsEdit: (v.permissions || {}).kubejsEdit !== false,
88
+ configEdit: (v.permissions || {}).configEdit !== false,
89
+ playerStart: (v.permissions || {}).playerStart !== false,
90
+ playerRestart: (v.permissions || {}).playerRestart !== false,
91
+ playerStop: (v.permissions || {}).playerStop === true,
92
+ gamemodeSwitch: (v.permissions || {}).gamemodeSwitch !== false,
93
+ say: (v.permissions || {}).say !== false,
94
+ fileSend: (v.permissions || {}).fileSend !== false,
95
+ },
96
+ })
97
+ setOwners(Array.isArray(data.owners) ? data.owners : [])
98
+ setStatus({ loading: false, error: "", saved: "", saving: false })
99
+ } catch (err) {
100
+ setStatus({ loading: false, error: String(err && err.message ? err.message : err), saved: "", saving: false })
101
+ }
102
+ }
103
+
104
+ function patch(group, key, value) {
105
+ setForm((prev) => (prev ? Object.assign({}, prev, { [group]: Object.assign({}, prev[group], { [key]: value }) }) : prev))
106
+ }
107
+
108
+ // 顶层字段(adapter 这种不是对象的)单独一个入口
109
+ function setTop(key, value) {
110
+ setForm((prev) => (prev ? Object.assign({}, prev, { [key]: value }) : prev))
111
+ }
112
+
113
+ async function save() {
114
+ if (!form) return
115
+ setStatus(Object.assign({}, status, { saving: true, error: "", saved: "" }))
116
+ try {
117
+ const res = await fetch(ENDPOINT, {
118
+ method: "POST",
119
+ headers: { "content-type": "application/json", "x-mc-ops-client": "1" },
120
+ body: JSON.stringify(form),
121
+ })
122
+ const data = await res.json()
123
+ if (!res.ok) throw new Error(data.error || ("HTTP " + res.status))
124
+ setStatus({ loading: false, error: "", saved: "已保存,马上生效", saving: false })
125
+ } catch (err) {
126
+ setStatus({ loading: false, error: String(err && err.message ? err.message : err), saved: "", saving: false })
127
+ }
128
+ }
129
+
130
+ async function submitOwner(kind, value) {
131
+ setStatus(Object.assign({}, status, { saving: true, error: "", saved: "" }))
132
+ try {
133
+ const payload = Object.assign({}, form || {})
134
+ payload[kind] = value
135
+ const res = await fetch(ENDPOINT, {
136
+ method: "POST",
137
+ headers: { "content-type": "application/json", "x-mc-ops-client": "1" },
138
+ body: JSON.stringify(payload),
139
+ })
140
+ const data = await res.json()
141
+ if (!res.ok) throw new Error(data.error || ("HTTP " + res.status))
142
+ setOwners(Array.isArray(data.owners) ? data.owners : owners)
143
+ setNewOwner("")
144
+ setStatus({ loading: false, error: "", saved: kind === "addOwner" ? "已添加服主" : "已移除", saving: false })
145
+ } catch (err) {
146
+ setStatus({ loading: false, error: String(err && err.message ? err.message : err), saved: "", saving: false })
147
+ }
148
+ }
149
+
150
+ if (status.loading) return h("div", { style: hintStyle }, "正在读取配置…")
151
+ if (status.error && !form) return h("div", { style: { color: "#d9534f", fontSize: 13 } }, "读取失败:" + status.error)
152
+ if (!form) return null
153
+
154
+ return h("div", { style: box },
155
+ h("div", null,
156
+ h("div", { style: titleStyle }, "服主绑定"),
157
+ h("div", { style: hintStyle }, "填 QQ 号(openid)加服主。不知道自己 ID:在群里 @ 机器人 说「我的 ID 是多少」,它会把你消息开头 [昵称 (ID)] 里那串念给你。"),
158
+ ),
159
+ h("div", { style: groupStyle },
160
+ h("div", { style: { borderTop: "1px solid rgba(127,127,127,0.22)", paddingTop: 10, display: "flex", flexDirection: "column", gap: 8 } },
161
+ h("div", { style: labelStyle }, "服主名单(" + owners.length + ")"),
162
+ owners.length
163
+ ? owners.map((id) => h("div", { key: id, style: { display: "flex", alignItems: "center", gap: 10 } },
164
+ h("code", { style: { fontSize: 12, opacity: 0.85 } }, id),
165
+ h("button", { type: "button", style: Object.assign({}, buttonStyle, { padding: "3px 10px", fontSize: 12 }), onClick: () => void submitOwner("removeOwner", id), disabled: status.saving }, "移除")))
166
+ : h("div", { style: hintStyle }, "还没有服主。在下面填 QQ 号加一个。"),
167
+ h("div", { style: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" } },
168
+ h("input", { style: Object.assign({}, inputStyle, { flex: "1 1 260px" }), value: newOwner, placeholder: "群消息里 [昵称 (ID)] 括号中的那串", onChange: (e) => setNewOwner(e.target.value) }),
169
+ h("button", { type: "button", style: buttonStyle, onClick: () => void submitOwner("addOwner", newOwner.trim()), disabled: status.saving || newOwner.trim().length < 8 }, "添加为服主")),
170
+ h("div", { style: hintStyle }, "面板在本机操作,等价于在服务器上执行 owner-add,不需要口令。"),
171
+ ),
172
+ ),
173
+ h("div", null,
174
+ h("div", { style: titleStyle }, "服务器"),
175
+ h("div", { style: hintStyle }, "Minecraft 服务器目录与 RCON。改完即时生效,无需重启。"),
176
+ ),
177
+ h("div", { style: groupStyle },
178
+ h(Field, { label: "服务器目录", hint: "含 server.properties、mods、java 子目录的路径,例如 D:\\server" },
179
+ h(TextInput, { value: form.server.dir, placeholder: "D:\\server", onChange: (x) => patch("server", "dir", x) })),
180
+ h(Field, { label: "RCON 端口" },
181
+ h(NumberInput, { value: form.server.rconPort, onChange: (x) => patch("server", "rconPort", x) })),
182
+ h(Field, { label: "RCON 密码", hint: "留空则从 server.properties 里读取" },
183
+ h(TextInput, { value: form.server.rconPassword, placeholder: "留空 = 自动读取", onChange: (x) => patch("server", "rconPassword", x) })),
184
+ h(Field, { label: "注入范围" },
185
+ h("select", { style: inputStyle, value: form.persona.scope, onChange: (e) => patch("persona", "scope", e.target.value) },
186
+ h("option", { value: "qq" }, "只注入 QQ 群/私聊"),
187
+ h("option", { value: "all" }, "所有会话"),
188
+ h("option", { value: "none" }, "关闭人设注入"))),
189
+ ),
190
+ h("div", null,
191
+ h("div", { style: titleStyle }, "连接方式"),
192
+ h("div", { style: hintStyle }, "启停和后台指令走哪条路。服务器就在这台机器上选「本机」;托管在翼龙面板上选「Pterodactyl」。状态、日志这些只读操作不受影响。"),
193
+ ),
194
+ h("div", { style: groupStyle },
195
+ h(Field, { label: "写操作走哪里" },
196
+ h("select", { style: inputStyle, value: form.adapter, onChange: (e) => setTop("adapter", e.target.value) },
197
+ h("option", { value: "local" }, "本机(直接跑脚本,默认)"),
198
+ h("option", { value: "panel" }, "Pterodactyl 面板(HTTP API)"))),
199
+ form.adapter === "panel"
200
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: 10 } },
201
+ h(Field, { label: "面板地址", hint: "例如 https://panel.example.com,不要带结尾斜杠" },
202
+ h(TextInput, { value: form.panel.url, placeholder: "https://…", onChange: (x) => patch("panel", "url", x) })),
203
+ h(Field, { label: "服务器 ID", hint: "面板里这台服务器 URL 的最后一段(8 位短 ID)" },
204
+ h(TextInput, { value: form.panel.serverId, placeholder: "a1b2c3d4", onChange: (x) => patch("panel", "serverId", x) })),
205
+ h(Field, { label: "客户端 API Key", hint: "面板 → Account → API Credentials 生成,ptlc_ 开头" },
206
+ h(TextInput, { value: form.panel.clientApiKey, placeholder: "ptlc_…", onChange: (x) => patch("panel", "clientApiKey", x) })))
207
+ : h("div", { style: hintStyle }, "当前用本机脚本启停,不需要面板配置。"),
208
+ ),
209
+ h("div", null,
210
+ h("div", { style: titleStyle }, "人设"),
211
+ h("div", { style: hintStyle }, "默认是小铜。改名字和语气只需要改这里,代码不用动。"),
212
+ ),
213
+ h("div", { style: groupStyle },
214
+ h(Toggle, { label: "启用自定义人设", value: form.persona.enabled, onChange: (x) => patch("persona", "enabled", x) }),
215
+ h(Field, { label: "名字" },
216
+ h(TextInput, { value: form.persona.name, placeholder: "小铜", onChange: (x) => patch("persona", "name", x) })),
217
+ h(Field, { label: "人设正文", hint: "留空则使用内置的小铜设定;写得越具体,语气越稳。" },
218
+ h("textarea", { style: textareaStyle, value: form.persona.text, placeholder: "你在 QQ 群里叫「小铜」,二十来岁……", onChange: (e) => patch("persona", "text", e.target.value) })),
219
+ ),
220
+ h("div", null,
221
+ h("div", { style: titleStyle }, "权限"),
222
+ h("div", { style: hintStyle }, "玩家能做什么、服主授权窗口多长。受保护区域(world、ops\\data、白名单)始终要投票。"),
223
+ ),
224
+ h("div", { style: groupStyle },
225
+ h(Toggle, { label: "允许玩家改服务器目录下的普通文件(kubejs/config 等)", value: form.ops.allowPlayerWrite, onChange: (x) => patch("ops", "allowPlayerWrite", x) }),
226
+ h(Field, { label: "服主授权窗口(小时)", hint: "服主确认后,该会话可以改文件、执行命令的时长" },
227
+ h(NumberInput, { value: form.ops.grantHours, onChange: (x) => patch("ops", "grantHours", x) })),
228
+ h(Field, { label: "创建服主口令冷却(秒)" },
229
+ h(NumberInput, { value: form.ops.riskApprovalSeconds, onChange: (x) => patch("ops", "riskApprovalSeconds", x) })),
230
+ ),
231
+ h("div", null,
232
+ h("div", { style: titleStyle }, "投票"),
233
+ h("div", { style: hintStyle }, "改 world / ops\\data / 白名单 这类受保护区域时走的流程。"),
234
+ ),
235
+ h("div", { style: groupStyle },
236
+ h(Field, { label: "通过需要几位同意", hint: "默认 2 位" },
237
+ h(NumberInput, { value: form.vote.approveNeed, onChange: (x) => patch("vote", "approveNeed", x) })),
238
+ h(Field, { label: "几位反对就作废", hint: "默认 1,也就是一票否决;改成 2 就要两个人反对才作废" },
239
+ h(NumberInput, { value: form.vote.rejectNeed, onChange: (x) => patch("vote", "rejectNeed", x) })),
240
+ h(Field, { label: "多久没凑够自动作废(分钟)", hint: "默认 15 分钟;到点没满票就变成「已过期」,不再占用待确认名额" },
241
+ h(NumberInput, { value: form.vote.timeoutMinutes, onChange: (x) => patch("vote", "timeoutMinutes", x) })),
242
+ h(Toggle, { label: "允许一票否决(凑够同意票之前有人反对就作废)", value: form.vote.vetoEnabled, onChange: (x) => patch("vote", "vetoEnabled", x) }),
243
+ h(Field, { label: "受保护路径", hint: "逗号分隔,改动这些位置要走投票。默认 world, ops/data, whitelist" },
244
+ h(TextInput, { value: form.vote.protectedPaths, placeholder: "world, ops/data, whitelist", onChange: (x) => patch("vote", "protectedPaths", x) })),
245
+ ),
246
+ h("div", null,
247
+ h("div", { style: titleStyle }, "功能开关"),
248
+ h("div", { style: hintStyle }, "逐项决定群友能做什么。关掉的那一项,玩家调用会被直接拒绝(服主不受影响)。"),
249
+ ),
250
+ h("div", { style: groupStyle },
251
+ h(Toggle, { label: "投票放权(改 world / ops\\data / 白名单)", value: form.permissions.voteEscalation, onChange: (x) => patch("permissions", "voteEscalation", x) }),
252
+ h(Toggle, { label: "允许玩家改 KubeJS 配方(kubejs/)", value: form.permissions.kubejsEdit, onChange: (x) => patch("permissions", "kubejsEdit", x) }),
253
+ h(Toggle, { label: "允许玩家改 config / defaultconfigs / server.properties", value: form.permissions.configEdit, onChange: (x) => patch("permissions", "configEdit", x) }),
254
+ h(Toggle, { label: "服务器关闭时允许玩家开服", value: form.permissions.playerStart, onChange: (x) => patch("permissions", "playerStart", x) }),
255
+ h(Toggle, { label: "服务器崩溃/假死时允许玩家重启", value: form.permissions.playerRestart, onChange: (x) => patch("permissions", "playerRestart", x) }),
256
+ h(Toggle, { label: "允许玩家停服", value: form.permissions.playerStop, onChange: (x) => patch("permissions", "playerStop", x) }),
257
+ h(Toggle, { label: "允许玩家切自己的游戏模式", value: form.permissions.gamemodeSwitch, onChange: (x) => patch("permissions", "gamemodeSwitch", x) }),
258
+ h(Toggle, { label: "允许玩家游戏内广播(say)", value: form.permissions.say, onChange: (x) => patch("permissions", "say", x) }),
259
+ h(Toggle, { label: "允许玩家把文件发到群里", value: form.permissions.fileSend, onChange: (x) => patch("permissions", "fileSend", x) }),
260
+ ),
261
+ h("div", { style: { display: "flex", alignItems: "center", gap: 12 } },
262
+ h("button", { type: "button", style: buttonStyle, onClick: () => void save(), disabled: status.saving }, status.saving ? "保存中…" : "保存"),
263
+ h("button", { type: "button", style: buttonStyle, onClick: () => void load(), disabled: status.saving }, "重新读取"),
264
+ status.saved ? h("span", { style: Object.assign({}, statusStyle, { color: "#3c9a5f" }) }, status.saved) : null,
265
+ status.error ? h("span", { style: Object.assign({}, statusStyle, { color: "#d9534f" }) }, status.error) : null,
266
+ ),
267
+ )
268
+ }
269
+
270
+ function PageBody() {
271
+ return h("div", { style: { padding: "16px 4px", maxWidth: 720 } },
272
+ h("div", { style: { fontSize: 18, fontWeight: 700, marginBottom: 4 } }, "Minecraft 服务器"),
273
+ h("div", { style: Object.assign({}, hintStyle, { marginBottom: 14 }) }, "改完即时生效。受保护区域(world、ops\\data、白名单)仍然要两位群友投票,这里改不了。"),
274
+ h(ConfigPanel),
275
+ )
276
+ }
277
+
278
+ function apply(ctx) {
279
+ const slots = ctx.slots
280
+ if (slots === void 0) return
281
+ // 1) 插件详情页里的配置块
282
+ ctx.effect(() => slots.inject("plugins.bundle.config", () => slots.register({
283
+ name: "plugins.bundle.config",
284
+ key: PACKAGE_NAME,
285
+ }, ConfigPanel)))
286
+ // 2) 设置左侧独立入口(和「QQ 机器人」并列),保证一定看得见
287
+ ctx.effect(() => slots.inject("settings.section", () => slots.register({
288
+ name: "settings.section",
289
+ id: "mc-server-ops",
290
+ order: 9,
291
+ label: "MC 服务器",
292
+ }, PageBody)))
293
+ }
294
+
295
+ const inject = ["slots"]
296
+ const name = "mc-server-ops-client"
297
+ const exportsObj = { apply, inject, name }
298
+ return exportsObj
299
+ }
300
+ });
@@ -0,0 +1,17 @@
1
+ # dsh-mc-server-ops bundle patch
2
+ #
3
+ # 安装本包后,dsh 启动时会自动插入 mc-server-ops 插件行。
4
+ # 所有配置都可以在「设置 → 插件」里改,这里的值只是初始默认。
5
+ - insert:
6
+ - id: mc-server-ops
7
+ name: dsh-mc-server-ops
8
+ config:
9
+ server:
10
+ dir: ''
11
+ rconPort: 25575
12
+ rconPassword: ''
13
+ persona:
14
+ enabled: true
15
+ name: 小铜
16
+ text: ''
17
+ scope: qq