@colyseus/core 0.17.2 → 0.17.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/package.json +2 -2
- package/build/matchmaker/driver/api.js +0 -48
- package/build/matchmaker/driver/api.js.map +0 -7
- package/build/matchmaker/driver/api.mjs +0 -24
- package/build/matchmaker/driver/api.mjs.map +0 -7
- package/build/matchmaker/driver/local/LocalDriver.js +0 -94
- package/build/matchmaker/driver/local/LocalDriver.js.map +0 -7
- package/build/matchmaker/driver/local/LocalDriver.mjs +0 -71
- package/build/matchmaker/driver/local/LocalDriver.mjs.map +0 -7
- package/build/matchmaker/driver/local/Query.js +0 -111
- package/build/matchmaker/driver/local/Query.js.map +0 -7
- package/build/matchmaker/driver/local/Query.mjs +0 -88
- package/build/matchmaker/driver/local/Query.mjs.map +0 -7
- package/build/matchmaker/routes.js +0 -79
- package/build/matchmaker/routes.js.map +0 -7
- package/build/matchmaker/routes.mjs +0 -45
- package/build/matchmaker/routes.mjs.map +0 -7
- package/build/rooms/createRoom.js +0 -51
- package/build/rooms/createRoom.js.map +0 -7
- package/build/rooms/createRoom.mjs +0 -28
- package/build/rooms/createRoom.mjs.map +0 -7
- package/build/src/matchmaker/driver/api.d.ts +0 -145
- package/build/src/matchmaker/driver/local/LocalDriver.d.ts +0 -17
- package/build/src/matchmaker/driver/local/Query.d.ts +0 -12
- package/build/src/matchmaker/routes.d.ts +0 -92
- package/build/src/rooms/createRoom.d.ts +0 -65
- /package/build/{src/Debug.d.ts → Debug.d.ts} +0 -0
- /package/build/{src/IPC.d.ts → IPC.d.ts} +0 -0
- /package/build/{src/Logger.d.ts → Logger.d.ts} +0 -0
- /package/build/{src/MatchMaker.d.ts → MatchMaker.d.ts} +0 -0
- /package/build/{src/Protocol.d.ts → Protocol.d.ts} +0 -0
- /package/build/{src/Room.d.ts → Room.d.ts} +0 -0
- /package/build/{src/Server.d.ts → Server.d.ts} +0 -0
- /package/build/{src/Stats.d.ts → Stats.d.ts} +0 -0
- /package/build/{src/Transport.d.ts → Transport.d.ts} +0 -0
- /package/build/{src/errors → errors}/RoomExceptions.d.ts +0 -0
- /package/build/{src/errors → errors}/SeatReservationError.d.ts +0 -0
- /package/build/{src/errors → errors}/ServerError.d.ts +0 -0
- /package/build/{src/index.d.ts → index.d.ts} +0 -0
- /package/build/{src/matchmaker → matchmaker}/Lobby.d.ts +0 -0
- /package/build/{src/matchmaker → matchmaker}/LocalDriver/LocalDriver.d.ts +0 -0
- /package/build/{src/matchmaker → matchmaker}/LocalDriver/Query.d.ts +0 -0
- /package/build/{src/matchmaker → matchmaker}/RegisteredHandler.d.ts +0 -0
- /package/build/{src/matchmaker → matchmaker}/controller.d.ts +0 -0
- /package/build/{src/matchmaker → matchmaker}/driver.d.ts +0 -0
- /package/build/{src/presence → presence}/LocalPresence.d.ts +0 -0
- /package/build/{src/presence → presence}/Presence.d.ts +0 -0
- /package/build/{src/rooms → rooms}/LobbyRoom.d.ts +0 -0
- /package/build/{src/rooms → rooms}/RankedQueueRoom.d.ts +0 -0
- /package/build/{src/rooms → rooms}/RelayRoom.d.ts +0 -0
- /package/build/{src/router → router}/default_routes.d.ts +0 -0
- /package/build/{src/router → router}/index.d.ts +0 -0
- /package/build/{src/serializer → serializer}/NoneSerializer.d.ts +0 -0
- /package/build/{src/serializer → serializer}/SchemaSerializer.d.ts +0 -0
- /package/build/{src/serializer → serializer}/SchemaSerializerDebug.d.ts +0 -0
- /package/build/{src/serializer → serializer}/Serializer.d.ts +0 -0
- /package/build/{src/utils → utils}/DevMode.d.ts +0 -0
- /package/build/{src/utils → utils}/StandardSchema.d.ts +0 -0
- /package/build/{src/utils → utils}/Utils.d.ts +0 -0
- /package/build/{src/utils → utils}/nanoevents.d.ts +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// packages/core/src/matchmaker/routes.ts
|
|
2
|
-
import { createEndpoint, createRouter } from "@colyseus/better-call";
|
|
3
|
-
import * as matchMaker from "../MatchMaker.mjs";
|
|
4
|
-
import { getBearerToken } from "../utils/Utils.mjs";
|
|
5
|
-
var postMatchmakeMethod = createEndpoint("/matchmake/:method/:roomName", { method: "POST" }, async (ctx) => {
|
|
6
|
-
if (matchMaker.state === matchMaker.MatchMakerState.SHUTTING_DOWN) {
|
|
7
|
-
throw ctx.error(503);
|
|
8
|
-
}
|
|
9
|
-
const requestHeaders = ctx.request.headers;
|
|
10
|
-
const headers = Object.assign(
|
|
11
|
-
{},
|
|
12
|
-
matchMaker.controller.DEFAULT_CORS_HEADERS,
|
|
13
|
-
matchMaker.controller.getCorsHeaders(requestHeaders)
|
|
14
|
-
);
|
|
15
|
-
const method = ctx.params.method;
|
|
16
|
-
const roomName = ctx.params.roomName;
|
|
17
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
18
|
-
ctx.setHeader(key, value);
|
|
19
|
-
});
|
|
20
|
-
ctx.setHeader("Content-Type", "application/json");
|
|
21
|
-
try {
|
|
22
|
-
const clientOptions = ctx.body;
|
|
23
|
-
const response = await matchMaker.controller.invokeMethod(
|
|
24
|
-
method,
|
|
25
|
-
roomName,
|
|
26
|
-
clientOptions,
|
|
27
|
-
{
|
|
28
|
-
token: getBearerToken(ctx.request.headers.get("authorization")),
|
|
29
|
-
headers: ctx.request.headers,
|
|
30
|
-
ip: requestHeaders.get("x-forwarded-for") ?? requestHeaders.get("x-client-ip") ?? requestHeaders.get("x-real-ip"),
|
|
31
|
-
req: ctx.request
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
return response;
|
|
35
|
-
} catch (e) {
|
|
36
|
-
throw ctx.error(e.code, { code: e.code, error: e.message });
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
function getDefaultRouter() {
|
|
40
|
-
return createRouter({ postMatchmakeMethod });
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
getDefaultRouter,
|
|
44
|
-
postMatchmakeMethod
|
|
45
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/matchmaker/routes.ts"],
|
|
4
|
-
"sourcesContent": ["import { createEndpoint, createRouter } from \"@colyseus/better-call\";\nimport * as matchMaker from \"../MatchMaker.ts\";\nimport { getBearerToken } from \"../utils/Utils.ts\";\n\nexport const postMatchmakeMethod = createEndpoint(\"/matchmake/:method/:roomName\", { method: \"POST\" }, async (ctx) => {\n // do not accept matchmaking requests if already shutting down\n if (matchMaker.state === matchMaker.MatchMakerState.SHUTTING_DOWN) {\n throw ctx.error(503);\n }\n\n const requestHeaders = ctx.request.headers;\n const headers = Object.assign(\n {},\n matchMaker.controller.DEFAULT_CORS_HEADERS,\n matchMaker.controller.getCorsHeaders(requestHeaders)\n );\n\n const method = ctx.params.method;\n const roomName = ctx.params.roomName;\n\n Object.entries(headers).forEach(([key, value]) => {\n ctx.setHeader(key, value);\n })\n ctx.setHeader('Content-Type', 'application/json');\n\n try {\n const clientOptions = ctx.body;\n const response = await matchMaker.controller.invokeMethod(\n method,\n roomName,\n clientOptions,\n {\n token: getBearerToken(ctx.request.headers.get('authorization')),\n headers: ctx.request.headers,\n ip: requestHeaders.get('x-forwarded-for') ?? requestHeaders.get('x-client-ip') ?? requestHeaders.get('x-real-ip'),\n req: ctx.request as any,\n },\n );\n\n //\n // TODO: respond with protocol, if available\n //\n // // specify protocol, if available.\n // if (this.transport.protocol !== undefined) {\n // response.protocol = this.transport.protocol;\n // }\n\n return response;\n\n } catch (e: any) {\n throw ctx.error(e.code, { code: e.code, error: e.message, });\n }\n\n});\n\nexport function getDefaultRouter() {\n return createRouter({ postMatchmakeMethod });\n}"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB,oBAAoB;AAC7C,YAAY,gBAAgB;AAC5B,SAAS,sBAAsB;AAExB,IAAM,sBAAsB,eAAe,gCAAgC,EAAE,QAAQ,OAAO,GAAG,OAAO,QAAQ;AAEnH,MAAe,qBAAqB,2BAAgB,eAAe;AACjE,UAAM,IAAI,MAAM,GAAG;AAAA,EACrB;AAEA,QAAM,iBAAiB,IAAI,QAAQ;AACnC,QAAM,UAAU,OAAO;AAAA,IACrB,CAAC;AAAA,IACU,sBAAW;AAAA,IACX,sBAAW,eAAe,cAAc;AAAA,EACrD;AAEA,QAAM,SAAS,IAAI,OAAO;AAC1B,QAAM,WAAW,IAAI,OAAO;AAE5B,SAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAChD,QAAI,UAAU,KAAK,KAAK;AAAA,EAC1B,CAAC;AACD,MAAI,UAAU,gBAAgB,kBAAkB;AAEhD,MAAI;AACF,UAAM,gBAAgB,IAAI;AAC1B,UAAM,WAAW,MAAiB,sBAAW;AAAA,MAC3C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,QACE,OAAO,eAAe,IAAI,QAAQ,QAAQ,IAAI,eAAe,CAAC;AAAA,QAC9D,SAAS,IAAI,QAAQ;AAAA,QACrB,IAAI,eAAe,IAAI,iBAAiB,KAAK,eAAe,IAAI,aAAa,KAAK,eAAe,IAAI,WAAW;AAAA,QAChH,KAAK,IAAI;AAAA,MACX;AAAA,IACF;AAUA,WAAO;AAAA,EAET,SAAS,GAAQ;AACf,UAAM,IAAI,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,EAAE,QAAS,CAAC;AAAA,EAC7D;AAEF,CAAC;AAEM,SAAS,mBAAmB;AACjC,SAAO,aAAa,EAAE,oBAAoB,CAAC;AAC7C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var createRoom_exports = {};
|
|
20
|
-
__export(createRoom_exports, {
|
|
21
|
-
createRoom: () => createRoom
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(createRoom_exports);
|
|
24
|
-
var import_core = require("@colyseus/core");
|
|
25
|
-
function createRoom(options) {
|
|
26
|
-
class _ extends import_core.Room {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
29
|
-
if (options.state && typeof options.state === "function") {
|
|
30
|
-
this.state = options.state();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
onCreate(opts) {
|
|
34
|
-
return options.onCreate?.call(this, opts);
|
|
35
|
-
}
|
|
36
|
-
onJoin(client, opts) {
|
|
37
|
-
return options.onJoin?.call(this, client, opts);
|
|
38
|
-
}
|
|
39
|
-
onLeave(client, code) {
|
|
40
|
-
return options.onLeave?.call(this, client, code);
|
|
41
|
-
}
|
|
42
|
-
onDispose() {
|
|
43
|
-
return options.onDispose?.call(this);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return _;
|
|
47
|
-
}
|
|
48
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
-
0 && (module.exports = {
|
|
50
|
-
createRoom
|
|
51
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/rooms/createRoom.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Exploration: defineRoom() factory function\n *\n * Goal: Allow users to define rooms without explicit generic parameters,\n * while still getting full type inference for broadcast() and client.send()\n */\n\nimport { Room, type Client, type AuthContext } from \"@colyseus/core\";\n\n/**\n * Helper type for cleaner Client typing with messages.\n * Reduces boilerplate from `Client<{ messages: M }>` to `MessageClient<M>`.\n *\n * @example\n * ```typescript\n * type MyClient = MessageClient<{\n * chat: { text: string };\n * move: { x: number; y: number };\n * }>;\n * ```\n */\nexport type MessageClient<Messages extends Record<string, any>> = Client<{ messages: Messages }>;\n\n// =============================================================================\n// APPROACH 2: Object-based config (Vue-style)\n// =============================================================================\n\n/**\n * Options for createRoom factory function.\n */\ninterface DefineRoomOptions<\n TClient extends Client = Client,\n State extends object = any,\n JoinOptions = any\n> {\n state?: State | (() => State);\n onCreate?(this: Room<State, any, TClient>, options: any): void | Promise<void>;\n onJoin?(this: Room<State, any, TClient>, client: TClient, options: JoinOptions): void | Promise<void>;\n onLeave?(this: Room<State, any, TClient>, client: TClient, code?: number): void | Promise<void>;\n onDispose?(this: Room<State, any, TClient>): void | Promise<void>;\n}\n\n/**\n * Create a Room class from an options object.\n * Provides Vue-style object configuration with full type inference.\n *\n * @example\n * ```typescript\n * type MyClient = Client<{\n * userData: { rank: number };\n * auth: { odToken: string };\n * messages: {\n * chat: { text: string };\n * move: { x: number; y: number };\n * };\n * }>;\n *\n * const MyRoom = createRoom<MyClient, MyState>({\n * state: () => new MyState(),\n *\n * onCreate() {\n * console.log(\"Room created\");\n * },\n *\n * onJoin(client, options) {\n * client.send(\"chat\", { text: \"Welcome!\" }); // \u2705 typed!\n * this.broadcast(\"move\", { x: 0, y: 0 }); // \u2705 typed!\n * client.userData.rank; // \u2705 typed!\n * client.auth.odToken; // \u2705 typed!\n * }\n * });\n * ```\n */\nexport function createRoom<\n TClient extends Client = Client,\n State extends object = any,\n JoinOptions = any\n>(options: DefineRoomOptions<TClient, State, JoinOptions>) {\n type TRoom = Room<State, any, TClient>;\n\n class _ extends Room<State, any, TClient> {\n constructor() {\n super();\n if (options.state && typeof options.state === 'function') {\n this.state = options.state();\n }\n }\n\n onCreate(opts: any) {\n return options.onCreate?.call(this as TRoom, opts);\n }\n\n onJoin(client: TClient, opts: JoinOptions) {\n return options.onJoin?.call(this as TRoom, client, opts);\n }\n\n onLeave(client: TClient, code?: number) {\n return options.onLeave?.call(this as TRoom, client, code);\n }\n\n onDispose() {\n return options.onDispose?.call(this as TRoom);\n }\n }\n\n return _ as typeof Room<State, any, TClient>;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,kBAAoD;AAkE7C,SAAS,WAId,SAAyD;AAAA,EAGzD,MAAM,UAAU,iBAA0B;AAAA,IACxC,cAAc;AACZ,YAAM;AACN,UAAI,QAAQ,SAAS,OAAO,QAAQ,UAAU,YAAY;AACxD,aAAK,QAAQ,QAAQ,MAAM;AAAA,MAC7B;AAAA,IACF;AAAA,IAEA,SAAS,MAAW;AAClB,aAAO,QAAQ,UAAU,KAAK,MAAe,IAAI;AAAA,IACnD;AAAA,IAEA,OAAO,QAAiB,MAAmB;AACzC,aAAO,QAAQ,QAAQ,KAAK,MAAe,QAAQ,IAAI;AAAA,IACzD;AAAA,IAEA,QAAQ,QAAiB,MAAe;AACtC,aAAO,QAAQ,SAAS,KAAK,MAAe,QAAQ,IAAI;AAAA,IAC1D;AAAA,IAEA,YAAY;AACV,aAAO,QAAQ,WAAW,KAAK,IAAa;AAAA,IAC9C;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// packages/core/src/rooms/createRoom.ts
|
|
2
|
-
import { Room } from "@colyseus/core";
|
|
3
|
-
function createRoom(options) {
|
|
4
|
-
class _ extends Room {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
if (options.state && typeof options.state === "function") {
|
|
8
|
-
this.state = options.state();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
onCreate(opts) {
|
|
12
|
-
return options.onCreate?.call(this, opts);
|
|
13
|
-
}
|
|
14
|
-
onJoin(client, opts) {
|
|
15
|
-
return options.onJoin?.call(this, client, opts);
|
|
16
|
-
}
|
|
17
|
-
onLeave(client, code) {
|
|
18
|
-
return options.onLeave?.call(this, client, code);
|
|
19
|
-
}
|
|
20
|
-
onDispose() {
|
|
21
|
-
return options.onDispose?.call(this);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return _;
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
createRoom
|
|
28
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/rooms/createRoom.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Exploration: defineRoom() factory function\n *\n * Goal: Allow users to define rooms without explicit generic parameters,\n * while still getting full type inference for broadcast() and client.send()\n */\n\nimport { Room, type Client, type AuthContext } from \"@colyseus/core\";\n\n/**\n * Helper type for cleaner Client typing with messages.\n * Reduces boilerplate from `Client<{ messages: M }>` to `MessageClient<M>`.\n *\n * @example\n * ```typescript\n * type MyClient = MessageClient<{\n * chat: { text: string };\n * move: { x: number; y: number };\n * }>;\n * ```\n */\nexport type MessageClient<Messages extends Record<string, any>> = Client<{ messages: Messages }>;\n\n// =============================================================================\n// APPROACH 2: Object-based config (Vue-style)\n// =============================================================================\n\n/**\n * Options for createRoom factory function.\n */\ninterface DefineRoomOptions<\n TClient extends Client = Client,\n State extends object = any,\n JoinOptions = any\n> {\n state?: State | (() => State);\n onCreate?(this: Room<State, any, TClient>, options: any): void | Promise<void>;\n onJoin?(this: Room<State, any, TClient>, client: TClient, options: JoinOptions): void | Promise<void>;\n onLeave?(this: Room<State, any, TClient>, client: TClient, code?: number): void | Promise<void>;\n onDispose?(this: Room<State, any, TClient>): void | Promise<void>;\n}\n\n/**\n * Create a Room class from an options object.\n * Provides Vue-style object configuration with full type inference.\n *\n * @example\n * ```typescript\n * type MyClient = Client<{\n * userData: { rank: number };\n * auth: { odToken: string };\n * messages: {\n * chat: { text: string };\n * move: { x: number; y: number };\n * };\n * }>;\n *\n * const MyRoom = createRoom<MyClient, MyState>({\n * state: () => new MyState(),\n *\n * onCreate() {\n * console.log(\"Room created\");\n * },\n *\n * onJoin(client, options) {\n * client.send(\"chat\", { text: \"Welcome!\" }); // \u2705 typed!\n * this.broadcast(\"move\", { x: 0, y: 0 }); // \u2705 typed!\n * client.userData.rank; // \u2705 typed!\n * client.auth.odToken; // \u2705 typed!\n * }\n * });\n * ```\n */\nexport function createRoom<\n TClient extends Client = Client,\n State extends object = any,\n JoinOptions = any\n>(options: DefineRoomOptions<TClient, State, JoinOptions>) {\n type TRoom = Room<State, any, TClient>;\n\n class _ extends Room<State, any, TClient> {\n constructor() {\n super();\n if (options.state && typeof options.state === 'function') {\n this.state = options.state();\n }\n }\n\n onCreate(opts: any) {\n return options.onCreate?.call(this as TRoom, opts);\n }\n\n onJoin(client: TClient, opts: JoinOptions) {\n return options.onJoin?.call(this as TRoom, client, opts);\n }\n\n onLeave(client: TClient, code?: number) {\n return options.onLeave?.call(this as TRoom, client, code);\n }\n\n onDispose() {\n return options.onDispose?.call(this as TRoom);\n }\n }\n\n return _ as typeof Room<State, any, TClient>;\n}\n"],
|
|
5
|
-
"mappings": ";AAOA,SAAS,YAA2C;AAkE7C,SAAS,WAId,SAAyD;AAAA,EAGzD,MAAM,UAAU,KAA0B;AAAA,IACxC,cAAc;AACZ,YAAM;AACN,UAAI,QAAQ,SAAS,OAAO,QAAQ,UAAU,YAAY;AACxD,aAAK,QAAQ,QAAQ,MAAM;AAAA,MAC7B;AAAA,IACF;AAAA,IAEA,SAAS,MAAW;AAClB,aAAO,QAAQ,UAAU,KAAK,MAAe,IAAI;AAAA,IACnD;AAAA,IAEA,OAAO,QAAiB,MAAmB;AACzC,aAAO,QAAQ,QAAQ,KAAK,MAAe,QAAQ,IAAI;AAAA,IACzD;AAAA,IAEA,QAAQ,QAAiB,MAAe;AACtC,aAAO,QAAQ,SAAS,KAAK,MAAe,QAAQ,IAAI;AAAA,IAC1D;AAAA,IAEA,YAAY;AACV,aAAO,QAAQ,WAAW,KAAK,IAAa;AAAA,IAC9C;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type { Room } from "@colyseus/core";
|
|
2
|
-
/**
|
|
3
|
-
* Sort options for room queries.
|
|
4
|
-
*/
|
|
5
|
-
export interface SortOptions {
|
|
6
|
-
[fieldName: string]: 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Built-in room cache fields that can be used for sorting.
|
|
10
|
-
*/
|
|
11
|
-
export type IRoomCacheSortByKeys = 'clients' | 'maxClients' | 'createdAt';
|
|
12
|
-
/**
|
|
13
|
-
* Built-in room cache fields that can be used for filtering.
|
|
14
|
-
*/
|
|
15
|
-
export type IRoomCacheFilterByKeys = 'clients' | 'maxClients' | 'processId';
|
|
16
|
-
/**
|
|
17
|
-
* Extract metadata type from Room type
|
|
18
|
-
*/
|
|
19
|
-
export type ExtractMetadata<RoomType extends Room> = RoomType extends Room<infer M> ? M : any;
|
|
20
|
-
/**
|
|
21
|
-
* Generates a unique lock ID based on filter options.
|
|
22
|
-
*/
|
|
23
|
-
export declare function getLockId(filterOptions: any): string;
|
|
24
|
-
/**
|
|
25
|
-
* Initialize a room cache which contains CRUD operations for room listings.
|
|
26
|
-
*
|
|
27
|
-
* @internal
|
|
28
|
-
* @param initialValues - Predefined room properties.
|
|
29
|
-
* @returns RoomData - New room cache.
|
|
30
|
-
*/
|
|
31
|
-
export declare function initializeRoomCache(initialValues?: Partial<IRoomCache>): IRoomCache;
|
|
32
|
-
export interface IRoomCache<Metadata = any> {
|
|
33
|
-
/**
|
|
34
|
-
* Room name.
|
|
35
|
-
*/
|
|
36
|
-
name: string;
|
|
37
|
-
/**
|
|
38
|
-
* Unique identifier for the room.
|
|
39
|
-
*/
|
|
40
|
-
roomId: string;
|
|
41
|
-
/**
|
|
42
|
-
* Process id where the room is running.
|
|
43
|
-
*/
|
|
44
|
-
processId: string;
|
|
45
|
-
/**
|
|
46
|
-
* Number of clients connected to this room.
|
|
47
|
-
*/
|
|
48
|
-
clients: number;
|
|
49
|
-
/**
|
|
50
|
-
* Maximum number of clients allowed to join the room.
|
|
51
|
-
*/
|
|
52
|
-
maxClients: number;
|
|
53
|
-
/**
|
|
54
|
-
* Indicates if the room is locked (i.e. join requests are rejected).
|
|
55
|
-
*/
|
|
56
|
-
locked?: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Indicates if the room is private
|
|
59
|
-
* Private rooms can't be joined via `join()` or `joinOrCreate()`.
|
|
60
|
-
*/
|
|
61
|
-
private?: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Public address of the server.
|
|
64
|
-
*/
|
|
65
|
-
publicAddress?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Do not show this room in lobby listing.
|
|
68
|
-
*/
|
|
69
|
-
unlisted?: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Metadata associated with the room.
|
|
72
|
-
*/
|
|
73
|
-
metadata?: Metadata;
|
|
74
|
-
/**
|
|
75
|
-
* When the room was created.
|
|
76
|
-
*/
|
|
77
|
-
createdAt?: Date;
|
|
78
|
-
}
|
|
79
|
-
export interface MatchMakerDriver {
|
|
80
|
-
/**
|
|
81
|
-
* Check if a room exists in room cache.
|
|
82
|
-
*
|
|
83
|
-
* @param roomId - The room id.
|
|
84
|
-
*
|
|
85
|
-
* @returns Promise<boolean> | boolean - A promise or a boolean value indicating if the room exists.
|
|
86
|
-
*/
|
|
87
|
-
has(roomId: string): Promise<boolean> | boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Query rooms in room cache for given conditions.
|
|
90
|
-
*
|
|
91
|
-
* @param conditions - Filtering conditions.
|
|
92
|
-
*
|
|
93
|
-
* @returns Promise<IRoomCache[]> | IRoomCache[] - A promise or an object contaning room metadata list.
|
|
94
|
-
*/
|
|
95
|
-
query<T extends Room = any>(conditions: Partial<IRoomCache & ExtractMetadata<T>>, sortOptions?: SortOptions): Promise<Array<IRoomCache<ExtractMetadata<T>>>> | Array<IRoomCache<ExtractMetadata<T>>>;
|
|
96
|
-
/**
|
|
97
|
-
* Clean up rooms in room cache by process id.
|
|
98
|
-
* @param processId - The process id.
|
|
99
|
-
*/
|
|
100
|
-
cleanup?(processId: string): Promise<void>;
|
|
101
|
-
/**
|
|
102
|
-
* Query for a room in room cache for given conditions.
|
|
103
|
-
*
|
|
104
|
-
* @param conditions - Filtering conditions.
|
|
105
|
-
*
|
|
106
|
-
* @returns `IRoomCache` - An object contaning filtered room metadata.
|
|
107
|
-
*/
|
|
108
|
-
findOne<T extends Room = any>(conditions: Partial<IRoomCache & ExtractMetadata<T>>, sortOptions?: SortOptions): Promise<IRoomCache<ExtractMetadata<T>>>;
|
|
109
|
-
/**
|
|
110
|
-
* Remove a room from room cache.
|
|
111
|
-
*
|
|
112
|
-
* @param roomId - The room id.
|
|
113
|
-
*/
|
|
114
|
-
remove(roomId: string): Promise<boolean> | boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Update a room in room cache.
|
|
117
|
-
*
|
|
118
|
-
* @param IRoomCache - The room to update.
|
|
119
|
-
* @param operations - The operations to update the room.
|
|
120
|
-
*/
|
|
121
|
-
update(room: IRoomCache, operations: Partial<{
|
|
122
|
-
$set: Partial<IRoomCache>;
|
|
123
|
-
$inc: Partial<IRoomCache>;
|
|
124
|
-
}>): Promise<boolean> | boolean;
|
|
125
|
-
/**
|
|
126
|
-
* Persist a room in room cache.
|
|
127
|
-
*
|
|
128
|
-
* @param room - The room to persist.
|
|
129
|
-
* @param create - If true, create a new record. If false (default), update existing record.
|
|
130
|
-
*/
|
|
131
|
-
persist(room: IRoomCache, create?: boolean): Promise<boolean> | boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Empty the room cache. Used for testing purposes only.
|
|
134
|
-
* @internal Do not call this method yourself.
|
|
135
|
-
*/
|
|
136
|
-
clear(): void;
|
|
137
|
-
/**
|
|
138
|
-
* Boot the room cache medium (if available).
|
|
139
|
-
*/
|
|
140
|
-
boot?(): Promise<void>;
|
|
141
|
-
/**
|
|
142
|
-
* Dispose the connection of the room cache medium.
|
|
143
|
-
*/
|
|
144
|
-
shutdown(): void;
|
|
145
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { IRoomCache, SortOptions, MatchMakerDriver } from '../api.ts';
|
|
2
|
-
export type { IRoomCache, SortOptions, MatchMakerDriver };
|
|
3
|
-
export declare class LocalDriver implements MatchMakerDriver {
|
|
4
|
-
rooms: IRoomCache[];
|
|
5
|
-
has(roomId: string): boolean;
|
|
6
|
-
query(conditions: Partial<IRoomCache>, sortOptions?: SortOptions): IRoomCache<any>[];
|
|
7
|
-
cleanup(processId: string): Promise<void>;
|
|
8
|
-
findOne(conditions: Partial<IRoomCache>, sortOptions?: SortOptions): Promise<IRoomCache>;
|
|
9
|
-
update(room: IRoomCache, operations: Partial<{
|
|
10
|
-
$set: Partial<IRoomCache>;
|
|
11
|
-
$inc: Partial<IRoomCache>;
|
|
12
|
-
}>): boolean;
|
|
13
|
-
persist(room: IRoomCache, create?: boolean): boolean;
|
|
14
|
-
remove(roomId: string): boolean;
|
|
15
|
-
clear(): void;
|
|
16
|
-
shutdown(): void;
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { IRoomCache, SortOptions } from '../api.ts';
|
|
2
|
-
export declare class Query<T extends IRoomCache> {
|
|
3
|
-
private $rooms;
|
|
4
|
-
private conditions;
|
|
5
|
-
private sortOptions?;
|
|
6
|
-
constructor(rooms: any[], conditions: any);
|
|
7
|
-
sort(options: SortOptions): this;
|
|
8
|
-
private applySort;
|
|
9
|
-
private applyFilter;
|
|
10
|
-
filter(conditions: any): T[];
|
|
11
|
-
then(resolve: any, reject: any): any;
|
|
12
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
export declare const postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
2
|
-
method: "POST";
|
|
3
|
-
}, any>;
|
|
4
|
-
export declare function getDefaultRouter(): {
|
|
5
|
-
handler: (request: Request) => Promise<Response>;
|
|
6
|
-
endpoints: {
|
|
7
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
8
|
-
method: "POST";
|
|
9
|
-
}, any>;
|
|
10
|
-
};
|
|
11
|
-
extend: <NE extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE) => {
|
|
12
|
-
handler: (request: Request) => Promise<Response>;
|
|
13
|
-
endpoints: {
|
|
14
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
15
|
-
method: "POST";
|
|
16
|
-
}, any>;
|
|
17
|
-
} & NE;
|
|
18
|
-
extend: <NE_1 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_1) => {
|
|
19
|
-
handler: (request: Request) => Promise<Response>;
|
|
20
|
-
endpoints: {
|
|
21
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
22
|
-
method: "POST";
|
|
23
|
-
}, any>;
|
|
24
|
-
} & NE & NE_1;
|
|
25
|
-
extend: <NE_2 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_2) => {
|
|
26
|
-
handler: (request: Request) => Promise<Response>;
|
|
27
|
-
endpoints: {
|
|
28
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
29
|
-
method: "POST";
|
|
30
|
-
}, any>;
|
|
31
|
-
} & NE & NE_1 & NE_2;
|
|
32
|
-
extend: <NE_3 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_3) => {
|
|
33
|
-
handler: (request: Request) => Promise<Response>;
|
|
34
|
-
endpoints: {
|
|
35
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
36
|
-
method: "POST";
|
|
37
|
-
}, any>;
|
|
38
|
-
} & NE & NE_1 & NE_2 & NE_3;
|
|
39
|
-
extend: <NE_4 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_4) => {
|
|
40
|
-
handler: (request: Request) => Promise<Response>;
|
|
41
|
-
endpoints: {
|
|
42
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
43
|
-
method: "POST";
|
|
44
|
-
}, any>;
|
|
45
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4;
|
|
46
|
-
extend: <NE_5 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_5) => {
|
|
47
|
-
handler: (request: Request) => Promise<Response>;
|
|
48
|
-
endpoints: {
|
|
49
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
50
|
-
method: "POST";
|
|
51
|
-
}, any>;
|
|
52
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5;
|
|
53
|
-
extend: <NE_6 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_6) => {
|
|
54
|
-
handler: (request: Request) => Promise<Response>;
|
|
55
|
-
endpoints: {
|
|
56
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
57
|
-
method: "POST";
|
|
58
|
-
}, any>;
|
|
59
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6;
|
|
60
|
-
extend: <NE_7 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_7) => {
|
|
61
|
-
handler: (request: Request) => Promise<Response>;
|
|
62
|
-
endpoints: {
|
|
63
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
64
|
-
method: "POST";
|
|
65
|
-
}, any>;
|
|
66
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7;
|
|
67
|
-
extend: <NE_8 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_8) => {
|
|
68
|
-
handler: (request: Request) => Promise<Response>;
|
|
69
|
-
endpoints: {
|
|
70
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
71
|
-
method: "POST";
|
|
72
|
-
}, any>;
|
|
73
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7 & NE_8;
|
|
74
|
-
extend: <NE_9 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_9) => {
|
|
75
|
-
handler: (request: Request) => Promise<Response>;
|
|
76
|
-
endpoints: {
|
|
77
|
-
postMatchmakeMethod: import("@colyseus/better-call").StrictEndpoint<"/matchmake/:method/:roomName", {
|
|
78
|
-
method: "POST";
|
|
79
|
-
}, any>;
|
|
80
|
-
} & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7 & NE_8 & NE_9;
|
|
81
|
-
extend: <NE_10 extends Record<string, import("@colyseus/better-call").Endpoint>>(newEndpoints: NE_10) => any;
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exploration: defineRoom() factory function
|
|
3
|
-
*
|
|
4
|
-
* Goal: Allow users to define rooms without explicit generic parameters,
|
|
5
|
-
* while still getting full type inference for broadcast() and client.send()
|
|
6
|
-
*/
|
|
7
|
-
import { Room, type Client } from "@colyseus/core";
|
|
8
|
-
/**
|
|
9
|
-
* Helper type for cleaner Client typing with messages.
|
|
10
|
-
* Reduces boilerplate from `Client<{ messages: M }>` to `MessageClient<M>`.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* type MyClient = MessageClient<{
|
|
15
|
-
* chat: { text: string };
|
|
16
|
-
* move: { x: number; y: number };
|
|
17
|
-
* }>;
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export type MessageClient<Messages extends Record<string, any>> = Client<{
|
|
21
|
-
messages: Messages;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Options for createRoom factory function.
|
|
25
|
-
*/
|
|
26
|
-
interface DefineRoomOptions<TClient extends Client = Client, State extends object = any, JoinOptions = any> {
|
|
27
|
-
state?: State | (() => State);
|
|
28
|
-
onCreate?(this: Room<State, any, TClient>, options: any): void | Promise<void>;
|
|
29
|
-
onJoin?(this: Room<State, any, TClient>, client: TClient, options: JoinOptions): void | Promise<void>;
|
|
30
|
-
onLeave?(this: Room<State, any, TClient>, client: TClient, code?: number): void | Promise<void>;
|
|
31
|
-
onDispose?(this: Room<State, any, TClient>): void | Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create a Room class from an options object.
|
|
35
|
-
* Provides Vue-style object configuration with full type inference.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* type MyClient = Client<{
|
|
40
|
-
* userData: { rank: number };
|
|
41
|
-
* auth: { odToken: string };
|
|
42
|
-
* messages: {
|
|
43
|
-
* chat: { text: string };
|
|
44
|
-
* move: { x: number; y: number };
|
|
45
|
-
* };
|
|
46
|
-
* }>;
|
|
47
|
-
*
|
|
48
|
-
* const MyRoom = createRoom<MyClient, MyState>({
|
|
49
|
-
* state: () => new MyState(),
|
|
50
|
-
*
|
|
51
|
-
* onCreate() {
|
|
52
|
-
* console.log("Room created");
|
|
53
|
-
* },
|
|
54
|
-
*
|
|
55
|
-
* onJoin(client, options) {
|
|
56
|
-
* client.send("chat", { text: "Welcome!" }); // ✅ typed!
|
|
57
|
-
* this.broadcast("move", { x: 0, y: 0 }); // ✅ typed!
|
|
58
|
-
* client.userData.rank; // ✅ typed!
|
|
59
|
-
* client.auth.odToken; // ✅ typed!
|
|
60
|
-
* }
|
|
61
|
-
* });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare function createRoom<TClient extends Client = Client, State extends object = any, JoinOptions = any>(options: DefineRoomOptions<TClient, State, JoinOptions>): typeof Room<State, any, TClient>;
|
|
65
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|