fix: 修复实机运行才暴露的 8 个缺陷,新增控制台添加玩家与移动测试
首次真正连上线上服务器(Debian 12 + pm2 + 端口 78)后暴露的问题,单元测试全绿但机器人干不了活: 致命 - 寻路插件从未加载:项目从没调用 bot.loadPlugin(pathfinder),bot.pathfinder 恒为 undefined、isReady() 恒为 false,扩地任务连启动都启动不了,界面只显示含糊的 「机器人尚未就绪」。现在 createBot 后立刻加载,失败时明确报错。 登录门禁相关(三处死锁) - preLoginCommands 白名单:/login、/register、简幻通的 /auth 本身就是登录流程的一部分, 原先被门禁一并拦下,形成「要先登录才能发登录指令」 - 验证码常被要求直接当聊天内容发出(不是指令),原先被 sendChat 的门禁挡住; 现在服务器明确要求验证时自动放行,另有 server.allowChatBeforeLogin 兜底 - 配置了登录指令却没有密码时 loggedIn 永久为 false,控制台连手动指令都发不出; 现在走与其他「服务器不回提示」一致的超时兜底并给出说明 可用性 - 离线时指令被静默丢弃却回报「已发送」;现在要求已连接并进入世界,失败信息区分 「未连接」「登录被拒」「未通过验证」 - 「被服务器传送」日志洪水:实测 3 分钟 748 行,会冲光日志缓冲并打满 WebSocket; 现在按 30 秒窗口聚合,断开时刷出未汇总计数 - 识别外站账号绑定流程并给出可操作告警,新增 server.authCommand 模板 - 重连指数退避(server.reconnectMaxDelayMs) - 控制台瓦片 URL 与后端路由不一致 新增 - 控制台添加 / 移除玩家:不必改 .env 重启。密码只写入 data/bots.credentials.json (强制 0600),不进仓库、不出现在任何响应里;.env 与凭据文件同名时以 .env 为准, .env 里的账号不允许从控制台移除 - 手动移动测试接口与按钮:绕开寻路器直接按方向键,返回真实位移, 用于区分「算不出路径」与「根本走不动」 - 位置同步诊断:位置包收发计数、onGround、游戏模式、维度、脚下方块与六向实心 - grim.reportOnGroundFromWorld:按世界数据修正出站 onGround(默认开启) - scripts/check-protocol.js:核对包名与字段名同目标版本协议是否一致 文档 - README 新增「部署到服务器」与「机器人走不动的排查方法」两章 已知限制:实测本服上 mineflayer 客户端无法移动(按方向键 2 秒位移 0.00~0.02 格, 服务端每 tick 回弹一次),已排除区块数据、onGround、Grim 层、游戏模式、物理引擎、 寻路插件、teleport_confirm 协议字段等因素,彻底定位需与原生客户端逐字节对比移动包。 连接 / 登录 / 指令 / 聊天 / 公屏日志 / 大地图均正常。 测试从 263 增至 290,全部通过。
这个提交包含在:
+50
-2
@@ -8,7 +8,7 @@ const path = require('path');
|
||||
|
||||
const { WebConsole } = require('../src/web/server');
|
||||
const { BotPool } = require('../src/bot/botPool');
|
||||
const { BotStore } = require('../src/config/botStore');
|
||||
const { BotStore, BotCredentialStore } = require('../src/config/botStore');
|
||||
const { ExpansionLog } = require('../src/core/expansionLog');
|
||||
const { ChatLog, ChatKind } = require('../src/core/chatLog');
|
||||
const { BigMapService } = require('../src/core/bigMapService');
|
||||
@@ -81,7 +81,8 @@ function setup(options) {
|
||||
dataService,
|
||||
expansionLog,
|
||||
chatLog,
|
||||
botStore: new BotStore(path.join(dir, 'bots.json'))
|
||||
botStore: new BotStore(path.join(dir, 'bots.json')),
|
||||
credentialStore: new BotCredentialStore(path.join(dir, 'bots.credentials.json'))
|
||||
});
|
||||
|
||||
const webConsole = new WebConsole({
|
||||
@@ -387,6 +388,53 @@ test('HTTP:配置了控制台密码时未登录一律 401,登录后可访问
|
||||
}
|
||||
});
|
||||
|
||||
test('HTTP:可在控制台新增与移除玩家,响应中不含密码', async () => {
|
||||
const { webConsole, pool } = setup();
|
||||
// 避免测试真的发起网络连接
|
||||
const proto = Object.getPrototypeOf(pool.get('BotA').manager);
|
||||
const originalConnect = proto.connect;
|
||||
proto.connect = function stub() {};
|
||||
await webConsole.start();
|
||||
const base = webConsole.baseUrl();
|
||||
try {
|
||||
const added = await fetch(base + '/api/bots', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: 'NewBot', password: 'super-secret', label: '新号' })
|
||||
}).then((r) => r.json());
|
||||
assert.strictEqual(added.ok, true);
|
||||
assert.strictEqual(added.data.id, 'NewBot');
|
||||
assert.ok(!JSON.stringify(added).includes('super-secret'), '响应中不得回显密码');
|
||||
assert.deepStrictEqual(added.data.bots.map((b) => b.id), ['BotA', 'BotB', 'NewBot']);
|
||||
assert.strictEqual(added.data.bots[2].source, 'store');
|
||||
|
||||
const duplicate = await fetch(base + '/api/bots', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: 'NewBot' })
|
||||
});
|
||||
assert.strictEqual(duplicate.status, 400);
|
||||
|
||||
const invalid = await fetch(base + '/api/bots', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: '带中文的名字' })
|
||||
});
|
||||
assert.strictEqual(invalid.status, 400);
|
||||
|
||||
// .env 里配置的账号不允许从控制台移除
|
||||
const envBot = await fetch(base + '/api/bots/BotA', { method: 'DELETE' });
|
||||
assert.strictEqual(envBot.status, 400);
|
||||
|
||||
const removed = await fetch(base + '/api/bots/NewBot', { method: 'DELETE' }).then((r) => r.json());
|
||||
assert.strictEqual(removed.ok, true);
|
||||
assert.deepStrictEqual(removed.data.bots.map((b) => b.id), ['BotA', 'BotB']);
|
||||
} finally {
|
||||
proto.connect = originalConnect;
|
||||
await webConsole.stop();
|
||||
}
|
||||
});
|
||||
|
||||
test('HTTP:未配置密码时免登录(本机开发模式)', async () => {
|
||||
const { webConsole } = setup();
|
||||
await webConsole.start();
|
||||
|
||||
在新工单中引用
屏蔽一个用户