dsh-mc-server-ops 0.6.2 → 0.6.3

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 +17 -0
  2. package/client.js +28 -0
  3. package/index.js +58 -0
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -37,6 +37,7 @@
37
37
  - **授权**:动受保护区域(world、ops\data、白名单)要 2 位群友投票;**凑满 2 票之前任何人反对就作废**
38
38
  - **人设**:默认「小铜」,名字和语气都能在设置里改
39
39
  - **游戏内 AI**:装上配套 Forge mod 后,玩家在游戏里 `/ai <内容>` 就能和「小铜」对话(只监听 `127.0.0.1`,按玩家 UUID 复用独立会话);mod 1.1.0 起还能带截图/文件附件
40
+ - **天气投票**:配套 mod 1.2.0 起,游戏内玩家可用 `/weather` 改天气;在线 ≤2 人直接生效,3 人及以上要 `/vote yes` 投票(2 票同意通过),门槛都能在设置面板改
40
41
 
41
42
  ## 安装
42
43
 
@@ -110,6 +111,11 @@ dsh plugin add /path/to/dsh-mc-server-ops
110
111
  | `ai.enabled` | `true` | 是否开游戏内 `/ai` 对话(需要配套 Forge mod;只监听 `127.0.0.1`) |
111
112
  | `ai.port` | `8765` | mod 连接的本地端口 |
112
113
  | `ai.timeoutSeconds` | `60` | 等 AI 回复的超时秒数 |
114
+ | `weather.enabled` | `true` | 允许游戏内玩家用 `/weather` 改天气(需要 mcai mod 1.2.0+) |
115
+ | `weather.directThreshold` | `2` | 在线 ≤ 这个数时直接改天气;更多人才发起投票 |
116
+ | `weather.approveNeed` / `weather.rejectNeed` | `2` / `1` | 通过需要几票同意 / 几票反对作废(发起人自动算 1 票同意) |
117
+ | `weather.timeoutSeconds` | `60` | 投票有效期(秒) |
118
+ | `weather.cooldownSeconds` | `60` | 同一玩家两次发起的最小间隔(秒) |
113
119
 
114
120
  ## 目录结构
115
121
 
@@ -274,6 +280,17 @@ powershell -File <服务器目录>\ops\mcadmin.ps1 -Action owner-add -Arg <openi
274
280
 
275
281
  游戏内玩家和群友一样受权限守卫限制:只读查询可以,写文件、执行命令需要服主授权;mod 侧默认每玩家 5 秒冷却,避免刷屏。
276
282
 
283
+ ## 游戏内天气投票(/weather)
284
+
285
+ 配套 Forge mod **mcai 1.2.0+**:游戏内所有玩家都能用 `/weather clear|rain|thunder [持续秒数]` 改天气(mod 会把原版需要 OP 的 `/weather` 换成对所有人开放)。
286
+
287
+ - 在线玩家 **≤ `weather.directThreshold`(默认 2)**:直接生效,全服提示「XX 把天气改成了下雨」
288
+ - **3 人及以上**:发起投票,发起人自动算 1 票同意;其他人在游戏里用 `/vote yes` 同意、`/vote no` 反对、`/vote status` 查看
289
+ - 同意达到 `weather.approveNeed`(默认 2)通过;反对达到 `weather.rejectNeed`(默认 1)作废;`weather.timeoutSeconds`(默认 60 秒)没结果也会作废
290
+ - 同一玩家两次发起间隔 `weather.cooldownSeconds`(默认 60 秒)
291
+ - 配置写在 `<服务器目录>/config/mcai-weather.json`,mod 每次 `/weather` 都读它,所以**设置面板改完即时生效**,不用重启服务器
292
+ - 服务器装的是旧版 mod(< 1.2.0)时,这个配置不会生效,`/weather` 也还是原版需要 OP 的版本
293
+
277
294
  ## 安全模型
278
295
 
279
296
  - 仓库和 npm 包里**不含任何口令、QQ 号、记忆数据或整合包**。
package/client.js CHANGED
@@ -182,6 +182,14 @@ window.__ModuleLoader__.load({
182
182
  ? (v.vote || {}).protectedPaths.join(", ")
183
183
  : "world, ops/data, whitelist",
184
184
  },
185
+ weather: {
186
+ enabled: (v.weather || {}).enabled !== false,
187
+ directThreshold: (v.weather || {}).directThreshold ?? 2,
188
+ approveNeed: (v.weather || {}).approveNeed ?? 2,
189
+ rejectNeed: (v.weather || {}).rejectNeed ?? 1,
190
+ timeoutSeconds: (v.weather || {}).timeoutSeconds ?? 60,
191
+ cooldownSeconds: (v.weather || {}).cooldownSeconds ?? 60,
192
+ },
185
193
  permissions: {
186
194
  voteEscalation: (v.permissions || {}).voteEscalation !== false,
187
195
  kubejsEdit: (v.permissions || {}).kubejsEdit !== false,
@@ -225,6 +233,9 @@ window.__ModuleLoader__.load({
225
233
  bridge: Object.assign({}, prev.bridge, { coalesce: Object.assign({}, prev.bridge.coalesce, { [key]: value }) }),
226
234
  }) : prev))
