feat(framework): config 调试登录账号进 profile(DebugAccount)

- DebugProfile 加 account?: DebugAccount(openid 等登录字段,仅 debug 模式生效)
- resolveBootstrap 结果加 account:debug 取 profile.account,release 恒 undefined
- staging profile 留占位 account 待填真值;接入处 setIdentity 合并 identity+account
- 同步指南

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-28 19:57:41 +08:00
co-authored by Claude Opus 4.8
parent 51a4ee57ac
commit d461578d6e
4 changed files with 46 additions and 4 deletions
@@ -3,7 +3,7 @@ import { resolveIdentity } from './identity.ts';
import { BUILD_IDENTITY } from './sources/defaults.ts';
import { queryStringSource } from './sources/query-string.ts';
import { nativeSettingsSource, type NativeHost } from './sources/native-settings.ts';
import { resolveActiveProfile, PROFILES, type DebugProfile } from './profiles.ts';
import { resolveActiveProfile, PROFILES, type DebugProfile, type DebugAccount } from './profiles.ts';
import { resolveServers, type ConfigFetcher, type RemoteConfig, ConfigFetchError } from './remote-config.ts';
import type { RuntimeMode } from './runtime-mode.ts';
@@ -20,6 +20,7 @@ export interface BootstrapResult {
mode: RuntimeMode;
isDebugger: boolean; // = (mode === 'debug')
identity: ChannelIdentity;
account?: DebugAccount; // 调试登录账号(仅 debug 模式有值;release 恒 undefined)
servers: string[];
rawConfig: RemoteConfig | null;
profile: DebugProfile;
@@ -47,7 +48,9 @@ export async function resolveBootstrap(opts: BootstrapOptions): Promise<Bootstra
nativeSettingsSource(opts.win), // release:身份只取原生,URL 一律无效
]);
const resultBase = { mode: opts.mode, isDebugger: isDebug, identity, profile };
// 调试账号只在 debug 模式从 profile 取;release 不读调试配置账号。
const account = isDebug ? profile.account : undefined;
const resultBase = { mode: opts.mode, isDebugger: isDebug, identity, account, profile };
// 服务器决策:profile 显式 server 直连捷径
if (profile.server) {
@@ -1,10 +1,22 @@
import type { ChannelIdentity } from './identity.ts';
/** 调试用登录玩家档案(player_login 中除渠道身份外的字段)。仅 debug 模式生效。 */
export interface DebugAccount {
openid: string; // 服务器据此标识玩家(必填)
nickname?: string;
avatar?: string;
sex?: number;
province?: string;
city?: string;
unionid?: string | number;
}
export interface DebugProfile {
name: string;
server?: string; // 显式 ws 调试服地址(给定则跳过远程抓取)
gameserver?: string; // 远程配置 txt URL(不含防缓存串)
identity?: Partial<ChannelIdentity>; // 调试用渠道身份覆盖
account?: DebugAccount; // 调试用登录账号(仅 debug 模式生效)
isDebugger?: boolean; // 收发包日志开关(替代旧 Game_Config.Debugger.isDebugger)
}
@@ -15,7 +27,13 @@ const STAGING_GAMESERVER = 'https://tsgames.daoqi88.cn/config_test/beta_update_j
export const PROFILES: Record<string, DebugProfile> = {
prod: { name: 'prod', gameserver: DEFAULT_GAMESERVER, isDebugger: false },
staging: { name: 'staging', gameserver: STAGING_GAMESERVER, isDebugger: true },
staging: {
name: 'staging',
gameserver: STAGING_GAMESERVER,
isDebugger: true,
// 调试登录账号:联调前替换为真实测试账号(openid 必填)。仅 debug 模式生效。
account: { openid: 'REPLACE_ME_test_openid', nickname: '测试号', avatar: '', sex: 0, province: '', city: '', unionid: '' },
},
local: { name: 'local', server: 'ws://127.0.0.1:3088', isDebugger: true },
};
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import { resolveBootstrap } from '../../YouleNexus/assets/framework/config/bootstrap.ts';
import { BUILD_IDENTITY } from '../../YouleNexus/assets/framework/config/sources/defaults.ts';
import type { ConfigFetcher, RemoteConfig } from '../../YouleNexus/assets/framework/config/remote-config.ts';
import { PROFILES } from '../../YouleNexus/assets/framework/config/profiles.ts';
function fetcherReturning(config: RemoteConfig): ConfigFetcher & { calls: string[] } {
const calls: string[] = [];
@@ -87,3 +88,15 @@ test('release:原生身份仍生效(URL 的 999 无效)', async () => {
assert.equal(r.identity.agentid, 'NA');
assert.equal(r.identity.channelid, 'NC');
});
test('debug:account 来自当前 profile', async () => {
const fetcher = fetcherReturning(REMOTE);
const r = await resolveBootstrap({ mode: 'debug', win: {}, search: '?profile=staging', fetcher, isNative: false });
assert.deepEqual(r.account, PROFILES.staging.account);
});
test('release:account 恒为 undefined(不从调试配置泄漏账号)', async () => {
const fetcher = fetcherReturning(REMOTE);
const r = await resolveBootstrap({ mode: 'release', win: {}, search: '?profile=staging', fetcher, isNative: true });
assert.equal(r.account, undefined);
});
+9 -1
View File
@@ -167,8 +167,13 @@ interface DebugProfile {
server?: string; // 显式 ws 调试服地址;给定则跳过远程抓取
gameserver?: string; // 远程配置 txt URL(不含防缓存串)
identity?: Partial<ChannelIdentity>; // 调试用渠道身份覆盖
account?: DebugAccount; // 调试用登录账号(openid 等),仅 debug 模式生效
isDebugger?: boolean; // 收发包日志开关
}
// DebugAccount:player_login 中除渠道身份外的字段(openid 必填,其余可选)
// { openid, nickname?, avatar?, sex?, province?, city?, unionid? }
// 联调账号写在这里(profile 是唯一权威来源),不要散在调试脚本里。
```
### 内置档位(`config/profiles.ts`)
@@ -313,6 +318,7 @@ interface BootstrapOptions {
interface BootstrapResult {
identity: ChannelIdentity;
account?: DebugAccount; // 调试登录账号(仅 debug 模式有值;release 恒 undefined)
servers: string[];
rawConfig: RemoteConfig | null; // 直连档位为 null
profile: DebugProfile;
@@ -352,9 +358,11 @@ async function startup() {
});
// 渠道身份 + 玩家档案合并成完整 player_login 数据
// debug:玩家档案来自 result.account(profile 里配的调试账号,单一权威来源)
// release:result.account 为 undefined,玩家档案由 platform 层/原生提供(后续 Plan)
net.setIdentity({
...result.identity, // agentid/channelid/gameid/marketid/version...
openid, nickname, avatar, sex, province, city, unionid, // 来自登录/微信信息
...(result.account ?? {}), // openid/nickname/avatar/... 调试账号或平台层登录信息
});
net.on('login', (data) => { /* 解析 parseLoginResponse(data) */ });