From 56dbfeb5e260b5466029093b696747ab89e7e8ce Mon Sep 17 00:00:00 2001 From: Joywayer Date: Sun, 28 Jun 2026 14:20:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(framework):=20core=20=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E9=9B=86=E5=8D=8F=E8=AE=AE=E7=B1=BB=E5=9E=8B(envelope/login)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../assets/framework/core/types/envelope.ts | 16 ++++++++++++ .../assets/framework/core/types/login.ts | 26 +++++++++++++++++++ .../framework-tests/core/types.typetest.ts | 9 +++++++ 3 files changed, 51 insertions(+) create mode 100644 cocoscreator_projects/YouleNexus/assets/framework/core/types/envelope.ts create mode 100644 cocoscreator_projects/YouleNexus/assets/framework/core/types/login.ts create mode 100644 cocoscreator_projects/framework-tests/core/types.typetest.ts 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;