227
235
  }
236
+ function patchWeather(key, value) {
237
+ setForm((prev) => (prev ? Object.assign({}, prev, { weather: Object.assign({}, prev.weather, { [key]: value }) }) : prev))
238
+ }
228
239
 
229
240
  async function save() {
230
241
  if (!form) return
@@ -395,6 +406,23 @@ window.__ModuleLoader__.load({
395
406
  h(Field, { label: "受保护路径", hint: "逗号分隔,改动这些位置要走投票。默认 world, ops/data, whitelist" },
396
407
  h(TextInput, { value: form.vote.protectedPaths, placeholder: "world, ops/data, whitelist", onChange: (x) => patch("vote", "protectedPaths", x) })),
397
408
  ),
409
+ h("div", null,
410
+ h("div", { style: titleStyle }, "游戏内天气投票"),
411
+ h("div", { style: hintStyle }, "玩家在游戏里用 /weather 改天气,在线人少直接生效、人多时 /vote 投票。配置写到服务器 config/mcai-weather.json,改完即时生效(需要 mcai mod 1.2.0+)。"),
412
+ ),
413
+ h("div", { style: groupStyle },
414
+ h(Toggle, { label: "允许玩家改天气(/weather)", value: form.weather.enabled, onChange: (x) => patchWeather("enabled", x) }),
415
+ h(Field, { label: "在线不超过几人时直接生效", hint: "默认 2:0-2 人直接改;3 人及以上发起投票" },
416
+ h(NumberInput, { value: form.weather.directThreshold, onChange: (x) => patchWeather("directThreshold", x) })),
417
+ h(Field, { label: "投票需要几人同意", hint: "默认 2;发起人自动算 1 票同意" },
418
+ h(NumberInput, { value: form.weather.approveNeed, onChange: (x) => patchWeather("approveNeed", x) })),
419
+ h(Field, { label: "几人反对就作废", hint: "默认 1 = 一票否决" },
420
+ h(NumberInput, { value: form.weather.rejectNeed, onChange: (x) => patchWeather("rejectNeed", x) })),
421
+ h(Field, { label: "投票有效期(秒)", hint: "默认 60 秒;到点没结果自动作废" },
422
+ h(NumberInput, { value: form.weather.timeoutSeconds, onChange: (x) => patchWeather("timeoutSeconds", x) })),
423
+ h(Field, { label: "发起冷却(秒)", hint: "同一玩家两次 /weather 的最小间隔,默认 60 秒,0 = 不限" },
424
+ h(NumberInput, { value: form.weather.cooldownSeconds, onChange: (x) => patchWeather("cooldownSeconds", x) })),
425
+ ),
398
426
  h("div", null,
399
427
  h("div", { style: titleStyle }, "群服互通"),
400
428
  h("div", { style: hintStyle }, "把游戏内聊天直接转发到 QQ 群。走机器人自己的接口,不经过 AI、不消耗 token。"),
package/index.js CHANGED
@@ -379,6 +379,21 @@ export const Config = Schema.object({
379
379
  .description('受保护路径:改动这些位置需要群友投票放行。默认 world, ops/data, whitelist'),
380
380
  }).description('投票'),
381
381
 
382
+ weather: Schema.object({
383
+ enabled: Schema.boolean().default(true)
384
+ .description('允许游戏内玩家用 /weather 改天气(需要 mcai mod 1.2.0+)。配置会写到服务器 config/mcai-weather.json,改完即时生效'),
385
+ directThreshold: Schema.number().min(0).max(20).default(2)
386
+ .description('在线玩家不超过这个数时直接改天气、不投票(默认 2:0-2 人直接生效)'),
387
+ approveNeed: Schema.number().min(1).max(20).default(2)
388
+ .description('投票通过需要几人同意(发起人自动算 1 票;默认 2)'),
389
+ rejectNeed: Schema.number().min(1).max(20).default(1)
390
+ .description('几人反对就作废(默认 1 = 一票否决)'),
391
+ timeoutSeconds: Schema.number().min(5).max(3600).default(60)
392
+ .description('投票有效期(秒,默认 60)'),
393
+ cooldownSeconds: Schema.number().min(0).max(86400).default(60)
394
+ .description('同一玩家两次发起的最小间隔(秒,默认 60,0 = 不限)'),
395
+ }).description('游戏内天气投票(配套 mcai mod)'),
396
+
382
397
  adapter: Schema.union(['local', 'panel']).default('local')
383
398
  .description('写操作走哪条路:local=本机直接跑脚本(默认);panel=通过 Pterodactyl 面板的 HTTP API 启停/发指令'),
384
399
  panel: Schema.object({
@@ -715,13 +730,20 @@ export function apply(ctx, config) {
715
730
  maxPerDay: 900,
716
731
  }, (config && config.bridge) || {}),
717
732
  ai: Object.assign({ enabled: true, port: 8765, timeoutSeconds: 60 }, (config && config.ai) || {}),
733
+ weather: Object.assign({
734
+ enabled: true, directThreshold: 2, approveNeed: 2, rejectNeed: 1,
735
+ timeoutSeconds: 60, cooldownSeconds: 60,
736
+ }, (config && config.weather) || {}),
718
737
  }
738
+ // 启动时先把天气投票配置写到服务器 config/mcai-weather.json;mod 每次 /weather 都读这个文件。
739
+ writeWeatherConfig(serverDir, liveConfig.weather)
719
740
  const memoryConfig = {
720
741
  get: () => liveConfig,
721
742
  set: (next) => {
722
743
  liveConfig = Object.assign({}, liveConfig, next && typeof next === 'object' ? next : {})
723
744
  writeVoteConfig(opsDir, liveConfig.vote)
724
745
  setProtectedPaths(liveConfig.vote && liveConfig.vote.protectedPaths)
746
+ writeWeatherConfig(paths.serverDir, liveConfig.weather)
725
747
  },
726
748
  }
727
749
  // 启动时先落一份,保证脚本读到的是当前设置
@@ -836,6 +858,7 @@ export function apply(ctx, config) {
836
858
  void bridge.start()
837
859
  const tick = setInterval(() => {
838
860
  resolveBridgeGroups((liveConfig && liveConfig.bridge) || {})
861
+ writeWeatherConfig(serverDir, liveConfig.weather)
839
862
  writeBridgeState(serverDir, Object.assign(
840
863
  { appId: appId ? appId.slice(0, 3) + '***' : '', hasSecret: !!appSecret },
841
864
  bridge.status(),
@@ -1473,6 +1496,7 @@ async function handleConfigRoute(req, res, services, fallbackConfig) {
1473
1496
  if (desc) {
1474
1497
  await settings.update(desc.ns, body, desc.revision)
1475
1498
  fallbackConfig.set(body)
1499
+ writeWeatherConfig(paths.serverDir, (body && body.weather) || (fallbackConfig.get() || {}).weather)
1476
1500
  return send(200, { ok: true, via: 'settings' })
1477
1501
  }
1478
1502
  if (editor && typeof editor.entries === 'function' && typeof editor.edit === 'function') {
@@ -1485,6 +1509,7 @@ async function handleConfigRoute(req, res, services, fallbackConfig) {
1485
1509
  if (entry) {
1486
1510
  await editor.edit(entry, (current) => Object.assign({}, current || {}, body))
1487
1511
  fallbackConfig.set(body)
1512
+ writeWeatherConfig(paths.serverDir, (body && body.weather) || (fallbackConfig.get() || {}).weather)
1488
1513
  return send(200, { ok: true, via: 'configEditor' })
1489
1514
  }
1490
1515
  }
@@ -1533,6 +1558,39 @@ function readBridgeState() {
1533
1558
 
1534
1559
 
1535
1560
 
1561
+ /** 把天气投票配置写到服务器 config/mcai-weather.json;mod 每次 /weather 时读取,改完即时生效。 */
1562
+ let lastWeatherConfigCore = ''
1563
+ function writeWeatherConfig(serverDir, weatherCfg) {
1564
+ try {
1565
+ const src = weatherCfg || {}
1566
+ const clampInt = (value, fallback, min, max) => {
1567
+ const n = Number(value)
1568
+ const v = Number.isFinite(n) ? Math.round(n) : fallback
1569
+ return Math.max(min, Math.min(max, v))
1570
+ }
1571
+ const core = {
1572
+ enabled: src.enabled !== false,
1573
+ directThreshold: clampInt(src.directThreshold, 2, 0, 20),
1574
+ approveNeed: clampInt(src.approveNeed, 2, 1, 20),
1575
+ rejectNeed: clampInt(src.rejectNeed, 1, 1, 20),
1576
+ timeoutSeconds: clampInt(src.timeoutSeconds, 60, 5, 3600),
1577
+ cooldownSeconds: clampInt(src.cooldownSeconds, 60, 0, 86400),
1578
+ }
1579
+ const coreText = JSON.stringify(core)
1580
+ if (coreText === lastWeatherConfigCore) return core
1581
+ const dir = join(serverDir, 'config')
1582
+ mkdirSync(dir, { recursive: true })
1583
+ writeFileSync(join(dir, 'mcai-weather.json'), JSON.stringify(Object.assign({}, core, {
1584
+ updatedAt: new Date().toISOString(),
1585
+ managedBy: 'dsh-mc-server-ops',
1586
+ }), null, 2) + '\n', 'utf8')
1587
+ lastWeatherConfigCore = coreText
1588
+ return core
1589
+ } catch (error) {
1590
+ return null
1591
+ }
1592
+ }
1593
+
1536
1594
  /** 把投票门槛写到 ops\data\vote-config.json,脚本每次调用时读它。 */
1537
1595
  function writeVoteConfig(opsPath, voteCfg, fallback) {
1538
1596
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mc-server-ops",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),把人设注入 QQ 会话,并让游戏内玩家用 /ai 和「小铜」对话(配套 Forge mod)。需要先安装 QQ 机器人插件。",
5
5
  "type": "module",
6
6
  "main": "./index.js",