fix(framework): decodeFrame 改单层(服务器协议非双层)
真机联调发现:服务器实发单层 {app,route,rpc,data};旧客户端的'外层 data'是浏览器
MessageEvent(00_minhttp.js:266 ws.onmessage=config.onmessage),非协议层。框架传输层
已取 ev.data,decodeFrame 不应再剥一层。修正后 kick_server 等业务包能正确解析。
- decodeFrame 单层化 + 测试改单层帧
- 更正 docs/protocol/01 §3.2(双层→单层,附 MessageEvent 依据)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -53,15 +53,15 @@ test('isSendLoginState 门控:login 响应前的其它包被丢弃,login 响
|
||||
client.start();
|
||||
await t.flush();
|
||||
// 登录响应前推一个业务包 → 应被门控丢弃
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 5 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 5 } }));
|
||||
await t.flush();
|
||||
assert.equal(messages.length, 0);
|
||||
// 推 login 响应 → 放行,emit login,清门控
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t.flush();
|
||||
assert.equal(loginResp.playerid, 9);
|
||||
// 门控已清,后续业务包放行
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 5 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 5 } }));
|
||||
await t.flush();
|
||||
assert.equal(messages.length, 1);
|
||||
assert.equal(messages[0].rpc, 'update_bean');
|
||||
@@ -76,10 +76,10 @@ test('握手包与心跳包被忽略且不进 message', async () => {
|
||||
client.start();
|
||||
await t.flush();
|
||||
// 先完成登录以清门控
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t.flush();
|
||||
t.serverPush(JSON.stringify({ data: '@toconconABC' })); // 握手
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ com: '@serverheartbeat' }) })); // 心跳
|
||||
t.serverPush('@toconconABC'); // 握手(原始串)
|
||||
t.serverPush(JSON.stringify({ com: '@serverheartbeat' })); // 心跳(单层)
|
||||
await t.flush();
|
||||
assert.equal(messages.length, 0);
|
||||
});
|
||||
@@ -93,7 +93,7 @@ test('收包超时 emit slow 并触发重连(onClose→新连接重发 login
|
||||
client.start();
|
||||
await t1.flush();
|
||||
// 先完成登录:清 4s 守护、feed 收包看门狗(否则 advance 会先撞上 loginGuard 而非 watchdog)
|
||||
t1.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t1.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t1.flush();
|
||||
// 30s 无收包 → watchdog → slow + 关闭当前连接
|
||||
advance(30000);
|
||||
@@ -114,12 +114,12 @@ test('TcpID 去重:旧连接的残留包被丢弃', async () => {
|
||||
client.on('message', (m: any) => messages.push(m));
|
||||
client.start();
|
||||
await t1.flush();
|
||||
t1.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t1.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t1.flush();
|
||||
// 触发重连切到 t2
|
||||
advance(30000); await t1.flush(); advance(10000); await t2.flush();
|
||||
// 旧连接 t1 仍推包 → 应被 TcpID 去重丢弃
|
||||
t1.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 1 } }) }));
|
||||
t1.serverPush(JSON.stringify({ route: 'agent', rpc: 'update_bean', data: { bean: 1 } }));
|
||||
await t1.flush();
|
||||
assert.equal(messages.length, 0);
|
||||
});
|
||||
@@ -139,7 +139,7 @@ test('debug=true 记录 send 与 recv(注入 logger)', async () => {
|
||||
client.start();
|
||||
await t.flush();
|
||||
assert.ok(logs.some((l) => l[0] === '[net] →')); // 发出 player_login 被记录
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t.flush();
|
||||
assert.ok(logs.some((l) => l[0] === '[net] ←')); // 收包被记录
|
||||
});
|
||||
@@ -157,7 +157,7 @@ test('debug 默认关闭:logger 不被调用', async () => {
|
||||
client.setIdentity(IDENTITY);
|
||||
client.start();
|
||||
await t.flush();
|
||||
t.serverPush(JSON.stringify({ data: JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }) }));
|
||||
t.serverPush(JSON.stringify({ route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }));
|
||||
await t.flush();
|
||||
assert.equal(logs.length, 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user