@open-core/framework 0.2.1-beta.1 → 0.2.4

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.
Files changed (38) hide show
  1. package/LICENSE +373 -373
  2. package/README.md +217 -217
  3. package/dist/adapters/node/node-entity-server.js +3 -0
  4. package/dist/adapters/node/node-exports.d.ts +2 -2
  5. package/dist/kernel/utils/vector3.d.ts +1 -0
  6. package/dist/kernel/utils/vector3.js +1 -0
  7. package/dist/runtime/client/services/appearance.service.js +4 -0
  8. package/dist/runtime/server/bootstrap.js +1 -1
  9. package/dist/runtime/server/bootstrap.validation.js +2 -0
  10. package/dist/runtime/server/bus/core-event-bus.js +5 -2
  11. package/dist/runtime/server/controllers/principal-export.controller.js +1 -1
  12. package/dist/runtime/server/decorators/command.d.ts +6 -3
  13. package/dist/runtime/server/decorators/onNet.d.ts +5 -2
  14. package/dist/runtime/server/decorators/throttle.js +3 -1
  15. package/dist/runtime/server/helpers/command-validation.helper.d.ts +1 -1
  16. package/dist/runtime/server/helpers/function-helper.d.ts +1 -1
  17. package/dist/runtime/server/services/chat.service.d.ts +33 -0
  18. package/dist/runtime/server/services/chat.service.js +67 -1
  19. package/dist/runtime/server/services/core/command.service.d.ts +1 -1
  20. package/dist/runtime/server/services/parallel/worker-pool.js +4 -0
  21. package/dist/runtime/server/services/ports/command-execution.port.d.ts +1 -1
  22. package/dist/runtime/server/services/remote/remote-command.service.d.ts +1 -1
  23. package/dist/runtime/server/services/services.register.js +2 -2
  24. package/package.json +100 -98
  25. package/dist/kernel/di/tokens.d.ts +0 -30
  26. package/dist/kernel/di/tokens.js +0 -38
  27. package/dist/runtime/client/interfaces/appearance.interface.d.ts +0 -25
  28. package/dist/runtime/client/interfaces/appearance.interface.js +0 -2
  29. package/dist/runtime/server/controllers/command.controller.d.ts +0 -15
  30. package/dist/runtime/server/controllers/command.controller.js +0 -100
  31. package/dist/runtime/server/services/access-control.service.d.ts +0 -59
  32. package/dist/runtime/server/services/access-control.service.js +0 -127
  33. package/dist/runtime/server/services/core/vehicle-modification.service.d.ts +0 -104
  34. package/dist/runtime/server/services/core/vehicle-modification.service.js +0 -330
  35. package/dist/runtime/server/services/core/vehicle.service.d.ts +0 -128
  36. package/dist/runtime/server/services/core/vehicle.service.js +0 -391
  37. package/dist/runtime/server/services/remote/remote-principal.provider.d.ts +0 -55
  38. package/dist/runtime/server/services/remote/remote-principal.provider.js +0 -130
@@ -1,5 +1,6 @@
1
1
  import { Server } from '../../..';
2
2
  import { RGB } from '../../../kernel/utils';
3
+ import { PlayerDirectoryPort } from './ports/player-directory.port';
3
4
  /**
4
5
  * Service for sending chat messages to players.
5
6
  *
@@ -7,6 +8,8 @@ import { RGB } from '../../../kernel/utils';
7
8
  * This service emits framework chat events over the network.
8
9
  */
