diff --git a/cocoscreator_projects/YouleNexus/assets/framework/config/bootstrap.ts b/cocoscreator_projects/YouleNexus/assets/framework/config/bootstrap.ts index 28d4661..dd38506 100644 --- a/cocoscreator_projects/YouleNexus/assets/framework/config/bootstrap.ts +++ b/cocoscreator_projects/YouleNexus/assets/framework/config/bootstrap.ts @@ -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; // 调试用渠道身份覆盖 + 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 = { 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 }, }; diff --git a/cocoscreator_projects/framework-tests/config/bootstrap.test.ts b/cocoscreator_projects/framework-tests/config/bootstrap.test.ts index 42b6daa..af7b1b7 100644 --- a/cocoscreator_projects/framework-tests/config/bootstrap.test.ts +++ b/cocoscreator_projects/framework-tests/config/bootstrap.test.ts @@ -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); +}); diff --git a/docs/guides/配置与调试指南.md b/docs/guides/配置与调试指南.md index 26a7d4a..7c5b427 100644 --- a/docs/guides/配置与调试指南.md +++ b/docs/guides/配置与调试指南.md @@ -167,8 +167,13 @@ interface DebugProfile { server?: string; // 显式 ws 调试服地址;给定则跳过远程抓取 gameserver?: string; // 远程配置 txt URL(不含防缓存串) identity?: Partial; // 调试用渠道身份覆盖 + 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) */ });