@colyseus/core 0.15.50 → 0.15.52

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.
@@ -0,0 +1,43 @@
1
+ // packages/core/src/matchmaker/driver/local/LocalDriver.ts
2
+ import { logger } from "../../../Logger.mjs";
3
+ import { Query } from "./Query.mjs";
4
+ import { RoomData } from "./RoomData.mjs";
5
+ var LocalDriver = class {
6
+ constructor() {
7
+ this.rooms = [];
8
+ }
9
+ createInstance(initialValues = {}) {
10
+ return new RoomData(initialValues, this.rooms);
11
+ }
12
+ has(roomId) {
13
+ return this.rooms.some((room) => room.roomId === roomId);
14
+ }
15
+ query(conditions, sortOptions) {
16
+ const query = new Query(this.rooms, conditions);
17
+ if (sortOptions) {
18
+ query.sort(sortOptions);
19
+ }
20
+ return query.filter(conditions);
21
+ }
22
+ cleanup(processId) {
23
+ const cachedRooms = this.query({ processId });
24
+ logger.debug("> Removing stale rooms by processId:", processId, `(${cachedRooms.length} rooms found)`);
25
+ cachedRooms.forEach((room) => room.remove());
26
+ return Promise.resolve();
27
+ }
28
+ findOne(conditions, sortOptions) {
29
+ const query = new Query(this.rooms, conditions);
30
+ if (sortOptions) {
31
+ query.sort(sortOptions);
32
+ }
33
+ return query;
34
+ }
35
+ clear() {
36
+ this.rooms = [];
37
+ }
38
+ shutdown() {
39
+ }
40
+ };
41
+ export {
42
+ LocalDriver
43
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/LocalDriver.ts"],
4
+ "sourcesContent": ["import { logger } from '../../../Logger.js';\nimport { IRoomCache, SortOptions, RoomCache, MatchMakerDriver } from '../api.js';\n\n// re-export\nexport type { IRoomCache, SortOptions, RoomCache, MatchMakerDriver };\n\nimport { Query } from './Query.js';\nimport { RoomData } from './RoomData.js';\n\nexport class LocalDriver implements MatchMakerDriver {\n public rooms: IRoomCache[] = [];\n\n public createInstance(initialValues: any = {}) {\n return new RoomData(initialValues, this.rooms);\n }\n\n public has(roomId: string) {\n return this.rooms.some((room) => room.roomId === roomId);\n }\n\n public query(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query.filter(conditions);\n }\n\n public cleanup(processId: string) {\n const cachedRooms = this.query({ processId });\n logger.debug(\"> Removing stale rooms by processId:\", processId, `(${cachedRooms.length} rooms found)`);\n\n cachedRooms.forEach((room) => room.remove());\n return Promise.resolve();\n }\n\n public findOne(conditions: Partial<IRoomCache>, sortOptions?: SortOptions) {\n const query = new Query<RoomCache>(this.rooms, conditions);\n\n if (sortOptions) {\n query.sort(sortOptions);\n }\n\n return query as unknown as Promise<RoomCache>;\n }\n\n public clear() {\n this.rooms = [];\n }\n\n public shutdown() {\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,cAAc;AAMvB,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAElB,IAAM,cAAN,MAA8C;AAAA,EAA9C;AACL,SAAO,QAAsB,CAAC;AAAA;AAAA,EAEvB,eAAe,gBAAqB,CAAC,GAAG;AAC7C,WAAO,IAAI,SAAS,eAAe,KAAK,KAAK;AAAA,EAC/C;AAAA,EAEO,IAAI,QAAgB;AACzB,WAAO,KAAK,MAAM,KAAK,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACzD;AAAA,EAEO,MAAM,YAAiC,aAA2B;AACvE,UAAM,QAAQ,IAAI,MAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO,MAAM,OAAO,UAAU;AAAA,EAChC;AAAA,EAEO,QAAQ,WAAmB;AAChC,UAAM,cAAc,KAAK,MAAM,EAAE,UAAU,CAAC;AAC5C,WAAO,MAAM,wCAAwC,WAAW,IAAI,YAAY,MAAM,eAAe;AAErG,gBAAY,QAAQ,CAAC,SAAS,KAAK,OAAO,CAAC;AAC3C,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEO,QAAQ,YAAiC,aAA2B;AACzE,UAAM,QAAQ,IAAI,MAAiB,KAAK,OAAO,UAAU;AAEzD,QAAI,aAAa;AACf,YAAM,KAAK,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,QAAQ;AACb,SAAK,QAAQ,CAAC;AAAA,EAChB;AAAA,EAEO,WAAW;AAAA,EAClB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ import { SortOptions } from '../api.js';
2
+ export declare class Query<T> {
3
+ private $rooms;
4
+ private conditions;
5
+ constructor(rooms: any[], conditions: any);
6
+ sort(options: SortOptions): void;
7
+ filter(conditions: any): T[];
8
+ then(resolve: any, reject: any): any;
9
+ }
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var Query_exports = {};
19
+ __export(Query_exports, {
20
+ Query: () => Query
21
+ });
22
+ module.exports = __toCommonJS(Query_exports);
23
+ class Query {
24
+ constructor(rooms, conditions) {
25
+ this.$rooms = rooms.slice(0);
26
+ this.conditions = conditions;
27
+ }
28
+ sort(options) {
29
+ this.$rooms = this.$rooms.sort((room1, room2) => {
30
+ for (const field in options) {
31
+ if (options.hasOwnProperty(field)) {
32
+ const direction = options[field];
33
+ const isAscending = direction === 1 || direction === "asc" || direction === "ascending";
34
+ if (isAscending) {
35
+ if (room1[field] > room2[field]) {
36
+ return 1;
37
+ }
38
+ if (room1[field] < room2[field]) {
39
+ return -1;
40
+ }
41
+ } else {
42
+ if (room1[field] > room2[field]) {
43
+ return -1;
44
+ }
45
+ if (room1[field] < room2[field]) {
46
+ return 1;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ });
52
+ }
53
+ filter(conditions) {
54
+ return this.$rooms.filter((room) => {
55
+ for (const field in conditions) {
56
+ if (conditions.hasOwnProperty(field) && room[field] !== conditions[field]) {
57
+ return false;
58
+ }
59
+ }
60
+ return true;
61
+ });
62
+ }
63
+ then(resolve, reject) {
64
+ const result = this.$rooms.find((room) => {
65
+ for (const field in this.conditions) {
66
+ if (this.conditions.hasOwnProperty(field) && room[field] !== this.conditions[field]) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ });
72
+ return resolve(result);
73
+ }
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ Query
78
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/Query.ts"],
4
+ "sourcesContent": ["import { SortOptions } from '../api.js';\n\nexport class Query<T> {\n private $rooms: T[];\n private conditions: any;\n\n constructor(rooms: any[], conditions) {\n this.$rooms = rooms.slice(0);\n this.conditions = conditions;\n }\n\n public sort(options: SortOptions) {\n this.$rooms = this.$rooms.sort((room1, room2) => {\n for (const field in options) {\n if (options.hasOwnProperty(field)) {\n const direction = options[field];\n const isAscending = (direction === 1 || direction === 'asc' || direction === 'ascending');\n\n if (isAscending) {\n if (room1[field] > room2[field]) { return 1; }\n if (room1[field] < room2[field]) { return -1; }\n\n } else {\n if (room1[field] > room2[field]) { return -1; }\n if (room1[field] < room2[field]) { return 1; }\n }\n }\n }\n });\n }\n\n public filter(conditions: any) {\n return this.$rooms.filter(((room) => {\n for (const field in conditions) {\n if (\n conditions.hasOwnProperty(field) &&\n room[field] !== conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n\n }\n\n public then(resolve, reject) {\n const result: any = this.$rooms.find(((room) => {\n for (const field in this.conditions) {\n if (\n this.conditions.hasOwnProperty(field) &&\n room[field] !== this.conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n return resolve(result);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,MAAS;AAAA,EAIpB,YAAY,OAAc,YAAY;AACpC,SAAK,SAAS,MAAM,MAAM,CAAC;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,KAAK,SAAsB;AAChC,SAAK,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU;AAC/C,iBAAW,SAAS,SAAS;AAC3B,YAAI,QAAQ,eAAe,KAAK,GAAG;AACjC,gBAAM,YAAY,QAAQ,KAAK;AAC/B,gBAAM,cAAe,cAAc,KAAK,cAAc,SAAS,cAAc;AAE7E,cAAI,aAAa;AACf,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAG;AAC7C,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAI;AAAA,UAEhD,OAAO;AACL,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAI;AAC9C,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAG;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,YAAiB;AAC7B,WAAO,KAAK,OAAO,OAAQ,CAAC,SAAS;AACnC,iBAAW,SAAS,YAAY;AAC9B,YACE,WAAW,eAAe,KAAK,KAC/B,KAAK,KAAK,MAAM,WAAW,KAAK,GAChC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AAAA,EAEJ;AAAA,EAEO,KAAK,SAAS,QAAQ;AAC3B,UAAM,SAAc,KAAK,OAAO,KAAM,CAAC,SAAS;AAC9C,iBAAW,SAAS,KAAK,YAAY;AACnC,YACE,KAAK,WAAW,eAAe,KAAK,KACpC,KAAK,KAAK,MAAM,KAAK,WAAW,KAAK,GACrC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AACF,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
1
+ // packages/core/src/matchmaker/driver/local/Query.ts
2
+ var Query = class {
3
+ constructor(rooms, conditions) {
4
+ this.$rooms = rooms.slice(0);
5
+ this.conditions = conditions;
6
+ }
7
+ sort(options) {
8
+ this.$rooms = this.$rooms.sort((room1, room2) => {
9
+ for (const field in options) {
10
+ if (options.hasOwnProperty(field)) {
11
+ const direction = options[field];
12
+ const isAscending = direction === 1 || direction === "asc" || direction === "ascending";
13
+ if (isAscending) {
14
+ if (room1[field] > room2[field]) {
15
+ return 1;
16
+ }
17
+ if (room1[field] < room2[field]) {
18
+ return -1;
19
+ }
20
+ } else {
21
+ if (room1[field] > room2[field]) {
22
+ return -1;
23
+ }
24
+ if (room1[field] < room2[field]) {
25
+ return 1;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ });
31
+ }
32
+ filter(conditions) {
33
+ return this.$rooms.filter((room) => {
34
+ for (const field in conditions) {
35
+ if (conditions.hasOwnProperty(field) && room[field] !== conditions[field]) {
36
+ return false;
37
+ }
38
+ }
39
+ return true;
40
+ });
41
+ }
42
+ then(resolve, reject) {
43
+ const result = this.$rooms.find((room) => {
44
+ for (const field in this.conditions) {
45
+ if (this.conditions.hasOwnProperty(field) && room[field] !== this.conditions[field]) {
46
+ return false;
47
+ }
48
+ }
49
+ return true;
50
+ });
51
+ return resolve(result);
52
+ }
53
+ };
54
+ export {
55
+ Query
56
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/Query.ts"],
4
+ "sourcesContent": ["import { SortOptions } from '../api.js';\n\nexport class Query<T> {\n private $rooms: T[];\n private conditions: any;\n\n constructor(rooms: any[], conditions) {\n this.$rooms = rooms.slice(0);\n this.conditions = conditions;\n }\n\n public sort(options: SortOptions) {\n this.$rooms = this.$rooms.sort((room1, room2) => {\n for (const field in options) {\n if (options.hasOwnProperty(field)) {\n const direction = options[field];\n const isAscending = (direction === 1 || direction === 'asc' || direction === 'ascending');\n\n if (isAscending) {\n if (room1[field] > room2[field]) { return 1; }\n if (room1[field] < room2[field]) { return -1; }\n\n } else {\n if (room1[field] > room2[field]) { return -1; }\n if (room1[field] < room2[field]) { return 1; }\n }\n }\n }\n });\n }\n\n public filter(conditions: any) {\n return this.$rooms.filter(((room) => {\n for (const field in conditions) {\n if (\n conditions.hasOwnProperty(field) &&\n room[field] !== conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n\n }\n\n public then(resolve, reject) {\n const result: any = this.$rooms.find(((room) => {\n for (const field in this.conditions) {\n if (\n this.conditions.hasOwnProperty(field) &&\n room[field] !== this.conditions[field]\n ) {\n return false;\n }\n }\n return true;\n }));\n return resolve(result);\n }\n}\n"],
5
+ "mappings": ";AAEO,IAAM,QAAN,MAAe;AAAA,EAIpB,YAAY,OAAc,YAAY;AACpC,SAAK,SAAS,MAAM,MAAM,CAAC;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,KAAK,SAAsB;AAChC,SAAK,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU;AAC/C,iBAAW,SAAS,SAAS;AAC3B,YAAI,QAAQ,eAAe,KAAK,GAAG;AACjC,gBAAM,YAAY,QAAQ,KAAK;AAC/B,gBAAM,cAAe,cAAc,KAAK,cAAc,SAAS,cAAc;AAE7E,cAAI,aAAa;AACf,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAG;AAC7C,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAI;AAAA,UAEhD,OAAO;AACL,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAI;AAC9C,gBAAI,MAAM,KAAK,IAAI,MAAM,KAAK,GAAG;AAAE,qBAAO;AAAA,YAAG;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,OAAO,YAAiB;AAC7B,WAAO,KAAK,OAAO,OAAQ,CAAC,SAAS;AACnC,iBAAW,SAAS,YAAY;AAC9B,YACE,WAAW,eAAe,KAAK,KAC/B,KAAK,KAAK,MAAM,WAAW,KAAK,GAChC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AAAA,EAEJ;AAAA,EAEO,KAAK,SAAS,QAAQ;AAC3B,UAAM,SAAc,KAAK,OAAO,KAAM,CAAC,SAAS;AAC9C,iBAAW,SAAS,KAAK,YAAY;AACnC,YACE,KAAK,WAAW,eAAe,KAAK,KACpC,KAAK,KAAK,MAAM,KAAK,WAAW,KAAK,GACrC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AACF,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ import { RoomCache, IRoomCache } from '../api.js';
2
+ export declare class RoomData implements RoomCache {
3
+ clients: number;
4
+ locked: boolean;
5
+ private: boolean;
6
+ maxClients: number;
7
+ metadata: any;
8
+ name: string;
9
+ publicAddress: string;
10
+ processId: string;
11
+ roomId: string;
12
+ createdAt: Date;
13
+ unlisted: boolean;
14
+ private $rooms;
15
+ constructor(initialValues: any, rooms: IRoomCache[]);
16
+ save(): void;
17
+ updateOne(operations: any): void;
18
+ remove(): void;
19
+ }
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var RoomData_exports = {};
19
+ __export(RoomData_exports, {
20
+ RoomData: () => RoomData
21
+ });
22
+ module.exports = __toCommonJS(RoomData_exports);
23
+ var import_Utils = require("../../../utils/Utils.js");
24
+ class RoomData {
25
+ constructor(initialValues, rooms) {
26
+ this.clients = 0;
27
+ this.locked = false;
28
+ this.private = false;
29
+ this.maxClients = Infinity;
30
+ this.unlisted = false;
31
+ this.createdAt = /* @__PURE__ */ new Date();
32
+ for (const field in initialValues) {
33
+ if (initialValues.hasOwnProperty(field)) {
34
+ this[field] = initialValues[field];
35
+ }
36
+ }
37
+ Object.defineProperty(this, "$rooms", {
38
+ value: rooms,
39
+ enumerable: false,
40
+ writable: true
41
+ });
42
+ }
43
+ save() {
44
+ if (this.$rooms.indexOf(this) === -1) {
45
+ this.$rooms.push(this);
46
+ }
47
+ }
48
+ updateOne(operations) {
49
+ if (operations.$set) {
50
+ for (const field in operations.$set) {
51
+ if (operations.$set.hasOwnProperty(field)) {
52
+ this[field] = operations.$set[field];
53
+ }
54
+ }
55
+ }
56
+ if (operations.$inc) {
57
+ for (const field in operations.$inc) {
58
+ if (operations.$inc.hasOwnProperty(field)) {
59
+ this[field] += operations.$inc[field];
60
+ }
61
+ }
62
+ }
63
+ }
64
+ remove() {
65
+ if (!this.$rooms) {
66
+ return;
67
+ }
68
+ const roomIndex = this.$rooms.indexOf(this);
69
+ if (roomIndex === -1) {
70
+ return;
71
+ }
72
+ (0, import_Utils.spliceOne)(this.$rooms, roomIndex);
73
+ this.$rooms = null;
74
+ }
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ RoomData
79
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/RoomData.ts"],
4
+ "sourcesContent": ["import { spliceOne } from '../../../utils/Utils.js';\nimport { RoomCache, IRoomCache } from '../api.js';\n\nexport class RoomData implements RoomCache {\n public clients: number = 0;\n public locked: boolean = false;\n public private: boolean = false;\n public maxClients: number = Infinity;\n public metadata: any;\n public name: string;\n public publicAddress: string;\n public processId: string;\n public roomId: string;\n public createdAt: Date;\n public unlisted: boolean = false;\n\n private $rooms: RoomCache[];\n\n constructor(initialValues: any, rooms: IRoomCache[]) {\n this.createdAt = new Date();\n\n for (const field in initialValues) {\n if (initialValues.hasOwnProperty(field)) {\n this[field] = initialValues[field];\n }\n }\n\n // make $rooms non-enumerable, so it can be serialized (circular references)\n Object.defineProperty(this, \"$rooms\", {\n value: rooms,\n enumerable: false,\n writable: true,\n });\n }\n\n public save() {\n if (this.$rooms.indexOf(this) === -1) {\n this.$rooms.push(this);\n }\n }\n\n public updateOne(operations: any) {\n if (operations.$set) {\n for (const field in operations.$set) {\n if (operations.$set.hasOwnProperty(field)) {\n this[field] = operations.$set[field];\n }\n }\n }\n\n if (operations.$inc) {\n for (const field in operations.$inc) {\n if (operations.$inc.hasOwnProperty(field)) {\n this[field] += operations.$inc[field];\n }\n }\n }\n }\n\n public remove() {\n //\n // WORKAROUND: prevent calling `.remove()` multiple times\n // Seems to happen during disconnect + dispose: https://github.com/colyseus/colyseus/issues/390\n //\n if (!this.$rooms) { return; }\n\n const roomIndex = this.$rooms.indexOf(this);\n if (roomIndex === -1) { return; }\n\n spliceOne(this.$rooms, roomIndex);\n this.$rooms = null;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAGnB,MAAM,SAA8B;AAAA,EAezC,YAAY,eAAoB,OAAqB;AAdrD,SAAO,UAAkB;AACzB,SAAO,SAAkB;AACzB,SAAO,UAAmB;AAC1B,SAAO,aAAqB;AAO5B,SAAO,WAAoB;AAKzB,SAAK,YAAY,oBAAI,KAAK;AAE1B,eAAW,SAAS,eAAe;AACjC,UAAI,cAAc,eAAe,KAAK,GAAG;AACvC,aAAK,KAAK,IAAI,cAAc,KAAK;AAAA,MACnC;AAAA,IACF;AAGA,WAAO,eAAe,MAAM,UAAU;AAAA,MACpC,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEO,OAAO;AACZ,QAAI,KAAK,OAAO,QAAQ,IAAI,MAAM,IAAI;AACpC,WAAK,OAAO,KAAK,IAAI;AAAA,IACvB;AAAA,EACF;AAAA,EAEO,UAAU,YAAiB;AAChC,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,KAAK,IAAI,WAAW,KAAK,KAAK;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,KAAK,KAAK,WAAW,KAAK,KAAK;AAAA,QACtC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,SAAS;AAKd,QAAI,CAAC,KAAK,QAAQ;AAAE;AAAA,IAAQ;AAE5B,UAAM,YAAY,KAAK,OAAO,QAAQ,IAAI;AAC1C,QAAI,cAAc,IAAI;AAAE;AAAA,IAAQ;AAEhC,gCAAU,KAAK,QAAQ,SAAS;AAChC,SAAK,SAAS;AAAA,EAChB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,57 @@
1
+ // packages/core/src/matchmaker/driver/local/RoomData.ts
2
+ import { spliceOne } from "../../../utils/Utils.mjs";
3
+ var RoomData = class {
4
+ constructor(initialValues, rooms) {
5
+ this.clients = 0;
6
+ this.locked = false;
7
+ this.private = false;
8
+ this.maxClients = Infinity;
9
+ this.unlisted = false;
10
+ this.createdAt = /* @__PURE__ */ new Date();
11
+ for (const field in initialValues) {
12
+ if (initialValues.hasOwnProperty(field)) {
13
+ this[field] = initialValues[field];
14
+ }
15
+ }
16
+ Object.defineProperty(this, "$rooms", {
17
+ value: rooms,
18
+ enumerable: false,
19
+ writable: true
20
+ });
21
+ }
22
+ save() {
23
+ if (this.$rooms.indexOf(this) === -1) {
24
+ this.$rooms.push(this);
25
+ }
26
+ }
27
+ updateOne(operations) {
28
+ if (operations.$set) {
29
+ for (const field in operations.$set) {
30
+ if (operations.$set.hasOwnProperty(field)) {
31
+ this[field] = operations.$set[field];
32
+ }
33
+ }
34
+ }
35
+ if (operations.$inc) {
36
+ for (const field in operations.$inc) {
37
+ if (operations.$inc.hasOwnProperty(field)) {
38
+ this[field] += operations.$inc[field];
39
+ }
40
+ }
41
+ }
42
+ }
43
+ remove() {
44
+ if (!this.$rooms) {
45
+ return;
46
+ }
47
+ const roomIndex = this.$rooms.indexOf(this);
48
+ if (roomIndex === -1) {
49
+ return;
50
+ }
51
+ spliceOne(this.$rooms, roomIndex);
52
+ this.$rooms = null;
53
+ }
54
+ };
55
+ export {
56
+ RoomData
57
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/matchmaker/driver/local/RoomData.ts"],
4
+ "sourcesContent": ["import { spliceOne } from '../../../utils/Utils.js';\nimport { RoomCache, IRoomCache } from '../api.js';\n\nexport class RoomData implements RoomCache {\n public clients: number = 0;\n public locked: boolean = false;\n public private: boolean = false;\n public maxClients: number = Infinity;\n public metadata: any;\n public name: string;\n public publicAddress: string;\n public processId: string;\n public roomId: string;\n public createdAt: Date;\n public unlisted: boolean = false;\n\n private $rooms: RoomCache[];\n\n constructor(initialValues: any, rooms: IRoomCache[]) {\n this.createdAt = new Date();\n\n for (const field in initialValues) {\n if (initialValues.hasOwnProperty(field)) {\n this[field] = initialValues[field];\n }\n }\n\n // make $rooms non-enumerable, so it can be serialized (circular references)\n Object.defineProperty(this, \"$rooms\", {\n value: rooms,\n enumerable: false,\n writable: true,\n });\n }\n\n public save() {\n if (this.$rooms.indexOf(this) === -1) {\n this.$rooms.push(this);\n }\n }\n\n public updateOne(operations: any) {\n if (operations.$set) {\n for (const field in operations.$set) {\n if (operations.$set.hasOwnProperty(field)) {\n this[field] = operations.$set[field];\n }\n }\n }\n\n if (operations.$inc) {\n for (const field in operations.$inc) {\n if (operations.$inc.hasOwnProperty(field)) {\n this[field] += operations.$inc[field];\n }\n }\n }\n }\n\n public remove() {\n //\n // WORKAROUND: prevent calling `.remove()` multiple times\n // Seems to happen during disconnect + dispose: https://github.com/colyseus/colyseus/issues/390\n //\n if (!this.$rooms) { return; }\n\n const roomIndex = this.$rooms.indexOf(this);\n if (roomIndex === -1) { return; }\n\n spliceOne(this.$rooms, roomIndex);\n this.$rooms = null;\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,iBAAiB;AAGnB,IAAM,WAAN,MAAoC;AAAA,EAezC,YAAY,eAAoB,OAAqB;AAdrD,SAAO,UAAkB;AACzB,SAAO,SAAkB;AACzB,SAAO,UAAmB;AAC1B,SAAO,aAAqB;AAO5B,SAAO,WAAoB;AAKzB,SAAK,YAAY,oBAAI,KAAK;AAE1B,eAAW,SAAS,eAAe;AACjC,UAAI,cAAc,eAAe,KAAK,GAAG;AACvC,aAAK,KAAK,IAAI,cAAc,KAAK;AAAA,MACnC;AAAA,IACF;AAGA,WAAO,eAAe,MAAM,UAAU;AAAA,MACpC,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AAAA,EAEO,OAAO;AACZ,QAAI,KAAK,OAAO,QAAQ,IAAI,MAAM,IAAI;AACpC,WAAK,OAAO,KAAK,IAAI;AAAA,IACvB;AAAA,EACF;AAAA,EAEO,UAAU,YAAiB;AAChC,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,KAAK,IAAI,WAAW,KAAK,KAAK;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,WAAW,MAAM;AACnB,iBAAW,SAAS,WAAW,MAAM;AACnC,YAAI,WAAW,KAAK,eAAe,KAAK,GAAG;AACzC,eAAK,KAAK,KAAK,WAAW,KAAK,KAAK;AAAA,QACtC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,SAAS;AAKd,QAAI,CAAC,KAAK,QAAQ;AAAE;AAAA,IAAQ;AAE5B,UAAM,YAAY,KAAK,OAAO,QAAQ,IAAI;AAC1C,QAAI,cAAc,IAAI;AAAE;AAAA,IAAQ;AAEhC,cAAU,KAAK,QAAQ,SAAS;AAChC,SAAK,SAAS;AAAA,EAChB;AACF;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/core",
3
- "version": "0.15.50",
3
+ "version": "0.15.52",
4
4
  "description": "Multiplayer Framework for Node.js.",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",