diff --git a/apps/game/server/bridge/framework-strategy.ts b/apps/game/server/bridge/framework-strategy.ts index a14b4c132..b22e7995b 100644 --- a/apps/game/server/bridge/framework-strategy.ts +++ b/apps/game/server/bridge/framework-strategy.ts @@ -1,9 +1,12 @@ -import { mainLogger } from '../sv_logger'; import { ESXFramework } from './esx/esx-server'; +import { NDCoreFramework } from './ndcore/ndcore-server'; import { QBCoreFramework } from './qb/qbcore-server'; import { QBXFramework } from './qbx/qbx-server'; import { Standalone } from './standalone/standalone-server'; + +export type Framework = 'qbcore' | 'qbx' | 'esx' | 'standalone' | 'ndcore'; + export interface Strategy { onStart(): void; init(): void; @@ -12,7 +15,7 @@ export interface Strategy { export class FrameworkStrategy { private strategy: Strategy | null; - constructor(strategy: 'qbcore' | 'qbx' | 'esx' | 'standalone') { + constructor(strategy: Framework) { switch (strategy) { case 'qbcore': this.strategy = new QBCoreFramework(); @@ -23,6 +26,9 @@ export class FrameworkStrategy { case 'esx': this.strategy = new ESXFramework(); break; + case 'ndcore': + this.strategy = new NDCoreFramework(); + break; case 'standalone': this.strategy = new Standalone(); break; @@ -41,11 +47,7 @@ export class FrameworkStrategy { } } -const framework = GetConvar('npwd:framework', 'standalone') as - | 'qbcore' - | 'qbx' - | 'esx' - | 'standalone'; +const framework = GetConvar('npwd:framework', 'standalone') as Framework const strategy = new FrameworkStrategy(framework); diff --git a/apps/game/server/bridge/ndcore/ndcore-server.ts b/apps/game/server/bridge/ndcore/ndcore-server.ts new file mode 100644 index 000000000..1a3902eef --- /dev/null +++ b/apps/game/server/bridge/ndcore/ndcore-server.ts @@ -0,0 +1,85 @@ +import { config } from '@npwd/config/server'; +import PlayerService from '../../players/player.service'; +import { mainLogger } from '../../sv_logger'; +import { Strategy } from '../framework-strategy'; + +type NDPlayer = { + id: number; + source: number; + identifier: string; + nickname: string; + user: string; + roles: unknown; + name: string; + firstname: string; + lastname: string; + fullname: string; + dob: string; + gender: string; + phoneNumber: string; + cash: number; + bank: number; + groups: unknown; + job: string; + jobInfo: unknown; + label: string; + rankName: string; + rank: number; + metadata: unknown; + inventory: unknown; +}; + + +// and this phone was supposed to be a 100% standalone my ass +export class NDCoreFramework implements Strategy { + constructor() { + mainLogger.info('Loading NDCore bridge....'); + + config.general.useResourceIntegration = true; + config.database.identifierColumn = 'citizenid'; + config.database.phoneNumberColumn = 'phone_number'; + config.database.playerTable = 'players'; + config.database.identifierType = 'license'; + } + + init(): void { + on('ND:characterLoaded', async (player: NDPlayer) => { + const playerIdent = player.identifier + const phoneNumber = player.phoneNumber ?? "" // TODO: tell andy to add a phone number column in this player table or atleast write a sql query + const playerSrc = player.source; + + await PlayerService.handleNewPlayerEvent({ + identifier: playerIdent, + source: playerSrc, + phoneNumber: phoneNumber.toString(), + firstname: player.firstname, + lastname: player.lastname, + }); + }); + + on("ND:characterUnloaded", async (source: number) => { + await PlayerService.handleUnloadPlayerEvent(source); + }) + + mainLogger.info('NDCore bridge initialized'); + } + + onStart(): void { + on('onServerResourceStart', async (resource: string) => { + const NDCore = global.exports['ND-Core'].GetCoreObject(); + + if (resource === GetCurrentResourceName()) { + const onlinePlayers = NDCore.getPlayers() as NDPlayer[]; + for (const player of onlinePlayers) { + await PlayerService.handleNewPlayerEvent({ + source: player.source, + identifier: player.identifier, + phoneNumber: player.phoneNumber, + firstname: player.firstname, + lastname: player.lastname, + }); + } + } + }); + } +}