feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 游戏网络协议定义
|
|
|
|
|
|
* @en Game Network Protocol Definition
|
|
|
|
|
|
*
|
|
|
|
|
|
* @zh 定义客户端与服务器之间的通信协议
|
|
|
|
|
|
* @en Defines the communication protocol between client and server
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { rpc } from '@esengine/rpc'
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// Message Types | 消息类型
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 玩家输入
|
|
|
|
|
|
* @en Player input
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface PlayerInput {
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 输入序列号(用于客户端预测)
|
|
|
|
|
|
* @en Input sequence number (for client prediction)
|
|
|
|
|
|
*/
|
|
|
|
|
|
seq: number
|
|
|
|
|
|
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 帧序号
|
|
|
|
|
|
* @en Frame number
|
|
|
|
|
|
*/
|
|
|
|
|
|
frame: number
|
|
|
|
|
|
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 客户端时间戳
|
|
|
|
|
|
* @en Client timestamp
|
|
|
|
|
|
*/
|
|
|
|
|
|
timestamp: number
|
|
|
|
|
|
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 移动方向
|
|
|
|
|
|
* @en Move direction
|
|
|
|
|
|
*/
|
|
|
|
|
|
moveDir?: { x: number; y: number }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 动作列表
|
|
|
|
|
|
* @en Action list
|
|
|
|
|
|
*/
|
|
|
|
|
|
actions?: string[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 实体同步状态
|
|
|
|
|
|
* @en Entity sync state
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface EntitySyncState {
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 网络实体 ID
|
|
|
|
|
|
* @en Network entity ID
|
|
|
|
|
|
*/
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
netId: number
|
2025-12-29 10:42:48 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 位置
|
|
|
|
|
|
* @en Position
|
|
|
|
|
|
*/
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
pos?: { x: number; y: number }
|
2025-12-29 10:42:48 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 旋转角度
|
|
|
|
|
|
* @en Rotation angle
|
|
|
|
|
|
*/
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
rot?: number
|
2025-12-29 10:42:48 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 速度(用于外推)
|
|
|
|
|
|
* @en Velocity (for extrapolation)
|
|
|
|
|
|
*/
|
|
|
|
|
|
vel?: { x: number; y: number }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 角速度
|
|
|
|
|
|
* @en Angular velocity
|
|
|
|
|
|
*/
|
|
|
|
|
|
angVel?: number
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 自定义数据
|
|
|
|
|
|
* @en Custom data
|
|
|
|
|
|
*/
|
|
|
|
|
|
custom?: Record<string, unknown>
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 同步消息
|
|
|
|
|
|
* @en Sync message
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface SyncData {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 服务器帧号
|
|
|
|
|
|
* @en Server frame number
|
|
|
|
|
|
*/
|
|
|
|
|
|
frame: number
|
|
|
|
|
|
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 服务器时间戳(用于插值)
|
|
|
|
|
|
* @en Server timestamp (for interpolation)
|
|
|
|
|
|
*/
|
|
|
|
|
|
timestamp: number
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 已确认的输入序列号(用于客户端预测校正)
|
|
|
|
|
|
* @en Acknowledged input sequence (for client prediction reconciliation)
|
|
|
|
|
|
*/
|
|
|
|
|
|
ackSeq?: number
|
|
|
|
|
|
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 实体状态列表
|
|
|
|
|
|
* @en Entity state list
|
|
|
|
|
|
*/
|
|
|
|
|
|
entities: EntitySyncState[]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 生成消息
|
|
|
|
|
|
* @en Spawn message
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface SpawnData {
|
|
|
|
|
|
netId: number
|
|
|
|
|
|
ownerId: number
|
|
|
|
|
|
prefab: string
|
|
|
|
|
|
pos: { x: number; y: number }
|
|
|
|
|
|
rot?: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 销毁消息
|
|
|
|
|
|
* @en Despawn message
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface DespawnData {
|
|
|
|
|
|
netId: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 完整状态快照(用于重连)
|
|
|
|
|
|
* @en Full state snapshot (for reconnection)
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface FullStateData {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 服务器帧号
|
|
|
|
|
|
* @en Server frame number
|
|
|
|
|
|
*/
|
|
|
|
|
|
frame: number
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 服务器时间戳
|
|
|
|
|
|
* @en Server timestamp
|
|
|
|
|
|
*/
|
|
|
|
|
|
timestamp: number
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 所有实体状态
|
|
|
|
|
|
* @en All entity states
|
|
|
|
|
|
*/
|
|
|
|
|
|
entities: Array<SpawnData & { state?: EntitySyncState }>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// API Types | API 类型
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 加入房间请求
|
|
|
|
|
|
* @en Join room request
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface JoinRequest {
|
|
|
|
|
|
playerName: string
|
|
|
|
|
|
roomId?: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 加入房间响应
|
|
|
|
|
|
* @en Join room response
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface JoinResponse {
|
|
|
|
|
|
playerId: number
|
|
|
|
|
|
roomId: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-29 10:42:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @zh 重连请求
|
|
|
|
|
|
* @en Reconnect request
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface ReconnectRequest {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 之前的玩家 ID
|
|
|
|
|
|
* @en Previous player ID
|
|
|
|
|
|
*/
|
|
|
|
|
|
playerId: number
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 房间 ID
|
|
|
|
|
|
* @en Room ID
|
|
|
|
|
|
*/
|
|
|
|
|
|
roomId: string
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 重连令牌
|
|
|
|
|
|
* @en Reconnection token
|
|
|
|
|
|
*/
|
|
|
|
|
|
token: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 重连响应
|
|
|
|
|
|
* @en Reconnect response
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface ReconnectResponse {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 是否成功
|
|
|
|
|
|
* @en Whether successful
|
|
|
|
|
|
*/
|
|
|
|
|
|
success: boolean
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 完整状态(成功时)
|
|
|
|
|
|
* @en Full state (when successful)
|
|
|
|
|
|
*/
|
|
|
|
|
|
state?: FullStateData
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 错误信息(失败时)
|
|
|
|
|
|
* @en Error message (when failed)
|
|
|
|
|
|
*/
|
|
|
|
|
|
error?: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
// ============================================================================
|
|
|
|
|
|
// Protocol Definition | 协议定义
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 默认游戏网络协议
|
|
|
|
|
|
* @en Default game network protocol
|
|
|
|
|
|
*
|
|
|
|
|
|
* @example
|
|
|
|
|
|
* ```typescript
|
|
|
|
|
|
* // 使用默认协议
|
|
|
|
|
|
* const service = new NetworkService(gameProtocol)
|
|
|
|
|
|
*
|
|
|
|
|
|
* // 或者扩展协议
|
|
|
|
|
|
* const customProtocol = rpc.define({
|
|
|
|
|
|
* api: {
|
|
|
|
|
|
* ...gameProtocol.api,
|
|
|
|
|
|
* customApi: rpc.api<CustomInput, CustomOutput>(),
|
|
|
|
|
|
* },
|
|
|
|
|
|
* msg: {
|
|
|
|
|
|
* ...gameProtocol.msg,
|
|
|
|
|
|
* customMsg: rpc.msg<CustomData>(),
|
|
|
|
|
|
* },
|
|
|
|
|
|
* })
|
|
|
|
|
|
* ```
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const gameProtocol = rpc.define({
|
|
|
|
|
|
api: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 加入房间
|
|
|
|
|
|
* @en Join room
|
|
|
|
|
|
*/
|
|
|
|
|
|
join: rpc.api<JoinRequest, JoinResponse>(),
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 离开房间
|
|
|
|
|
|
* @en Leave room
|
|
|
|
|
|
*/
|
|
|
|
|
|
leave: rpc.api<void, void>(),
|
2025-12-29 10:42:48 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 重连
|
|
|
|
|
|
* @en Reconnect
|
|
|
|
|
|
*/
|
|
|
|
|
|
reconnect: rpc.api<ReconnectRequest, ReconnectResponse>(),
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
msg: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 玩家输入
|
|
|
|
|
|
* @en Player input
|
|
|
|
|
|
*/
|
|
|
|
|
|
input: rpc.msg<PlayerInput>(),
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 状态同步
|
|
|
|
|
|
* @en State sync
|
|
|
|
|
|
*/
|
|
|
|
|
|
sync: rpc.msg<SyncData>(),
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 实体生成
|
|
|
|
|
|
* @en Entity spawn
|
|
|
|
|
|
*/
|
|
|
|
|
|
spawn: rpc.msg<SpawnData>(),
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 实体销毁
|
|
|
|
|
|
* @en Entity despawn
|
|
|
|
|
|
*/
|
|
|
|
|
|
despawn: rpc.msg<DespawnData>(),
|
2025-12-29 10:42:48 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 完整状态快照
|
|
|
|
|
|
* @en Full state snapshot
|
|
|
|
|
|
*/
|
|
|
|
|
|
fullState: rpc.msg<FullStateData>(),
|
feat(rpc,network): 新增 RPC 库并迁移网络模块 (#364)
* feat(rpc,network): 新增 RPC 库并迁移网络模块
## @esengine/rpc (新增)
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增 RpcClient 类:connect/disconnect, call/send/on/off/once 方法
- 新增 RpcServer 类:Node.js WebSocket 服务端
- 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
## @esengine/network (重构)
- 重构 NetworkService:拆分为 RpcService 基类和 GameNetworkService
- 新增 gameProtocol:类型安全的 API 和消息定义
- 新增类型安全便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
## 文档
- 新增 RPC 模块文档(中英文)
- 更新 Network 模块文档(中英文)
- 更新侧边栏导航
* fix(network,cli): 修复 CI 构建和更新 CLI 适配器
## 修复
- 在 tsconfig.build.json 添加 rpc 引用,修复类型声明生成
## CLI 更新
- 更新 nodejs 适配器使用新的 @esengine/rpc
- 生成的服务器代码使用 RpcServer 替代旧的 GameServer
- 添加 ws 和 @types/ws 依赖
- 更新 README 模板中的客户端连接示例
* chore: 添加 CLI changeset
* fix(ci): add @esengine/rpc to build and check scripts
- Add rpc package to CI build step (must build before network)
- Add rpc to type-check:framework, lint:framework, test:ci:framework
* fix(rpc,network): fix tsconfig for declaration generation
- Remove composite mode from rpc (not needed, causes CI issues)
- Remove rpc from network project references (resolves via node_modules)
- Remove unused references from network tsconfig.build.json
2025-12-28 10:54:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @zh 游戏协议类型
|
|
|
|
|
|
* @en Game protocol type
|
|
|
|
|
|
*/
|
|
|
|
|
|
export type GameProtocol = typeof gameProtocol
|