fix(framework): kick_server 终止不重连(对齐真实客户端)
收到 kick_server 时 emit kicked 并 stop(),不再 onClose→重连→重踢空转。 kick 处理移出登录门控,登录态内外一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,14 +114,14 @@ export class NetClient {
|
|||||||
|
|
||||||
const msg = r.message;
|
const msg = r.message;
|
||||||
if (msg.rpc === 'submit_error') return; // docs §3.2-9
|
if (msg.rpc === 'submit_error') return; // docs §3.2-9
|
||||||
|
// 服务器踢人:发事件并终止,**不自动重连**(对齐真实客户端 kick 弹窗停住;否则会空转重踢)。
|
||||||
|
if (msg.rpc === 'kick_server') { this.bus.emit('kicked', msg.data); this.stop(); return; }
|
||||||
if (this.isSendLoginState) { // docs §3.2-10 登录态门控
|
if (this.isSendLoginState) { // docs §3.2-10 登录态门控
|
||||||
if (msg.rpc === 'player_login') {
|
if (msg.rpc === 'player_login') {
|
||||||
this.isSendLoginState = false; this.isLogin = true;
|
this.isSendLoginState = false; this.isLogin = true;
|
||||||
if (this.loginGuard != null) { this.clock.clearTimeout(this.loginGuard); this.loginGuard = null; }
|
if (this.loginGuard != null) { this.clock.clearTimeout(this.loginGuard); this.loginGuard = null; }
|
||||||
this.policy.reset();
|
this.policy.reset();
|
||||||
this.bus.emit('login', msg.data);
|
this.bus.emit('login', msg.data);
|
||||||
} else if (msg.rpc === 'kick_server') {
|
|
||||||
this.bus.emit('kicked', msg.data);
|
|
||||||
}
|
}
|
||||||
return; // 其它一律丢弃
|
return; // 其它一律丢弃
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,24 @@ test('TcpID 去重:旧连接的残留包被丢弃', async () => {
|
|||||||
assert.equal(messages.length, 0);
|
assert.equal(messages.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('kick_server:emit kicked 且不再自动重连', async () => {
|
||||||
|
const t1 = new FakeTransport(), t2 = new FakeTransport();
|
||||||
|
const { clock, advance } = fakeClock();
|
||||||
|
const client = makeClient([t1, t2], clock);
|
||||||
|
let kicked = 0;
|
||||||
|
client.on('kicked', () => { kicked++; });
|
||||||
|
client.start();
|
||||||
|
await t1.flush();
|
||||||
|
// 服务器踢人(登录态期间)
|
||||||
|
t1.serverPush(JSON.stringify({ route: 'agent', rpc: 'kick_server', data: { msg: 'x' } }));
|
||||||
|
await t1.flush();
|
||||||
|
assert.equal(kicked, 1);
|
||||||
|
// 推进重连/超时定时器 → 不应建立新连接或重发 login
|
||||||
|
advance(30000); advance(10000);
|
||||||
|
await t2.flush();
|
||||||
|
assert.equal(t2.sent.length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
test('debug=true 记录 send 与 recv(注入 logger)', async () => {
|
test('debug=true 记录 send 与 recv(注入 logger)', async () => {
|
||||||
const t = new FakeTransport();
|
const t = new FakeTransport();
|
||||||
const { clock } = fakeClock();
|
const { clock } = fakeClock();
|
||||||
|
|||||||
Reference in New Issue
Block a user