真机联调发现:协议 version 字段=数字 versionCode(源码 8 处 data.version=GameData.versionCode), 框架原发字符串 '1.1' 被服务器版本校验拒绝(kick_server 检查到新版本)。改为数字后登录成功 (state:0 playerid:430511)。 - ChannelIdentity/LoginRequestData.version: string→number,去掉冗余 versionCode 与未发送的 '1.1' 串 - query-string version 解析为数字;测试 fixture 同步 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { buildLoginRequest, parseLoginResponse } from '../../YouleNexus/assets/framework/protocol/login.ts';
|
||
|
||
const IDENTITY = { agentid: 1, gameid: 2, openid: 'o', nickname: 'n', avatar: 'a', sex: 1, province: 'p', city: 'c', unionid: 'u', version: 10001, channelid: 7, marketid: 9 };
|
||
|
||
test('buildLoginRequest 透传必备身份字段', () => {
|
||
const d = buildLoginRequest(IDENTITY);
|
||
assert.equal(d.agentid, 1);
|
||
assert.equal(d.openid, 'o');
|
||
assert.equal(d.marketid, 9);
|
||
});
|
||
|
||
test('parseLoginResponse 提取核心字段 + 房间恢复标志', () => {
|
||
const r = parseLoginResponse({ state: 0, playerid: 9, bean: 100, roomcode: 'ABCD', isbattle: 1, deskinfo: { x: 1 } });
|
||
assert.equal(r.ok, true);
|
||
assert.equal(r.playerid, 9);
|
||
assert.equal(r.inRoom, true);
|
||
assert.equal(r.hasBattle, true);
|
||
assert.deepEqual(r.deskinfo, { x: 1 });
|
||
});
|
||
|
||
test('parseLoginResponse:无 roomcode 时不在房间', () => {
|
||
const r = parseLoginResponse({ state: 0, playerid: 9 });
|
||
assert.equal(r.inRoom, false);
|
||
assert.equal(r.hasBattle, false);
|
||
});
|
||
|
||
test('parseLoginResponse:state!=0 视为失败', () => {
|
||
const r = parseLoginResponse({ state: 1, playerid: -1 });
|
||
assert.equal(r.ok, false);
|
||
});
|