feat(framework): protocol routes 常量 + login 请求构造/响应解析

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-28 14:25:29 +08:00
co-authored by Claude Opus 4.8
parent 540cf286a5
commit 0ada512464
3 changed files with 70 additions and 0 deletions
@@ -0,0 +1,32 @@
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: '1.0', 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);
});