@open-core/framework 0.2.2-beta.1 → 0.2.5

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 (56) 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/internal-event.bus.d.ts +6 -0
  11. package/dist/runtime/server/bus/{core-event-bus.js → internal-event.bus.js} +5 -2
  12. package/dist/runtime/server/controllers/principal-export.controller.js +1 -1
  13. package/dist/runtime/server/controllers/session.controller.js +4 -4
  14. package/dist/runtime/server/decorators/onFrameworkEvent.d.ts +15 -6
  15. package/dist/runtime/server/decorators/onFrameworkEvent.js +9 -6
  16. package/dist/runtime/server/decorators/throttle.js +3 -1
  17. package/dist/runtime/server/entities/player.d.ts +6 -0
  18. package/dist/runtime/server/entities/player.js +12 -0
  19. package/dist/runtime/server/helpers/command-validation.helper.d.ts +1 -1
  20. package/dist/runtime/server/helpers/function-helper.d.ts +1 -1
  21. package/dist/runtime/server/index.d.ts +2 -1
  22. package/dist/runtime/server/index.js +3 -1
  23. package/dist/runtime/server/services/core/command.service.d.ts +1 -1
  24. package/dist/runtime/server/services/core/player.service.d.ts +0 -11
  25. package/dist/runtime/server/services/core/player.service.js +0 -15
  26. package/dist/runtime/server/services/parallel/worker-pool.js +4 -0
  27. package/dist/runtime/server/services/ports/command-execution.port.d.ts +1 -1
  28. package/dist/runtime/server/services/ports/player-session-lifecycle.port.d.ts +0 -12
  29. package/dist/runtime/server/services/remote/remote-command.service.d.ts +1 -1
  30. package/dist/runtime/server/services/services.register.js +2 -2
  31. package/dist/runtime/server/system/metadata-server.keys.d.ts +1 -1
  32. package/dist/runtime/server/system/metadata-server.keys.js +10 -10
  33. package/dist/runtime/server/system/processors/{coreEvent.processor.d.ts → internalEvent.processor.d.ts} +1 -1
  34. package/dist/runtime/server/system/processors/{coreEvent.processor.js → internalEvent.processor.js} +10 -10
  35. package/dist/runtime/server/system/processors.register.js +2 -2
  36. package/dist/runtime/server/types/index.d.ts +1 -1
  37. package/dist/runtime/server/types/index.js +1 -1
  38. package/dist/runtime/server/types/internal-events.d.ts +19 -0
  39. package/package.json +100 -99
  40. package/dist/kernel/di/tokens.d.ts +0 -30
  41. package/dist/kernel/di/tokens.js +0 -38
  42. package/dist/runtime/client/interfaces/appearance.interface.d.ts +0 -25
  43. package/dist/runtime/client/interfaces/appearance.interface.js +0 -2
  44. package/dist/runtime/server/bus/core-event-bus.d.ts +0 -6
  45. package/dist/runtime/server/controllers/command.controller.d.ts +0 -15
  46. package/dist/runtime/server/controllers/command.controller.js +0 -100
  47. package/dist/runtime/server/services/access-control.service.d.ts +0 -59
  48. package/dist/runtime/server/services/access-control.service.js +0 -127
  49. package/dist/runtime/server/services/core/vehicle-modification.service.d.ts +0 -104
  50. package/dist/runtime/server/services/core/vehicle-modification.service.js +0 -330
  51. package/dist/runtime/server/services/core/vehicle.service.d.ts +0 -128
  52. package/dist/runtime/server/services/core/vehicle.service.js +0 -391
  53. package/dist/runtime/server/services/remote/remote-principal.provider.d.ts +0 -55
  54. package/dist/runtime/server/services/remote/remote-principal.provider.js +0 -130
  55. package/dist/runtime/server/types/core-events.d.ts +0 -22
  56. /package/dist/runtime/server/types/{core-events.js → internal-events.js} +0 -0
