Compare commits

..

6 Commits

Author SHA1 Message Date
github-actions[bot]
1316d7de49 chore: release packages (#373)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-12-28 13:49:34 +08:00
YHH
9c41181875 fix(server): expose id property on ServerConnection type (#372) 2025-12-28 13:47:27 +08:00
github-actions[bot]
9f3f9a547a chore: release packages (#371)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-12-28 13:32:44 +08:00
YHH
18df9d1cda fix(server): allow define() to be called before start() (#370) 2025-12-28 13:29:17 +08:00
github-actions[bot]
9a4b3388e0 chore: release packages (#369)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-12-28 12:51:20 +08:00
YHH
66d5dc27f7 fix(server): 修复发布缺少 dist | fix missing dist (#368)
* fix(server): 修复发布缺少 dist | fix missing dist in publish

* ci: 添加 server 和 create-esengine-server 构建 | add server packages to build

* fix: 添加 create-esengine-server 到 changeset
2025-12-28 12:46:50 +08:00
7 changed files with 53 additions and 17 deletions

View File

@@ -56,7 +56,9 @@ jobs:
pnpm --filter "@esengine/network-protocols" build
pnpm --filter "@esengine/rpc" build
pnpm --filter "@esengine/network" build
pnpm --filter "@esengine/server" build
pnpm --filter "@esengine/cli" build
pnpm --filter "create-esengine-server" build
- name: Create Release Pull Request or Publish
id: changesets

View File

@@ -1,5 +1,33 @@
# @esengine/server
## 1.1.3
### Patch Changes
- [#372](https://github.com/esengine/esengine/pull/372) [`9c41181`](https://github.com/esengine/esengine/commit/9c4118187539e39ead48ef2fa7af3ff45285fde5) Thanks [@esengine](https://github.com/esengine)! - fix: expose `id` property on ServerConnection type
TypeScript was not properly resolving the inherited `id` property from the base `Connection` interface in some module resolution scenarios. This fix explicitly declares the `id` property on `ServerConnection` to ensure it's always visible to consumers.
## 1.1.2
### Patch Changes
- [#370](https://github.com/esengine/esengine/pull/370) [`18df9d1`](https://github.com/esengine/esengine/commit/18df9d1cda4d4cf3095841d93125f9d41ce214f1) Thanks [@esengine](https://github.com/esengine)! - fix: allow define() to be called before start()
Previously, calling `server.define()` before `server.start()` would throw an error because `roomManager` was initialized inside `start()`. This fix moves the `roomManager` initialization to `createServer()`, allowing the expected usage pattern:
```typescript
const server = await createServer({ port: 3000 });
server.define('world', WorldRoom); // Now works correctly
await server.start();
```
## 1.1.1
### Patch Changes
- [#368](https://github.com/esengine/esengine/pull/368) [`66d5dc2`](https://github.com/esengine/esengine/commit/66d5dc27f740cc81b0645bde61dabf665743a5a0) Thanks [@esengine](https://github.com/esengine)! - fix: 修复发布缺少 dist 目录 | fix missing dist in published packages
## 1.1.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@esengine/server",
"version": "1.1.0",
"version": "1.1.3",
"description": "Game server framework for ESEngine with file-based routing",
"type": "module",
"main": "./dist/index.js",

View File

@@ -91,8 +91,10 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
let tickInterval: ReturnType<typeof setInterval> | null = null
let rpcServer: RpcServer<typeof protocol, Record<string, unknown>> | null = null
// 房间管理器
let roomManager: RoomManager | null = null
// 房间管理器(立即初始化,以便 define() 可在 start() 前调用)
const roomManager = new RoomManager((conn, type, data) => {
rpcServer?.send(conn, 'RoomMessage' as any, { type, data } as any)
})
// 构建 API 处理器映射
const apiMap: Record<string, LoadedApiHandler> = {}
@@ -108,7 +110,7 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
// 游戏服务器实例
const gameServer: GameServer & {
rooms: RoomManager | null
rooms: RoomManager
} = {
get connections() {
return (rpcServer?.connections ?? []) as ReadonlyArray<ServerConnection>
@@ -127,18 +129,10 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
* @en Define room type
*/
define(name: string, roomClass: new () => unknown): void {
if (!roomManager) {
throw new Error('Server not started. Call define() after createServer().')
}
roomManager.define(name, roomClass as RoomClass)
},
async start() {
// 初始化房间管理器
roomManager = new RoomManager((conn, type, data) => {
rpcServer?.send(conn, 'RoomMessage' as any, { type, data } as any)
})
// 构建 API handlers
const apiHandlersObj: Record<string, (input: unknown, conn: any) => Promise<unknown>> = {}
@@ -151,7 +145,7 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
}
if (roomId) {
const result = await roomManager!.joinById(roomId, conn.id, conn)
const result = await roomManager.joinById(roomId, conn.id, conn)
if (!result) {
throw new Error('Failed to join room')
}
@@ -159,7 +153,7 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
}
if (roomType) {
const result = await roomManager!.joinOrCreate(roomType, conn.id, conn, options)
const result = await roomManager.joinOrCreate(roomType, conn.id, conn, options)
if (!result) {
throw new Error('Failed to join or create room')
}
@@ -171,7 +165,7 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
// 内置 LeaveRoom API
apiHandlersObj['LeaveRoom'] = async (_input, conn) => {
await roomManager!.leave(conn.id)
await roomManager.leave(conn.id)
return { success: true }
}
@@ -192,7 +186,7 @@ export async function createServer(config: ServerConfig = {}): Promise<GameServe
// 内置 RoomMessage 处理
msgHandlersObj['RoomMessage'] = async (data: any, conn) => {
const { type, payload } = data as { type: string; payload: unknown }
roomManager!.handleMessage(conn.id, type, payload)
roomManager.handleMessage(conn.id, type, payload)
}
// 文件路由消息

View File

@@ -70,6 +70,12 @@ export interface ServerConfig {
* @en Server connection (extends RPC Connection)
*/
export interface ServerConnection<TData = Record<string, unknown>> extends Connection<TData> {
/**
* @zh 连接唯一标识(继承自 Connection
* @en Connection unique identifier (inherited from Connection)
*/
readonly id: string
/**
* @zh 用户自定义数据
* @en User-defined data

View File

@@ -1,5 +1,11 @@
# create-esengine-server
## 1.1.1
### Patch Changes
- [#368](https://github.com/esengine/esengine/pull/368) [`66d5dc2`](https://github.com/esengine/esengine/commit/66d5dc27f740cc81b0645bde61dabf665743a5a0) Thanks [@esengine](https://github.com/esengine)! - fix: 修复发布缺少 dist 目录 | fix missing dist in published packages
## 1.1.0
### Minor Changes

View File

@@ -1,6 +1,6 @@
{
"name": "create-esengine-server",
"version": "1.1.0",
"version": "1.1.1",
"description": "Create ESEngine game server projects",
"type": "module",
"bin": {