dsh-mc-server-ops 0.6.3 → 0.6.5
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/README.md +1 -0
- package/index.js +114 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -290,6 +290,7 @@ powershell -File <服务器目录>\ops\mcadmin.ps1 -Action owner-add -Arg <openi
|
|
|
290
290
|
- 同一玩家两次发起间隔 `weather.cooldownSeconds`(默认 60 秒)
|
|
291
291
|
- 配置写在 `<服务器目录>/config/mcai-weather.json`,mod 每次 `/weather` 都读它,所以**设置面板改完即时生效**,不用重启服务器
|
|
292
292
|
- 服务器装的是旧版 mod(< 1.2.0)时,这个配置不会生效,`/weather` 也还是原版需要 OP 的版本
|
|
293
|
+
- **QQ 群里也能改**:玩家先用 `bind-player` 绑定游戏名并进入游戏,然后在群里跟小铜说「把天气改成下雨」即可——小铜会用你的游戏名执行 `weather`,在线 ≤2 人直接生效、≥3 人时游戏内会广播投票(其他玩家 `/vote yes`)。服主在群里说则直接执行。
|
|
293
294
|
|
|
294
295
|
## 安全模型
|
|
295
296
|
|
package/index.js
CHANGED
|
@@ -83,6 +83,36 @@ function isOwner(actor) {
|
|
|
83
83
|
return readOwners().includes(actor)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** 读 ops/data/bindings.json:QQ openid 与游戏名的绑定。 */
|
|
87
|
+
function readPlayerBindings() {
|
|
88
|
+
try {
|
|
89
|
+
const raw = readFileSync(join(paths.serverDir, 'ops', 'data', 'bindings.json'), 'utf8').replace(/^\uFEFF/, '')
|
|
90
|
+
const doc = JSON.parse(raw)
|
|
91
|
+
return Array.isArray(doc)
|
|
92
|
+
? doc.map((x) => ({ qq: String((x && x.qq) || ''), name: String((x && x.name) || '') })).filter((x) => x.qq && x.name)
|
|
93
|
+
: []
|
|
94
|
+
} catch {
|
|
95
|
+
return []
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 从 mcadmin players 的输出里解析在线玩家名。 */
|
|
100
|
+
function parseOnlinePlayers(text) {
|
|
101
|
+
const match = /online:\s*([^\n]*)/i.exec(String(text || ''))
|
|
102
|
+
if (!match) return []
|
|
103
|
+
return match[1].split(',').map((x) => x.trim()).filter(Boolean)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 天气类型规范化;不认识的返回空串。 */
|
|
107
|
+
const WEATHER_NAMES = { clear: '晴天', rain: '下雨', thunder: '雷雨' }
|
|
108
|
+
function normalizeWeatherType(arg) {
|
|
109
|
+
const value = String(arg || '').trim().toLowerCase()
|
|
110
|
+
if (value === 'clear' || value === 'sunny' || value === '晴天') return 'clear'
|
|
111
|
+
if (value === 'rain' || value === '下雨') return 'rain'
|
|
112
|
+
if (value === 'thunder' || value === '雷雨') return 'thunder'
|
|
113
|
+
return ''
|
|
114
|
+
}
|
|
115
|
+
|
|
86
116
|
function grantTools(agentId) {
|
|
87
117
|
if (agentId) grants.set(String(agentId), Date.now() + GRANT_MS)
|
|
88
118
|
}
|
|
@@ -116,7 +146,7 @@ function readQqbotCredentials() {
|
|
|
116
146
|
|
|
117
147
|
const ACTIONS = [
|
|
118
148
|
'status', 'players', 'say', 'cmd', 'start', 'stop', 'restart',
|
|
119
|
-
'logs', 'crashinfo', 'whoami', 'help', 'gamemode',
|
|
149
|
+
'logs', 'crashinfo', 'whoami', 'help', 'gamemode', 'weather',
|
|
120
150
|
'bind-player', 'unbind-player', 'my-players', 'bindings', 'whitelist-sync',
|
|
121
151
|
'kubejs-backup', 'kubejs-reload', 'vote-start', 'vote-approve', 'vote-reject', 'vote-status',
|
|
122
152
|
'export-data', 'import-data', 'bridge-groups',
|
|
@@ -173,9 +203,10 @@ const DESCRIPTION = [
|
|
|
173
203
|
'- stop:停服,仅服主',
|
|
174
204
|
'- restart:服务器确认关闭、或健康=无响应(假死)时任何人可用(假死会自动强杀重启);健康=正常或启动中时仅服主',
|
|
175
205
|
'- gamemode:切换游戏模式,arg 形如 spectator 玩家名。玩家只能切 survival / spectator,且目标必须是自己绑定的游戏名;creative / adventure 和切别人仅服主',
|
|
206
|
+
'- weather:改天气,arg 为 clear / rain / thunder(也可写 晴天 / 下雨 / 雷雨)。所有玩家都能用:自己的游戏名在线时,小铜会用他的游戏名发起——在线 ≤2 人直接生效,≥3 人时游戏内会广播投票(其他玩家 /vote yes);服主则直接执行。不要因为 cmd 仅服主就拒绝玩家的天气请求',
|
|
176
207
|
'- cmd:执行任意后台指令(op/deop/ban/kick/whitelist 等),仅服主',
|
|
177
208
|
'',
|
|
178
|
-
'玩家还能做:用 read / glob / grep 看服务器文件、用只读的 pwsh 命令查信息、用 qqbot_send_file
|
|
209
|
+
'玩家还能做:用 read / glob / grep 看服务器文件、用只读的 pwsh 命令查信息、用 qqbot_send_file 把普通文件发到群里(口令/密钥类文件除外)、用 weather 改天气。',
|
|
179
210
|
'玩家不能:改文件、删文件、新建文件、执行危险命令、设置创造模式。',
|
|
180
211
|
'- bind-player:把游戏名绑定到当前 QQ(同时加入服务器白名单),arg 为游戏名(1-16 位字母/数字/下划线),一个 QQ 最多 10 个,一个游戏名最多被 3 个 QQ 绑定',
|
|
181
212
|
'- unbind-player:解绑自己的某个游戏名(若该名字已无其它 QQ 绑定,同时移出白名单),arg 为游戏名',
|
|
@@ -1119,7 +1150,7 @@ export function apply(ctx, config) {
|
|
|
1119
1150
|
},
|
|
1120
1151
|
arg: {
|
|
1121
1152
|
type: 'string',
|
|
1122
|
-
description: 'say 的内容、cmd
|
|
1153
|
+
description: 'say 的内容、cmd 的指令(不带斜杠)、weather 的天气类型(clear/rain/thunder)、口令,其它操作为空',
|
|
1123
1154
|
},
|
|
1124
1155
|
channel: {
|
|
1125
1156
|
type: 'string',
|
|
@@ -1137,10 +1168,22 @@ export function apply(ctx, config) {
|
|
|
1137
1168
|
timeoutMs: 180000,
|
|
1138
1169
|
isConcurrencySafe: () => false,
|
|
1139
1170
|
async execute(args, exec) {
|
|
1140
|
-
|
|
1171
|
+
let action = String((args && args.action) || '')
|
|
1141
1172
|
if (!ACTIONS.includes(action)) throw new Error('mc_server: 不支持的 action: ' + action)
|
|
1142
1173
|
const actor = String((args && args.actor) || '').trim()
|
|
1143
1174
|
if (!actor) throw new Error('mc_server: actor 不能为空(必须取自 [昵称 (ID)] 标记)')
|
|
1175
|
+
// 兼容旧习惯:模型可能用 cmd 发「weather rain」。只要整个参数就是天气命令,
|
|
1176
|
+
// 就转成 weather 动作处理(玩家也能走,不再被 cmd 的服主限制拦住)。
|
|
1177
|
+
// 注意:args 对象是只读的(工具层冻结),不要原地改 args.arg,用局部变量覆盖。
|
|
1178
|
+
let weatherArgOverride = null
|
|
1179
|
+
if (action === 'cmd') {
|
|
1180
|
+
const cmdArg = String((args && args.arg) || '').trim()
|
|
1181
|
+
const weatherMatch = /^weather\s+(clear|rain|thunder|sunny|晴天|下雨|雷雨)\s*$/i.exec(cmdArg)
|
|
1182
|
+
if (weatherMatch) {
|
|
1183
|
+
weatherArgOverride = weatherMatch[1]
|
|
1184
|
+
action = 'weather'
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1144
1187
|
const agentIdForGate = exec && exec.agent && exec.agent.id ? String(exec.agent.id) : ''
|
|
1145
1188
|
if ((action === 'owner-add' || action === 'owner-del') && !isLocalSession(agentIdForGate)) {
|
|
1146
1189
|
return { ok: false, text: '增删服主只能在设置面板里做,或者到服务器本机执行。' }
|
|
@@ -1156,7 +1199,7 @@ export function apply(ctx, config) {
|
|
|
1156
1199
|
// Channel 由会话决定,不信模型自己填:本机会话=console,QQ 会话=group,只有私聊且模型声明 c2c 才算 c2c
|
|
1157
1200
|
const channel = isLocalSession(agentIdForGate) ? 'console' : (String((args && args.channel) || '') === 'c2c' ? 'c2c' : 'group')
|
|
1158
1201
|
const cli = ['-Action', action, '-Actor', actor, '-Channel', channel]
|
|
1159
|
-
const arg = args && args.arg !== undefined && args.arg !== null ? String(args.arg) : ''
|
|
1202
|
+
const arg = weatherArgOverride !== null ? weatherArgOverride : (args && args.arg !== undefined && args.arg !== null ? String(args.arg) : '')
|
|
1160
1203
|
if (arg !== '') cli.push('-Arg', arg)
|
|
1161
1204
|
// ── 出网前的三道闸 ──
|
|
1162
1205
|
// ① 权限校验:上面已经拦掉服主专属动作和设置里关掉的功能
|
|
@@ -1200,6 +1243,49 @@ export function apply(ctx, config) {
|
|
|
1200
1243
|
}
|
|
1201
1244
|
}
|
|
1202
1245
|
|
|
1246
|
+
// 天气投票:玩家也能用(不需要服主权限)。
|
|
1247
|
+
// - 服主/控制台:直接执行 weather 命令(相当于控制台发起,不投票)
|
|
1248
|
+
// - 玩家:用他绑定且当前在线的游戏名执行 execute as <name> run weather <type>,
|
|
1249
|
+
// mod 会按在线人数决定直接生效还是发起游戏内投票(/vote yes)。
|
|
1250
|
+
if (action === 'weather') {
|
|
1251
|
+
const weatherCfg = (liveConfig && liveConfig.weather) || {}
|
|
1252
|
+
if (weatherCfg.enabled === false) return { ok: false, text: '天气功能已经在设置里关掉了(设置 → 游戏内天气投票)。' }
|
|
1253
|
+
const type = normalizeWeatherType(arg)
|
|
1254
|
+
if (!type) return { ok: false, text: '用法:weather <clear|rain|thunder>(晴天 / 下雨 / 雷雨)' }
|
|
1255
|
+
const typeName = WEATHER_NAMES[type]
|
|
1256
|
+
const threshold = Math.max(0, Number(weatherCfg.directThreshold) || 0)
|
|
1257
|
+
const approveNeed = Math.max(1, Number(weatherCfg.approveNeed) || 2)
|
|
1258
|
+
if (isOwner(actor)) {
|
|
1259
|
+
const done = await runMcAdmin(['-Action', 'cmd', '-Arg', 'weather ' + type, '-Actor', 'LOCAL-CONSOLE', '-Channel', 'console'], 60000)
|
|
1260
|
+
if (!done.ok) return { ok: false, text: '改天气失败:' + done.text }
|
|
1261
|
+
return { ok: true, text: '天气已改成「' + typeName + '」(服主直接执行,不投票)。' }
|
|
1262
|
+
}
|
|
1263
|
+
const mine = readPlayerBindings().filter((b) => b.qq === actor).map((b) => b.name)
|
|
1264
|
+
const playersResult = await runMcAdmin(['-Action', 'players', '-Actor', actor, '-Channel', channel], 30000)
|
|
1265
|
+
const online = parseOnlinePlayers(playersResult.ok ? playersResult.text : '')
|
|
1266
|
+
const onlineName = mine.find((name) => online.some((p) => p.toLowerCase() === name.toLowerCase()))
|
|
1267
|
+
// 没有绑定或不在线时:在线人少(≤ 免投票阈值)不需要身份也能直接生效。
|
|
1268
|
+
if (!onlineName) {
|
|
1269
|
+
const who = !mine.length ? '你还没绑定游戏名' : '你绑定的游戏名(' + mine.join(', ') + ')现在都不在线'
|
|
1270
|
+
if (online.length <= threshold) {
|
|
1271
|
+
const direct = await runMcAdmin(['-Action', 'cmd', '-Arg', 'weather ' + type, '-Actor', 'LOCAL-CONSOLE', '-Channel', 'console'], 60000)
|
|
1272
|
+
if (!direct.ok) return { ok: false, text: '改天气失败:' + direct.text }
|
|
1273
|
+
return { ok: true, text: who + ';不过当前在线 ' + online.length + ' 人(≤' + threshold + ',不用投票),已直接改成「' + typeName + '」。' }
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
ok: false,
|
|
1277
|
+
text: who + ',而当前在线 ' + online.length + ' 人(超过 ' + threshold + '),改天气需要游戏内投票。'
|
|
1278
|
+
+ '先发「绑定游戏名 你的ID」并进服,或者直接在游戏里输入 /weather ' + type + ' 发起。',
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
const started = await runMcAdmin(['-Action', 'cmd', '-Arg', 'execute as ' + onlineName + ' run weather ' + type, '-Actor', 'LOCAL-CONSOLE', '-Channel', 'console'], 60000)
|
|
1282
|
+
if (!started.ok) return { ok: false, text: '发起天气请求失败:' + started.text }
|
|
1283
|
+
const how = online.length <= threshold
|
|
1284
|
+
? '当前在线 ' + online.length + ' 人(≤' + threshold + '),会直接生效'
|
|
1285
|
+
: '当前在线 ' + online.length + ' 人,游戏里已经发起投票,需要 ' + approveNeed + ' 票同意(其他玩家输入 /vote yes)'
|
|
1286
|
+
return { ok: true, text: '已用你的游戏名 ' + onlineName + ' 发起:把天气改成「' + typeName + '」。' + how + '。' }
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1203
1289
|
const isWindows = process.platform === 'win32'
|
|
1204
1290
|
if (!isWindows && !NODE_ACTIONS.has(action)) {
|
|
1205
1291
|
return { ok: false, text: `(${process.platform})${action} 还没跨平台,目前只在 Windows 上可用。跨平台可用的是:${[...NODE_ACTIONS].join(' / ')}` }
|
|
@@ -1338,18 +1424,21 @@ export function apply(ctx, config) {
|
|
|
1338
1424
|
if (typeof ctx.on === 'function') {
|
|
1339
1425
|
ctx.effect(() => ctx.on('system-prompt/assemble', async (assembly, context, next) => {
|
|
1340
1426
|
const assembled = await next()
|
|
1341
|
-
if (persona.enabled === false) return assembled
|
|
1342
|
-
const scope = String(persona.scope || 'qq')
|
|
1343
|
-
if (scope === 'none') return assembled
|
|
1344
1427
|
const agentId = context && context.agent ? String(context.agent.id ?? '') : ''
|
|
1345
1428
|
if (!agentId) return assembled
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
if (!
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1429
|
+
const sections = [...(assembled.sections ?? [])]
|
|
1430
|
+
// QQ 会话一律带上能力清单:明确告诉模型天气对所有玩家开放,别再按旧记忆拒绝
|
|
1431
|
+
if (!isLocalSession(agentId)) {
|
|
1432
|
+
sections.push({ name: 'mc-ops:abilities', order: 90, text: renderAbilities() })
|
|
1433
|
+
}
|
|
1434
|
+
if (persona.enabled !== false) {
|
|
1435
|
+
const scope = String(persona.scope || 'qq')
|
|
1436
|
+
if (scope !== 'none' && !(scope === 'qq' && isLocalSession(agentId))) {
|
|
1437
|
+
const text = renderPersona(persona)
|
|
1438
|
+
if (text) sections.push({ name: 'mc-ops:persona', order: 91, text })
|
|
1439
|
+
}
|
|
1352
1440
|
}
|
|
1441
|
+
return { ...assembled, sections }
|
|
1353
1442
|
}))
|
|
1354
1443
|
}
|
|
1355
1444
|
}
|
|
@@ -1619,6 +1708,17 @@ function checkActionAllowed(action, perms) {
|
|
|
1619
1708
|
return ''
|
|
1620
1709
|
}
|
|
1621
1710
|
|
|
1711
|
+
/** 注入给 QQ 会话的能力清单(system prompt)。重点是天气:所有玩家都能用。 */
|
|
1712
|
+
function renderAbilities() {
|
|
1713
|
+
return [
|
|
1714
|
+
'## 服务器操作能力(mc_server 工具,参数 action + actor)',
|
|
1715
|
+
'- 改天气:action=weather,arg 为 clear / rain / thunder(也可写 晴天 / 下雨 / 雷雨)。',
|
|
1716
|
+
' **所有玩家都能用,不要回复「只有服主能做」**。玩家需要先用 bind-player 绑定游戏名并且当前在游戏里;',
|
|
1717
|
+
' 服主/控制台直接执行。在线 ≤2 人直接生效,≥3 人时游戏内会广播投票(其他玩家输入 /vote yes)。',
|
|
1718
|
+
'- 其它常用 action:status、players、logs、say、gamemode、my-players、bind-player、vote-start / vote-approve / vote-status。',
|
|
1719
|
+
].join('\n')
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1622
1722
|
function renderPersona(persona) {
|
|
1623
1723
|
const p = persona || {}
|
|
1624
1724
|
const text = String(p.text || '').trim() || DEFAULT_PERSONA
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mc-server-ops",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),把人设注入 QQ 会话,并让游戏内玩家用 /ai 和「小铜」对话(配套 Forge mod)。需要先安装 QQ 机器人插件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|