@@ -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,6 +0,0 @@
1
- import { CoreEventMap } from '../types/core-events';
2
- type CoreEventName = keyof CoreEventMap;
3
- type CoreEventHandler<E extends CoreEventName> = (payload: CoreEventMap[E]) => void;
4
- export declare function onFrameworkEvent<E extends CoreEventName>(event: E, handler: CoreEventHandler<E>): () => void;
5
- export declare function emitFrameworkEvent<E extends CoreEventName>(event: E, payload: CoreEventMap[E]): void;
6
- export {};
@@ -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
- )
@@ -1,59 +0,0 @@
1
- import { Server } from '../../..'
2
- import { PrincipalProviderContract } from '../contracts'
3
- /**
4
- * **Core Security Service**
5
- *
6
- * This service acts as the central enforcement point for the Access Control system.
7
- * It uses the configured `PrincipalProvider` to query roles and validates them against requirements.
8
- *
9
- * It is primarily used internally by the `@Guard` decorator, but can be injected
10
- * into services to perform manual checks.
11
- */
12
- export declare class AccessControlService {
13
- private readonly principalProvider
14
- constructor(principalProvider: PrincipalProviderContract)
15
- /**
16
- * Verifies if a player meets a minimum numeric rank requirement.
17
- *
18
- * @param player - The target player.
19
- * @param minRank - The minimum numeric value required (Inclusive).
20
- *
21
- * @returns `true` if `Principal.rank >= minRank`.
22
- *
23
- * @throws {AppError} code `UNAUTHORIZED` if the player has no Principal (not logged in).
24
- * @throws {AppError} code `NO_RANK_IN_PRINCIPAL` if the Principal exists but has no `rank` defined.
25
- */
26
- hasRank(player: Server.Player, minRank: number): Promise<boolean>
27
- /**
28
- * Verifies if a player possesses a specific permission string.
29
- *
30
- * @remarks
31
- * This method supports the **Wildcard ('*')** permission. If the principal has `'*'`
32
- * in their permissions array, this method always returns `true`.
33
- *
34
- * @param player - The target player.
35
- * @param permission - The specific permission key (e.g., `'admin.ban'`).
36
- * @returns `true` if the player has the permission or the wildcard.
37
- */
38
- hasPermission(player: Server.Player, permission: string): Promise<boolean>
39
- /**
40
- * **Strict Enforcement**
41
- *
42
- * Validates a set of requirements against a player. If any requirement fails,
43
- * it throws an exception, halting the execution flow.
44
- *
45
- * Used primarily by the `@Guard` decorator logic.
46
- *
47
- * @param player - The server player to validate.
48
- * @param requirements - An object containing rank and/or permission constraints.
49
- *
50
- * @throws {AppError} code `PERMISSION_DENIED` if validation fails.
51
- */
52
- enforce(
53
- player: Server.Player,
54
- requirements: {
55
- minRank?: number
56
- permission?: string
57
- },
58
- ): Promise<void>
59
- }
@@ -1,127 +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.AccessControlService = void 0
29
- const tsyringe_1 = require('tsyringe')
30
- const utils_1 = require('../../../kernel/utils')
31
- const contracts_1 = require('../contracts')
32
- /**
33
- * **Core Security Service**
34
- *
35
- * This service acts as the central enforcement point for the Access Control system.
36
- * It uses the configured `PrincipalProvider` to query roles and validates them against requirements.
37
- *
38
- * It is primarily used internally by the `@Guard` decorator, but can be injected
39
- * into services to perform manual checks.
40
- */
41
- let AccessControlService = class AccessControlService {
42
- constructor(principalProvider) {
43
- this.principalProvider = principalProvider
44
- }
45
- /**
46
- * Verifies if a player meets a minimum numeric rank requirement.
47
- *
48
- * @param player - The target player.
49
- * @param minRank - The minimum numeric value required (Inclusive).
50
- *
51
- * @returns `true` if `Principal.rank >= minRank`.
52
- *
53
- * @throws {AppError} code `UNAUTHORIZED` if the player has no Principal (not logged in).
54
- * @throws {AppError} code `NO_RANK_IN_PRINCIPAL` if the Principal exists but has no `rank` defined.
55
- */
56
- async hasRank(player, minRank) {
57
- const principal = await this.principalProvider.getPrincipal(player)
58
- if (!principal) throw new utils_1.AppError('AUTH:UNAUTHORIZED', 'No principal found', 'core')
59
- if (principal.rank === undefined)
60
- throw new utils_1.AppError(
61
- 'GAME:NO_RANK_IN_PRINCIPAL',
62
- "You're trying to compare a Principal rank, but there's no defined rank! ",
63
- 'core',
64
- )
65
- return principal.rank >= minRank
66
- }
67
- /**
68
- * Verifies if a player possesses a specific permission string.
69
- *
70
- * @remarks
71
- * This method supports the **Wildcard ('*')** permission. If the principal has `'*'`
72
- * in their permissions array, this method always returns `true`.
73
- *
74
- * @param player - The target player.
75
- * @param permission - The specific permission key (e.g., `'admin.ban'`).
76
- * @returns `true` if the player has the permission or the wildcard.
77
- */
78
- async hasPermission(player, permission) {
79
- const principal = await this.principalProvider.getPrincipal(player)
80
- if (!principal) return false
81
- if (principal.permissions.includes('*')) return true
82
- return principal.permissions.includes(permission)
83
- }
84
- /**
85
- * **Strict Enforcement**
86
- *
87
- * Validates a set of requirements against a player. If any requirement fails,
88
- * it throws an exception, halting the execution flow.
89
- *
90
- * Used primarily by the `@Guard` decorator logic.
91
- *
92
- * @param player - The server player to validate.
93
- * @param requirements - An object containing rank and/or permission constraints.
94
- *
95
- * @throws {AppError} code `PERMISSION_DENIED` if validation fails.
96
- */
97
- async enforce(player, requirements) {
98
- if (requirements.minRank !== undefined) {
99
- const hasRank = await this.hasRank(player, requirements.minRank)
100
- if (!hasRank) {
101
- throw new utils_1.AppError(
102
- 'AUTH:PERMISSION_DENIED',
103
- `Access Denied: Requires minimum rank level ${requirements.minRank}`,
104
- 'core',
105
- )
106
- }
107
- }
108
- if (requirements.permission) {
109
- const hasPerm = await this.hasPermission(player, requirements.permission)
110
- if (!hasPerm) {
111
- throw new utils_1.AppError(
112
- 'AUTH:PERMISSION_DENIED',
113
- `Access Denied: Missing required permission '${requirements.permission}'`,
114
- 'core',
115
- )
116
- }
117
- }
118
- }
119
- }
120
- exports.AccessControlService = AccessControlService
121
- exports.AccessControlService = AccessControlService = __decorate(
122
- [
123
- (0, tsyringe_1.injectable)(),
124
- __metadata('design:paramtypes', [contracts_1.PrincipalProviderContract]),
125
- ],
126
- AccessControlService,
127
- )
@@ -1,104 +0,0 @@
1
- import { VehicleService } from './vehicle.service'
2
- import type { VehicleModificationOptions, VehicleMods } from '../../types/vehicle.types'
3
- /**
4
- * Service for handling vehicle modifications with validation.
5
- *
6
- * This service is separated from VehicleService to maintain single responsibility.
7
- * All modifications are validated server-side before being applied.
8
- *
9
- * Security features:
10
- * - Ownership validation
11
- * - Proximity checks
12
- * - Modification limits
13
- * - Audit logging
14
- */
15
- export declare class VehicleModificationService {
16
- private readonly vehicleService
17
- constructor(vehicleService: VehicleService)
18
- /**
19
- * Applies modifications to a vehicle with validation.
20
- *
21
- * @param options - Modification options
22
- * @returns Success status
23
- */
24
- applyModifications(options: VehicleModificationOptions): boolean
25
- /**
26
- * Sets vehicle colors with validation.
27
- *
28
- * @param networkId - Network ID of the vehicle
29
- * @param primaryColor - Primary color ID
30
- * @param secondaryColor - Secondary color ID
31
- * @param requestedBy - Client ID requesting the change
32
- * @returns Success status
33
- */
34
- setColors(
35
- networkId: number,
36
- primaryColor: number,
37
- secondaryColor: number,
38
- requestedBy?: number,
39
- ): boolean
40
- /**
41
- * Sets vehicle livery with validation.
42
- *
43
- * @param networkId - Network ID of the vehicle
44
- * @param livery - Livery index
45
- * @param requestedBy - Client ID requesting the change
46
- * @returns Success status
47
- */
48
- setLivery(networkId: number, livery: number, requestedBy?: number): boolean
49
- /**
50
- * Toggles vehicle turbo with validation.
51
- *
52
- * @param networkId - Network ID of the vehicle
53
- * @param enabled - Whether turbo should be enabled
54
- * @param requestedBy - Client ID requesting the change
55
- * @returns Success status
56
- */
57
- setTurbo(networkId: number, enabled: boolean, requestedBy?: number): boolean
58
- /**
59
- * Sets vehicle window tint with validation.
60
- *
61
- * @param networkId - Network ID of the vehicle
62
- * @param tint - Tint level (0-6)
63
- * @param requestedBy - Client ID requesting the change
64
- * @returns Success status
65
- */
66
- setWindowTint(networkId: number, tint: number, requestedBy?: number): boolean
67
- /**
68
- * Sets vehicle neon lights with validation.
69
- *
70
- * @param networkId - Network ID of the vehicle
71
- * @param enabled - Array of [left, right, front, back] enabled states
72
- * @param color - RGB color array
73
- * @param requestedBy - Client ID requesting the change
74
- * @returns Success status
75
- */
76
- setNeon(
77
- networkId: number,
78
- enabled: [boolean, boolean, boolean, boolean],
79
- color?: [number, number, number],
80
- requestedBy?: number,
81
- ): boolean
82
- /**
83
- * Resets all modifications on a vehicle.
84
- *
85
- * @param networkId - Network ID of the vehicle
86
- * @param requestedBy - Client ID requesting the reset
87
- * @returns Success status
88
- */
89
- resetModifications(networkId: number, requestedBy?: number): boolean
90
- /**
91
- * Gets the current modifications of a vehicle.
92
- *
93
- * @param networkId - Network ID of the vehicle
94
- * @returns Vehicle mods or undefined
95
- */
96
- getModifications(networkId: number): VehicleMods | undefined
97
- /**
98
- * Validates modification values to prevent exploits.
99
- *
100
- * @param mods - Modifications to validate
101
- * @returns Validated modifications
102
- */
103
- private validateMods
104
- }