@pieai/swimmer-game-server-kit 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/dist/colyseus.js +17 -7
- package/dist/colyseus.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# SwimmerGameServerKit
|
|
2
2
|
|
|
3
|
+
TCP listeners honor `config.host` (local default `127.0.0.1`) through the existing
|
|
4
|
+
WebSocket transport. The upstream Colyseus tools still own process-port offsets,
|
|
5
|
+
Cloud Unix sockets, matchmaking and shutdown. Keep the same config when creating
|
|
6
|
+
and starting an app. Binding is tested using real IPv4/IPv6 sockets, an HTTP health
|
|
7
|
+
request, WebSocket room joins and a Unix socket, not just configuration objects.
|
|
8
|
+
|
|
3
9
|
Shared Colyseus game-server kit for PieAI Swimmer-based games.
|
|
4
10
|
|
|
5
11
|
This repository is the central template for PieAI multiplayer game servers.
|
|
@@ -56,7 +62,7 @@ Install the exact reviewed npm version:
|
|
|
56
62
|
```json
|
|
57
63
|
{
|
|
58
64
|
"dependencies": {
|
|
59
|
-
"@pieai/swimmer-game-server-kit": "0.
|
|
65
|
+
"@pieai/swimmer-game-server-kit": "0.2.3"
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
```
|
|
@@ -115,6 +121,13 @@ const client = await connectSwimmerGameClient({
|
|
|
115
121
|
client.sendInput({ jump: true });
|
|
116
122
|
```
|
|
117
123
|
|
|
124
|
+
For an invitation or an exact-room return, pass `roomId` as a top-level option.
|
|
125
|
+
The Kit then uses the SDK's `joinById`, without falling back to `joinOrCreate`
|
|
126
|
+
when that room is full, expired, locked or unavailable. Omitting `roomId` preserves
|
|
127
|
+
existing creation behavior. The product owns invitation parsing, consent, protocol
|
|
128
|
+
compatibility and seat/reconnection rules; a public room ID grants no identity or
|
|
129
|
+
right to take an occupied seat. Actual loopback tests cover both admission paths.
|
|
130
|
+
|
|
118
131
|
## Auth Usage
|
|
119
132
|
|
|
120
133
|
```ts
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export interface SwimmerGameClient<TInput, TSnapshot, TPlayerId extends string =
|
|
|
9
9
|
}
|
|
10
10
|
export interface ConnectSwimmerGameClientOptions<TSnapshot extends object, TPlayerId extends string = string> {
|
|
11
11
|
endpoint: string;
|
|
12
|
+
/** Join this existing room through the SDK's joinById. Failure must never
|
|
13
|
+
* create a replacement room. Omit for the existing joinOrCreate behavior. */
|
|
14
|
+
roomId?: string;
|
|
12
15
|
joinOptions?: Record<string, unknown>;
|
|
13
16
|
messages?: Partial<SwimmerGameMessages>;
|
|
14
17
|
onError?: (message: string) => void;
|
package/dist/client.js
CHANGED
|
@@ -2,8 +2,17 @@ import { Client } from '@colyseus/sdk';
|
|
|
2
2
|
import { resolveSwimmerGameMessages } from './definition.js';
|
|
3
3
|
export async function connectSwimmerGameClient(options) {
|
|
4
4
|
const messages = resolveSwimmerGameMessages(options.messages);
|
|
5
|
+
if (options.roomId !== undefined &&
|
|
6
|
+
(typeof options.roomId !== 'string' ||
|
|
7
|
+
options.roomId.length === 0 ||
|
|
8
|
+
options.roomId.length > 128 ||
|
|
9
|
+
!/^[a-zA-Z0-9_-]+$/.test(options.roomId))) {
|
|
10
|
+
throw new Error('A bounded existing room ID is required.');
|
|
11
|
+
}
|
|
5
12
|
const client = new Client(options.endpoint);
|
|
6
|
-
const room =
|
|
13
|
+
const room = options.roomId === undefined
|
|
14
|
+
? await client.joinOrCreate(options.roomName, options.joinOptions ?? {})
|
|
15
|
+
: await client.joinById(options.roomId, options.joinOptions ?? {});
|
|
7
16
|
let playerId = null;
|
|
8
17
|
room.onMessage(messages.welcome, (payload) => {
|
|
9
18
|
playerId = payload.playerId;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAA4B,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAA4B,MAAM,iBAAiB,CAAC;AA0BvF,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAK5C,OAA8D;IAE9D,MAAM,QAAQ,GAAG,0BAA0B,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,IACE,OAAO,CAAC,MAAM,KAAK,SAAS;QAC5B,CAAC,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;YACjC,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG;YAC3B,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAC3C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,IAAI,GACR,OAAO,CAAC,MAAM,KAAK,SAAS;QAC1B,CAAC,CAAC,MAAM,MAAM,CAAC,YAAY,CAAY,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QACnF,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAY,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IAClF,IAAI,QAAQ,GAAqB,IAAI,CAAC;IAEtC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAkD,EAAE,EAAE;QACtF,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC5B,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,OAA6B,EAAE,EAAE;QAC/D,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,OAA6B,EAAE,EAAE;QAC/D,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE7B,OAAO;QACL,IAAI,QAAQ;YACV,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,IAAI;QACJ,KAAK,CAAC,KAAK;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QACD,SAAS,CAAC,KAAa;YACrB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,WAAW;YACT,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/colyseus.js
CHANGED
|
@@ -2,6 +2,21 @@ import defineServer, { listen } from '@colyseus/tools';
|
|
|
2
2
|
import { defineRoom } from '@colyseus/core';
|
|
3
3
|
import { WebSocketTransport } from '@colyseus/ws-transport';
|
|
4
4
|
import { configureGameServerHttpRoutes } from './http.js';
|
|
5
|
+
/** @colyseus/tools owns Cloud sockets, process ports and server lifecycle, but
|
|
6
|
+
* its TCP listen helper omits hostname. Supply it at the existing transport
|
|
7
|
+
* extension point, before any socket binds; never bind publicly then rebind. */
|
|
8
|
+
class HostBoundWebSocketTransport extends WebSocketTransport {
|
|
9
|
+
bindHost;
|
|
10
|
+
constructor(options, bindHost) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.bindHost = bindHost;
|
|
13
|
+
}
|
|
14
|
+
listen(port, hostname, backlog, listeningListener) {
|
|
15
|
+
// The Cloud helper passes a Unix socket path through this numeric API.
|
|
16
|
+
// A path is not a TCP port; preserve the native socket overload unchanged.
|
|
17
|
+
return super.listen(port, typeof port === 'number' ? this.bindHost : hostname, backlog, listeningListener);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
5
20
|
export function createSwimmerGameServerApp(options) {
|
|
6
21
|
const roomDefinitions = Object.fromEntries(options.rooms.map((registration) => {
|
|
7
22
|
const handler = defineRoom(registration.room);
|
|
@@ -14,13 +29,8 @@ export function createSwimmerGameServerApp(options) {
|
|
|
14
29
|
const transport = options.transport;
|
|
15
30
|
return defineServer({
|
|
16
31
|
displayLogs: options.displayLogs ?? true,
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
...(transport === undefined
|
|
20
|
-
? {}
|
|
21
|
-
: {
|
|
22
|
-
initializeTransport: (transportOptions) => new WebSocketTransport({ ...transportOptions, ...transport }),
|
|
23
|
-
}),
|
|
32
|
+
// Keep the upstream HTTP handle, ping settings, matchmaking and shutdown.
|
|
33
|
+
initializeTransport: (transportOptions) => new HostBoundWebSocketTransport({ ...transportOptions, ...transport }, options.config.host),
|
|
24
34
|
rooms: roomDefinitions,
|
|
25
35
|
initializeExpress(app) {
|
|
26
36
|
configureGameServerHttpRoutes(app, options.config, options.extraHealth === undefined
|
package/dist/colyseus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colyseus.js","sourceRoot":"","sources":["../src/colyseus.ts"],"names":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mer-game-server-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Shared Colyseus game server kit for PieAI Swimmer-based games.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"colyseus",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"zod": "^4.1.13"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@pieai/doc-gov": "0.
|
|
86
|
-
"@pieai/pro-gov": "0.
|
|
85
|
+
"@pieai/doc-gov": "0.9.11",
|
|
86
|
+
"@pieai/pro-gov": "0.9.11",
|
|
87
87
|
"@types/cors": "^2.8.19",
|
|
88
88
|
"@types/express": "^5.0.6",
|
|
89
89
|
"@types/node": "24.13.2",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"lint": "oxlint src tests templates/colyseus-game-server/src -c ./.oxlintrc.json",
|
|
103
103
|
"format": "oxfmt package.json tsconfig.json tsconfig.build.json templates/colyseus-game-server/package.json templates/colyseus-game-server/tsconfig.json src tests templates/colyseus-game-server/src --write --ignore-path ./.oxfmtignore",
|
|
104
104
|
"format:check": "oxfmt package.json tsconfig.json tsconfig.build.json templates/colyseus-game-server/package.json templates/colyseus-game-server/tsconfig.json src tests templates/colyseus-game-server/src --check --ignore-path ./.oxfmtignore",
|
|
105
|
-
"test": "vitest run --pool threads",
|
|
105
|
+
"test": "vitest run tests --pool threads",
|
|
106
106
|
"verify": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test && pnpm build",
|
|
107
107
|
"doc-gov": "doc-gov",
|
|
108
108
|
"pro-gov": "pro-gov",
|