2025-12-28 12:23:55 +08:00
|
|
|
/**
|
|
|
|
|
* @zh ESEngine 游戏服务器框架
|
|
|
|
|
* @en ESEngine Game Server Framework
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* ```typescript
|
|
|
|
|
* import { createServer, Room, onMessage } from '@esengine/server'
|
|
|
|
|
*
|
|
|
|
|
* class GameRoom extends Room {
|
|
|
|
|
* maxPlayers = 4
|
|
|
|
|
* tickRate = 20
|
|
|
|
|
*
|
|
|
|
|
* onJoin(player) {
|
|
|
|
|
* this.broadcast('Joined', { id: player.id })
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* @onMessage('Move')
|
|
|
|
|
* handleMove(data, player) {
|
|
|
|
|
* // handle move
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* const server = await createServer({ port: 3000 })
|
|
|
|
|
* server.define('game', GameRoom)
|
|
|
|
|
* await server.start()
|
|
|
|
|
* ```
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Core
|
2026-01-01 18:39:00 +08:00
|
|
|
export { createServer } from './core/server.js';
|
2025-12-28 12:23:55 +08:00
|
|
|
|
|
|
|
|
// Helpers
|
2026-01-02 17:18:13 +08:00
|
|
|
export {
|
|
|
|
|
defineApi,
|
|
|
|
|
defineMsg,
|
|
|
|
|
defineHttp,
|
|
|
|
|
defineApiWithSchema,
|
|
|
|
|
defineMsgWithSchema,
|
|
|
|
|
type ApiDefinitionWithSchema,
|
|
|
|
|
type MsgDefinitionWithSchema
|
|
|
|
|
} from './helpers/define.js';
|
|
|
|
|
|
|
|
|
|
// Schema Validation System
|
|
|
|
|
export {
|
|
|
|
|
// Schema Builder (main API)
|
|
|
|
|
s,
|
|
|
|
|
|
|
|
|
|
// Primitive Validators
|
|
|
|
|
string,
|
|
|
|
|
number,
|
|
|
|
|
boolean,
|
|
|
|
|
literal,
|
|
|
|
|
any,
|
|
|
|
|
|
|
|
|
|
// Composite Validators
|
|
|
|
|
object,
|
|
|
|
|
array,
|
|
|
|
|
tuple,
|
|
|
|
|
union,
|
|
|
|
|
record,
|
|
|
|
|
nativeEnum,
|
|
|
|
|
|
|
|
|
|
// Validator Classes (for extension)
|
|
|
|
|
StringValidator,
|
|
|
|
|
NumberValidator,
|
|
|
|
|
BooleanValidator,
|
|
|
|
|
LiteralValidator,
|
|
|
|
|
AnyValidator,
|
|
|
|
|
ObjectValidator,
|
|
|
|
|
ArrayValidator,
|
|
|
|
|
TupleValidator,
|
|
|
|
|
UnionValidator,
|
|
|
|
|
RecordValidator,
|
|
|
|
|
EnumValidator,
|
|
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
parse,
|
|
|
|
|
safeParse,
|
|
|
|
|
createGuard,
|
|
|
|
|
|
|
|
|
|
// Types
|
|
|
|
|
type Validator,
|
|
|
|
|
type ValidationResult,
|
|
|
|
|
type ValidationSuccess,
|
|
|
|
|
type ValidationFailure,
|
|
|
|
|
type ValidationError,
|
|
|
|
|
type Infer,
|
|
|
|
|
type ObjectShape,
|
|
|
|
|
type InferShape
|
|
|
|
|
} from './schema/index.js';
|
2025-12-28 12:23:55 +08:00
|
|
|
|
|
|
|
|
// Room System
|
2026-01-01 18:39:00 +08:00
|
|
|
export { Room, type RoomOptions } from './room/Room.js';
|
|
|
|
|
export { Player, type IPlayer } from './room/Player.js';
|
|
|
|
|
export { onMessage } from './room/decorators.js';
|
2025-12-28 12:23:55 +08:00
|
|
|
|
2026-01-02 17:18:13 +08:00
|
|
|
// ECS Room (for ECS-integrated games)
|
|
|
|
|
export { ECSRoom, type ECSRoomConfig } from './ecs/ECSRoom.js';
|
|
|
|
|
|
2025-12-28 12:23:55 +08:00
|
|
|
// Types
|
|
|
|
|
export type {
|
|
|
|
|
ServerConfig,
|
|
|
|
|
ServerConnection,
|
|
|
|
|
GameServer,
|
|
|
|
|
ApiContext,
|
|
|
|
|
MsgContext,
|
|
|
|
|
ApiDefinition,
|
|
|
|
|
MsgDefinition,
|
2025-12-31 09:52:45 +08:00
|
|
|
HttpDefinition,
|
2026-01-01 18:39:00 +08:00
|
|
|
HttpMethod
|
|
|
|
|
} from './types/index.js';
|
2025-12-28 12:23:55 +08:00
|
|
|
|
2025-12-31 09:52:45 +08:00
|
|
|
// HTTP
|
2026-01-01 18:39:00 +08:00
|
|
|
export { createHttpRouter } from './http/router.js';
|
2025-12-31 09:52:45 +08:00
|
|
|
export type {
|
|
|
|
|
HttpRequest,
|
|
|
|
|
HttpResponse,
|
|
|
|
|
HttpHandler,
|
|
|
|
|
HttpRoutes,
|
2026-01-01 18:39:00 +08:00
|
|
|
CorsOptions
|
|
|
|
|
} from './http/types.js';
|
2025-12-31 09:52:45 +08:00
|
|
|
|
2025-12-28 12:23:55 +08:00
|
|
|
// Re-export useful types from @esengine/rpc
|
2026-01-01 18:39:00 +08:00
|
|
|
export { RpcError, ErrorCode } from '@esengine/rpc';
|
2026-01-02 17:18:13 +08:00
|
|
|
|
|
|
|
|
// Distributed Room Support
|
|
|
|
|
export {
|
|
|
|
|
DistributedRoomManager,
|
|
|
|
|
MemoryAdapter,
|
|
|
|
|
RedisAdapter,
|
|
|
|
|
createRedisAdapter,
|
|
|
|
|
LoadBalancedRouter,
|
|
|
|
|
createLoadBalancedRouter,
|
|
|
|
|
type IDistributedAdapter,
|
|
|
|
|
type MemoryAdapterConfig,
|
|
|
|
|
type RedisAdapterConfig,
|
|
|
|
|
type RedisClient,
|
|
|
|
|
type RedisClientFactory,
|
|
|
|
|
type ServerStatus,
|
|
|
|
|
type ServerRegistration,
|
|
|
|
|
type RoomRegistration,
|
|
|
|
|
type RoomQuery,
|
|
|
|
|
type RoomSnapshot,
|
|
|
|
|
type DistributedEvent,
|
|
|
|
|
type DistributedEventType,
|
|
|
|
|
type DistributedEventHandler,
|
|
|
|
|
type DistributedRoomManagerConfig,
|
|
|
|
|
type DistributedConfig,
|
|
|
|
|
type RoutingResult,
|
|
|
|
|
type RoutingRequest,
|
|
|
|
|
type LoadBalanceStrategy,
|
|
|
|
|
type LoadBalancedRouterConfig
|
|
|
|
|
} from './distributed/index.js';
|
|
|
|
|
|
|
|
|
|
// Room Manager (for extension)
|
|
|
|
|
export { RoomManager, type RoomClass } from './room/RoomManager.js';
|
|
|
|
|
|