9
10
  export declare class ChatService {
11
+ private readonly playerDirectory;
12
+ constructor(playerDirectory: PlayerDirectoryPort);
10
13
  /**
11
14
  * Broadcast a chat message to all connected players.
12
15
  *
@@ -30,4 +33,34 @@ export declare class ChatService {
30
33
  * @param player - Target player.
31
34
  */
32
35
  clearChat(player: Server.Player): void;
36
+ /**
37
+ * Send a chat message to multiple players.
38
+ *
39
+ * @param players - Array of target players or their client IDs.
40
+ * @param message - Message body.
41
+ * @param author - Author label.
42
+ * @param color - Message color (RGB).
43
+ */
44
+ sendMany(players: (Server.Player | number)[], message: string, author?: string, color?: RGB): void;
45
+ /**
46
+ * Send a chat message to players within a certain radius of a specific player.
47
+ *
48
+ * @param playerFrom - Origin player.
49
+ * @param message - Message body.
50
+ * @param radius - Distance radius in game units.
51
+ * @param author - Author label.
52
+ * @param color - Message color (RGB).
53
+ */
54
+ sendNearby(playerFrom: Server.Player, message: string, radius: number, author?: string, color?: RGB): void;
55
+ /**
56
+ * Broadcast a system message to all players.
57
+ *
58
+ * @param message - Message body.
59
+ * @param color - Message color (RGB). Defaults to a light blue/cyan.
60
+ */
61
+ broadcastSystem(message: string, color?: RGB): void;
62
+ /**
63
+ * Clear chat for all connected players.
64
+ */
65
+ clearChatAll(): void;
33
66
  }
@@ -5,9 +5,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.ChatService = void 0;
10
13
  const tsyringe_1 = require("tsyringe");
14
+ const player_directory_port_1 = require("./ports/player-directory.port");
11
15
  /**
12
16
  * Service for sending chat messages to players.
13
17
  *
@@ -15,6 +19,9 @@ const tsyringe_1 = require("tsyringe");
15
19
  * This service emits framework chat events over the network.
16
20
  */
17
21
  let ChatService = class ChatService {
22
+ constructor(playerDirectory) {
23
+ this.playerDirectory = playerDirectory;
24
+ }
18
25
  /**
19
26
  * Broadcast a chat message to all connected players.
20
27
  *
@@ -50,8 +57,67 @@ let ChatService = class ChatService {
50
57
  clearChat(player) {
51
58
  emitNet('core:chat:clear', player.clientID);
52
59
  }
60
+ /**
61
+ * Send a chat message to multiple players.
62
+ *
63
+ * @param players - Array of target players or their client IDs.
64
+ * @param message - Message body.
65
+ * @param author - Author label.
66
+ * @param color - Message color (RGB).
67
+ */
68
+ sendMany(players, message, author = 'SYSTEM', color = { r: 255, g: 255, b: 255 }) {
69
+ players.forEach((p) => {
70
+ const targetId = typeof p === 'number' ? p : p.clientID;
71
+ emitNet('core:chat:addMessage', targetId, {
72
+ args: [author, message],
73
+ color: color,
74
+ });
75
+ });
76
+ }
77
+ /**
78
+ * Send a chat message to players within a certain radius of a specific player.
79
+ *
80
+ * @param playerFrom - Origin player.
81
+ * @param message - Message body.
82
+ * @param radius - Distance radius in game units.
83
+ * @param author - Author label.
84
+ * @param color - Message color (RGB).
85
+ */
86
+ sendNearby(playerFrom, message, radius, author = playerFrom.name, color = { r: 255, g: 255, b: 255 }) {
87
+ const originPos = playerFrom.getPosition();
88
+ if (!originPos)
89
+ return;
90
+ const allPlayers = this.playerDirectory.getAll();
91
+ const nearbyPlayers = allPlayers.filter((p) => {
92
+ const pos = p.getPosition();
93
+ if (!pos)
94
+ return false;
95
+ const dx = originPos.x - pos.x;
96
+ const dy = originPos.y - pos.y;
97
+ const dz = originPos.z - pos.z;
98
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
99
+ return distance <= radius;
100
+ });
101
+ this.sendMany(nearbyPlayers, message, author, color);
102
+ }
103
+ /**
104
+ * Broadcast a system message to all players.
105
+ *
106
+ * @param message - Message body.
107
+ * @param color - Message color (RGB). Defaults to a light blue/cyan.
108
+ */
109
+ broadcastSystem(message, color = { r: 0, g: 191, b: 255 }) {
110
+ this.broadcast(message, 'SYSTEM', color);
111
+ }
112
+ /**
113
+ * Clear chat for all connected players.
114
+ */
115
+ clearChatAll() {
116
+ emitNet('core:chat:clear', -1);
117
+ }
53
118
  };
