diff --git a/cocoscreator_projects/YouleNexus/assets/framework/core/types/envelope.ts b/cocoscreator_projects/YouleNexus/assets/framework/core/types/envelope.ts new file mode 100644 index 0000000..66a0d75 --- /dev/null +++ b/cocoscreator_projects/YouleNexus/assets/framework/core/types/envelope.ts @@ -0,0 +1,16 @@ +import type { RouteName } from '../constants.ts'; + +/** 客户端→服务器 单层信封。来源 docs/protocol/01 §3.1。 */ +export interface OutboundEnvelope { + app: 'youle'; + route: RouteName | string; // 游戏内 route 为子游戏名 + rpc: string; + data: T; +} + +/** 服务器→客户端 解包后的内层。来源 docs/protocol/01 §3.2。 */ +export interface InboundMessage { + route: string; + rpc: string; + data: T; +} diff --git a/cocoscreator_projects/YouleNexus/assets/framework/core/types/login.ts b/cocoscreator_projects/YouleNexus/assets/framework/core/types/login.ts new file mode 100644 index 0000000..846b0be --- /dev/null +++ b/cocoscreator_projects/YouleNexus/assets/framework/core/types/login.ts @@ -0,0 +1,26 @@ +/** + * player_login 请求/响应(最小集)。完整字段以 docs/protocol/01 §6、02、04 为准(spec §0.1)。 + * 用索引签名容纳本最小集未显式列出的协议字段,避免在此内联复制全部协议字段。 + */ +export interface LoginRequestData { + agentid: number | string; + gameid: number | string; + openid: string; + nickname: string; + avatar: string; + sex: number; + province: string; + city: string; + unionid: string | number; + version: string; + channelid: number | string; + marketid: number | string; + [extra: string]: unknown; // location/ip/machineid/telphone 等由 Send_login 注入,见 docs/protocol/01 §6 +} + +/** 登录响应 A 组账号资产(核心字段)。完整见 docs/protocol/04。 */ +export interface LoginResponseData { + state: number; // 0=成功 + playerid: number; + [extra: string]: unknown; // bean/roomcard/charm/... 及 B 组房间恢复字段 roomcode/isbattle/deskinfo +} diff --git a/cocoscreator_projects/framework-tests/core/types.typetest.ts b/cocoscreator_projects/framework-tests/core/types.typetest.ts new file mode 100644 index 0000000..ba4b5b3 --- /dev/null +++ b/cocoscreator_projects/framework-tests/core/types.typetest.ts @@ -0,0 +1,9 @@ +import type { OutboundEnvelope, InboundMessage } from '../../YouleNexus/assets/framework/core/types/envelope.ts'; +import type { LoginRequestData, LoginResponseData } from '../../YouleNexus/assets/framework/core/types/login.ts'; + +const out: OutboundEnvelope = { + app: 'youle', route: 'agent', rpc: 'player_login', + data: { agentid: 1, gameid: 2, openid: 'o', nickname: 'n', avatar: 'a', sex: 0, province: '', city: '', unionid: 'u', version: '1', channelid: 0, marketid: 0 }, +}; +const inb: InboundMessage = { route: 'agent', rpc: 'player_login', data: { state: 0, playerid: 9 } }; +void out; void inb;