feat(server): add Schema validation system and binary encoding optimization (#421)
* feat(server): add distributed room support - Add DistributedRoomManager for multi-server room management - Add MemoryAdapter for testing and standalone mode - Add RedisAdapter for production multi-server deployments - Add LoadBalancedRouter with 5 load balancing strategies - Add distributed config option to createServer - Add $redirect message for cross-server player redirection - Add failover mechanism for automatic room recovery - Add room:migrated and server:draining event types - Update documentation (zh/en) * feat(server): add Schema validation system and binary encoding optimization ## Schema Validation System - Add lightweight schema validation system (s.object, s.string, s.number, etc.) - Support auto type inference with Infer<> generic - Integrate schema validation into API/message handlers - Add defineApiWithSchema and defineMsgWithSchema helpers ## Binary Encoding Optimization - Add native WebSocket binary frame support via sendBinary() - Add PacketType.Binary for efficient binary data transmission - Optimize ECSRoom.broadcastBinary() to use native binary ## Architecture Improvements - Extract BaseValidator to separate file to eliminate code duplication - Add ECSRoom export to main index.ts for better discoverability - Add Core.worldManager initialization check in ECSRoom constructor - Remove deprecated validate field from ApiDefinition (use schema instead) ## Documentation - Add Schema validation documentation in Chinese and English * fix(rpc): resolve ESLint warnings with proper types - Replace `any` with proper WebSocket type in connection.ts - Add IncomingMessage type for request handling in index.ts - Use Record<string, Handler> pattern instead of `any` casting - Replace `any` with `unknown` in ProtocolDef and type inference
This commit is contained in:
21
.changeset/distributed-room-support.md
Normal file
21
.changeset/distributed-room-support.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
"@esengine/server": minor
|
||||
---
|
||||
|
||||
feat(server): 添加分布式房间支持 | Add distributed room support
|
||||
|
||||
**@esengine/server** - 新增分布式房间管理功能 | Added distributed room management features
|
||||
|
||||
- 新增 `DistributedRoomManager` 支持多服务器房间管理 | Added `DistributedRoomManager` for multi-server room management
|
||||
- 新增 `MemoryAdapter` 用于测试和单机模式 | Added `MemoryAdapter` for testing and standalone mode
|
||||
- 新增 `RedisAdapter` 用于生产环境多服务器部署 | Added `RedisAdapter` for production multi-server deployments
|
||||
- 新增 `LoadBalancedRouter` 支持 5 种负载均衡策略 | Added `LoadBalancedRouter` with 5 load balancing strategies
|
||||
- round-robin: 轮询 | Round robin
|
||||
- least-rooms: 最少房间数 | Fewest rooms
|
||||
- least-players: 最少玩家数 | Fewest players
|
||||
- random: 随机选择 | Random selection
|
||||
- weighted: 权重(基于容量使用率)| Weighted by capacity usage
|
||||
- `createServer` 新增 `distributed` 配置选项 | Added `distributed` config option to `createServer`
|
||||
- 新增 `$redirect` 消息用于跨服务器玩家重定向 | Added `$redirect` message for cross-server player redirection
|
||||
- 新增故障转移机制,服务器离线时自动恢复房间 | Added failover mechanism for automatic room recovery on server offline
|
||||
- 新增 `room:migrated` 和 `server:draining` 事件类型 | Added `room:migrated` and `server:draining` event types
|
||||
Reference in New Issue
Block a user