54
119
  exports.ChatService = ChatService;
55
120
  exports.ChatService = ChatService = __decorate([
56
- (0, tsyringe_1.injectable)()
121
+ (0, tsyringe_1.injectable)(),
122
+ __metadata("design:paramtypes", [player_directory_port_1.PlayerDirectoryPort])
57
123
  ], ChatService);
@@ -22,7 +22,7 @@ export declare class CommandService extends CommandExecutionPort {
22
22
  * @param meta - Command metadata collected from the {@link Command} decorator.
23
23
  * @param handler - The bound method to invoke.
24
24
  */
25
- register(meta: CommandMetadata, handler: Function): void;
25
+ register(meta: CommandMetadata, handler: (...args: any[]) => any): void;
26
26
  /**
27
27
  * Executes a registered command.
28
28
  *
@@ -305,12 +305,16 @@ class WorkerPool extends SimpleEventEmitter {
305
305
  const idleWorker = this.findIdleWorker();
306
306
  if (idleWorker) {
307
307
  const task = this.taskQueue.shift();
308
+ if (!task)
309
+ break;
308
310
  this.assignTask(idleWorker, task);
309
311
  }
310
312
  else if (this.workers.size < this.config.maxWorkers) {
311
313
  const newWorker = this.spawnWorker();
312
314
  if (newWorker) {
313
315
  const task = this.taskQueue.shift();
316
+ if (!task)
317
+ break;
314
318
  this.assignTask(newWorker, task);
315
319
  }
316
320
  else {
@@ -25,7 +25,7 @@ export declare abstract class CommandExecutionPort {
25
25
  * @param metadata - Command metadata from decorator
26
26
  * @param handler - Bound method to invoke when command is executed
27
27
  */
28
- abstract register(metadata: CommandMetadata, handler: Function): void;
28
+ abstract register(metadata: CommandMetadata, handler: (...args: any[]) => any): void;
29
29
  /**
30
30
  * Executes a registered command.
31
31
  *
@@ -36,7 +36,7 @@ export declare class RemoteCommandService extends CommandExecutionPort {
36
36
  * The handler and full metadata are stored locally for schema validation.
37
37
  * Only serializable metadata is sent to CORE for security validation.
38
38
  */
39
- register(metadata: CommandMetadata, handler: Function): void;
39
+ register(metadata: CommandMetadata, handler: (...args: any[]) => any): void;
40
40
  /**
41
41
  * Executes a command handler stored in this resource.
42
42
  *
@@ -9,13 +9,13 @@ const player_service_1 = require("./core/player.service");
9
9
  const principal_service_1 = require("./core/principal.service");
10
10
  const http_service_1 = require("./http/http.service");
11
11
  const persistence_service_1 = require("./persistence.service");
12
- const player_session_lifecycle_port_1 = require("./ports/player-session-lifecycle.port");
12
+ const command_execution_port_1 = require("./ports/command-execution.port");
13
13
  const player_directory_port_1 = require("./ports/player-directory.port");
14
+ const player_session_lifecycle_port_1 = require("./ports/player-session-lifecycle.port");
14
15
  const principal_port_1 = require("./ports/principal.port");
15
16
  const remote_command_service_1 = require("./remote/remote-command.service");
16
17
  const remote_player_service_1 = require("./remote/remote-player.service");
17
18
  const remote_principal_service_1 = require("./remote/remote-principal.service");
18
- const command_execution_port_1 = require("./ports/command-execution.port");
19
19
  /**
20
20
  * Registers server runtime services in the dependency injection container.
21
21
  *
package/package.json CHANGED
@@ -1,98 +1,100 @@
1
- {
2
- "name": "@open-core/framework",
3
- "version": "0.2.1-beta.1",
4
- "description": "Secure, Event-Driven, OOP Engine for FiveM. Stop scripting, start engineering.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "commonjs",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/newcore-network/opencore.git"
11
- },
12
- "homepage": "https://github.com/newcore-network/opencore",
13
- "bugs": {
14
- "url": "https://github.com/newcore-network/opencore/issues"
15
- },
16
- "files": [
17
- "dist",
18
- "README.md",
19
- "LICENSE"
20
- ],
21
- "exports": {
22
- ".": {
23
- "types": "./dist/index.d.ts",
24
- "import": "./dist/index.js",
25
- "require": "./dist/index.js"
26
- },
27
- "./server": {
28
- "types": "./dist/runtime/server/index.d.ts",
29
- "import": "./dist/runtime/server/index.js",
30
- "require": "./dist/runtime/server/index.js"
31
- },
32
- "./client": {
33
- "types": "./dist/runtime/client/index.d.ts",
34
- "import": "./dist/runtime/client/index.js",
35
- "require": "./dist/runtime/client/index.js"
36
- },
37
- "./shared": {
38
- "types": "./dist/kernel/shared/index.d.ts",
39
- "import": "./dist/kernel/shared/index.js",
40
- "require": "./dist/kernel/shared/index.js"
41
- },
42
- "./utils": {
43
- "types": "./dist/kernel/utils/index.d.ts",
44
- "import": "./dist/kernel/utils/index.js",
45
- "require": "./dist/kernel/utils/index.js"
46
- },
47
- "./package.json": "./package.json"
48
- },
49
- "scripts": {
50
- "build": "tsc -p tsconfig.build.json",
51
- "watch": "tsc -p tsconfig.build.json --watch",
52
- "check": "biome check .",
53
- "check:fix": "biome check --write .",
54
- "check:fix:unsafe": "biome check --write --unsafe",
55
- "format": "biome format --write .",
56
- "lint": "biome lint .",
57
- "lint:fix": "biome lint --write .",
58
- "typecheck": "tsc --noEmit",
59
- "test": "npx vitest run --project unit --project integration --project e2e",
60
- "test:watch": "npx vitest --project unit --project integration --project e2e",
61
- "test:unit": "npx vitest run --project unit",
62
- "test:integration": "npx vitest run --project integration",
63
- "test:coverage": "npx vitest run --coverage",
64
- "bench": "npx tsx benchmark/index.ts",
65
- "bench:core": "npx tsx benchmark/index.ts --core",
66
- "bench:load": "npx vitest run --project benchmark",
67
- "bench:all": "npx tsx benchmark/index.ts --all"
68
- },
69
- "keywords": [
70
- "framework",
71
- "opencore",
72
- "fivem",
73
- "typescript",
74
- "roleplay"
75
- ],
76
- "author": "OpenCore Team",
77
- "license": "MPL-2.0",
78
- "packageManager": "pnpm@10.13.1",
79
- "dependencies": {
80
- "reflect-metadata": "^0.2.2",
81
- "tsyringe": "^4.10.0",
82
- "uuid": "^13.0.0",
83
- "zod": "^4.1.13"
84
- },
85
- "devDependencies": {
86
- "@biomejs/biome": "^2.3.10",
87
- "@citizenfx/client": "2.0.22443-1",
88
- "@citizenfx/server": "2.0.22443-1",
89
- "@types/node": "^24.10.1",
90
- "@vitest/coverage-v8": "^4.0.15",
91
- "eslint-config-prettier": "^10.1.8",
92
- "eslint-plugin-import": "^2.32.0",
93
- "tinybench": "^2.7.0",
94
- "tsx": "^4.19.2",
95
- "typescript": "^5.9.3",
96
- "vitest": "^4.0.15"
97
- }
98
- }
1
+ {
2
+ "name": "@open-core/framework",
3
+ "version": "0.2.4",
4
+ "description": "Secure, Event-Driven, OOP Engine for FiveM. Stop scripting, start engineering.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "commonjs",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/newcore-network/opencore.git"
11
+ },
12
+ "homepage": "https://github.com/newcore-network/opencore",
13
+ "bugs": {
14
+ "url": "https://github.com/newcore-network/opencore/issues"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "require": "./dist/index.js"
26
+ },
27
+ "./server": {
28
+ "types": "./dist/runtime/server/index.d.ts",
29
+ "import": "./dist/runtime/server/index.js",
30
+ "require": "./dist/runtime/server/index.js"
31
+ },
32
+ "./client": {
33
+ "types": "./dist/runtime/client/index.d.ts",
34
+ "import": "./dist/runtime/client/index.js",
35
+ "require": "./dist/runtime/client/index.js"
36
+ },
37
+ "./shared": {
38
+ "types": "./dist/kernel/shared/index.d.ts",
39
+ "import": "./dist/kernel/shared/index.js",
40
+ "require": "./dist/kernel/shared/index.js"
41
+ },
42
+ "./utils": {
43
+ "types": "./dist/kernel/utils/index.d.ts",
44
+ "import": "./dist/kernel/utils/index.js",
45
+ "require": "./dist/kernel/utils/index.js"
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.build.json",
51
+ "watch": "tsc -p tsconfig.build.json --watch",
52
+ "check": "biome check .",
53
+ "check:fix": "biome check --write .",
54
+ "check:fix:unsafe": "biome check --write --unsafe",
55
+ "format": "biome format --write .",
56
+ "lint": "biome lint .",
57
+ "lint:fix": "biome lint --write .",
58
+ "typecheck": "tsc --noEmit",
59
+ "test": "npx vitest run --project unit --project integration --project e2e",
60
+ "test:ci": "npx vitest run --project unit --project integration",
61
+ "test:watch": "npx vitest --project unit --project integration --project e2e",
62
+ "test:unit": "npx vitest run --project unit",
63
+ "test:integration": "npx vitest run --project integration",
64
+ "test:e2e": "npx vitest run --project e2e",
65
+ "test:coverage": "npx vitest run --coverage",
66
+ "bench": "npx tsx benchmark/index.ts",
67
+ "bench:core": "npx tsx benchmark/index.ts --core",
68
+ "bench:load": "npx vitest run --project benchmark",
69
+ "bench:all": "npx tsx benchmark/index.ts --all"
70
+ },
71
+ "keywords": [
72
+ "framework",
73
+ "opencore",
74
+ "fivem",
75
+ "typescript",
76
+ "roleplay"
77
+ ],
78
+ "author": "OpenCore Team",
79
+ "license": "MPL-2.0",
80
+ "packageManager": "pnpm@10.13.1",
81
+ "dependencies": {
82
+ "reflect-metadata": "^0.2.2",
83
+ "tsyringe": "^4.10.0",
84
+ "uuid": "^13.0.0",
85
+ "zod": "^4.1.13"
86
+ },
87
+ "devDependencies": {
88
+ "@biomejs/biome": "^2.3.10",
89
+ "@citizenfx/client": "2.0.22443-1",
90
+ "@citizenfx/server": "2.0.22443-1",
91
+ "@types/node": "^24.10.1",
92
+ "@vitest/coverage-v8": "^4.0.15",
93
+ "eslint-config-prettier": "^10.1.8",
94
+ "eslint-plugin-import": "^2.32.0",
95
+ "tinybench": "^2.7.0",
96
+ "tsx": "^4.19.2",
97
+ "typescript": "^5.9.3",
98
+ "vitest": "^4.0.15"
99
+ }
100
+ }
@@ -1,30 +0,0 @@
1
- /**
2
- * Dependency Injection Tokens for OpenCore.
3
- *
4
- * Using string tokens instead of class references for injection
5
- * avoids issues with circular dependencies and "TypeInfo not known"
6
- * errors in certain build environments.
7
- */
8
- export declare const DI_TOKENS: {
9
- readonly CommandExecutionPort: symbol;
10
- readonly PlayerDirectoryPort: symbol;
11
- readonly PrincipalPort: symbol;
12
- readonly DecoratorProcessor: "DecoratorProcessor";
13
- readonly DatabaseService: symbol;
14
- readonly HttpService: symbol;
15
- readonly ChatService: symbol;
16
- readonly RateLimiterService: symbol;
17
- readonly PrincipalProvider: symbol;
18
- readonly AuthProvider: symbol;
19
- readonly Exports: symbol;
20
- readonly EngineEvents: symbol;
21
- readonly NetTransport: symbol;
22
- readonly Tick: symbol;
23
- readonly PlayerInfo: symbol;
24
- readonly ResourceInfo: symbol;
25
- readonly EntityServer: symbol;
26
- readonly VehicleServer: symbol;
27
- readonly PlayerServer: symbol;
28
- readonly Hasher: symbol;
29
- readonly PedAppearanceServer: symbol;
30
- };
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DI_TOKENS = void 0;
4
- /**
5
- * Dependency Injection Tokens for OpenCore.
6
- *
7
- * Using string tokens instead of class references for injection
8
- * avoids issues with circular dependencies and "TypeInfo not known"
9
- * errors in certain build environments.
10
- */
11
- exports.DI_TOKENS = {
12
- // Ports
13
- CommandExecutionPort: Symbol.for('CommandExecutionPort'),
14
- PlayerDirectoryPort: Symbol.for('PlayerDirectoryPort'),
15
- PrincipalPort: Symbol.for('PrincipalPort'),
16
- // Decorator Processors
17
- DecoratorProcessor: 'DecoratorProcessor',
18
- // Services
19
- DatabaseService: Symbol.for('DatabaseService'),
20
- HttpService: Symbol.for('HttpService'),
21
- ChatService: Symbol.for('ChatService'),
22
- RateLimiterService: Symbol.for('RateLimiterService'),
23
- // Providers
24
- PrincipalProvider: Symbol.for('PrincipalProvider'),
25
- AuthProvider: Symbol.for('AuthProvider'),
26
- // Adapters
27
- Exports: Symbol.for('IExports'),
28
- EngineEvents: Symbol.for('IEngineEvents'),
29
- NetTransport: Symbol.for('INetTransport'),
30
- Tick: Symbol.for('ITick'),
31
- PlayerInfo: Symbol.for('IPlayerInfo'),
32
- ResourceInfo: Symbol.for('IResourceInfo'),
33
- EntityServer: Symbol.for('IEntityServer'),
34
- VehicleServer: Symbol.for('IVehicleServer'),
35
- PlayerServer: Symbol.for('IPlayerServer'),
36
- Hasher: Symbol.for('IHasher'),
37
- PedAppearanceServer: Symbol.for('IPedAppearanceServer'),
38
- };
@@ -1,25 +0,0 @@
1
- export interface PlayerAppearance {
2
- components?: Record<
3
- number,
4
- {
5
- drawable: number
6
- texture: number
7
- }
8
- >
9
- props?: Record<
10
- number,
11
- {
12
- drawable: number
13
- texture: number
14
- }
15
- >
16
- faceFeatures?: Record<number, number>
17
- headBlend?: {
18
- shapeFirst: number
19
- shapeSecond: number
20
- shapeMix: number
21
- skinFirst: number
22
- skinSecond: number
23
- skinMix: number
24
- }
25
- }
@@ -1,2 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
@@ -1,15 +0,0 @@
1
- import { CommandExecutionPort } from '../services/ports/command-execution.port'
2
- import { Player } from '../entities'
3
- /**
4
- * Network controller for command execution.
5
- *
6
- * @remarks
7
- * Receives command execution requests from clients and delegates to CommandExecutionPort.
8
- * In CORE mode, executes commands directly or delegates to owning resource.
9
- * In RESOURCE mode, delegates to CORE via exports.
10
- */
11
- export declare class CommandNetworkController {
12
- private readonly commandService
13
- constructor(commandService: CommandExecutionPort)
14
- onCommandReceived(player: Player, command: string, args: string[]): Promise<void>
15
- }
@@ -1,100 +0,0 @@
1
- 'use strict'
2
- var __decorate =
3
- (this && this.__decorate) ||
4
- function (decorators, target, key, desc) {
5
- var c = arguments.length,
6
- r =
7
- c < 3
8
- ? target
9
- : desc === null
10
- ? (desc = Object.getOwnPropertyDescriptor(target, key))
11
- : desc,
12
- d
13
- if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
14
- r = Reflect.decorate(decorators, target, key, desc)
15
- else
16
- for (var i = decorators.length - 1; i >= 0; i--)
17
- if ((d = decorators[i]))
18
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r
19
- return c > 3 && r && Object.defineProperty(target, key, r), r
20
- }
21
- var __metadata =
22
- (this && this.__metadata) ||
23
- ((k, v) => {
24
- if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function')
25
- return Reflect.metadata(k, v)
26
- })
27
- Object.defineProperty(exports, '__esModule', { value: true })
28
- exports.CommandNetworkController = void 0
29
- const onNet_1 = require('../decorators/onNet')
30
- const command_execution_port_1 = require('../services/ports/command-execution.port')
31
- const entities_1 = require('../entities')
32
- const decorators_1 = require('../decorators')
33
- const logger_1 = require('../../../kernel/shared/logger')
34
- const utils_1 = require('../../../kernel/utils')
35
- /**
36
- * Network controller for command execution.
37
- *
38
- * @remarks
39
- * Receives command execution requests from clients and delegates to CommandExecutionPort.
40
- * In CORE mode, executes commands directly or delegates to owning resource.
41
- * In RESOURCE mode, delegates to CORE via exports.
42
- */
43
- let CommandNetworkController = class CommandNetworkController {
44
- constructor(commandService) {
45
- this.commandService = commandService
46
- }
47
- async onCommandReceived(player, command, args) {
48
- try {
49
- if (command.startsWith('/')) command = command.slice(1)
50
- if (!player.clientID || player.clientID === null || player.clientID === undefined) {
51
- console.log('DEBUG; Player entity not received in core:execute-command')
52
- }
53
- if (args.length > 10 || !/^[a-zA-Z0-9:_-]+$/.test(command)) {
54
- logger_1.loggers.command.warn(`Rejected suspicious command: ${command}`, {
55
- playerId: player.clientID,
56
- playerName: player.name,
57
- })
58
- return
59
- }
60
- logger_1.loggers.command.trace(`Received: /${command}`, {
61
- playerId: player.clientID,
62
- playerName: player.name,
63
- })
64
- await this.commandService.execute(player, command, args)
65
- } catch (error) {
66
- if (error instanceof utils_1.AppError) {
67
- if (error.code === 'GAME:BAD_REQUEST' || error.code === 'COMMAND:NOT_FOUND')
68
- player.send(error.message, 'error')
69
- else player.send('An error occurred while executing the command', 'error')
70
- logger_1.loggers.command.error(
71
- `Execution failed: /${command}`,
72
- {
73
- playerId: player.clientID,
74
- },
75
- error,
76
- )
77
- }
78
- }
79
- }
80
- }
81
- exports.CommandNetworkController = CommandNetworkController
82
- __decorate(
83
- [
84
- (0, decorators_1.Public)(),
85
- (0, onNet_1.OnNet)('core:execute-command'),
86
- __metadata('design:type', Function),
87
- __metadata('design:paramtypes', [entities_1.Player, String, Array]),
88
- __metadata('design:returntype', Promise),
89
- ],
90
- CommandNetworkController.prototype,
91
- 'onCommandReceived',
92
- null,
93
- )
94
- exports.CommandNetworkController = CommandNetworkController = __decorate(
95
- [
96
- (0, decorators_1.Controller)(),
97
- __metadata('design:paramtypes', [command_execution_port_1.CommandExecutionPort]),
98
- ],
99
- CommandNetworkController,
100
- )