Skip to content

Commit

Permalink
feat(game/server): ndcore support
Browse files Browse the repository at this point in the history
this is an attempt at supporting ndcore
  • Loading branch information
itschip committed Jan 7, 2024
1 parent dcc8e2f commit 5ca9014
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 7 deletions.
16 changes: 9 additions & 7 deletions apps/game/server/bridge/framework-strategy.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);

Expand Down
85 changes: 85 additions & 0 deletions apps/game/server/bridge/ndcore/ndcore-server.ts
Original file line number Diff line number Diff line change
@@ -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();

This comment has been minimized.

Copy link
@marshular

marshular Jan 7, 2024

GetCoreObject no longer works, heres how to do it: https://ndcore.dev/core#importing-ndcore

Another way of doing it using ox_lib to load it like: overextended/ox_doorlock@a11ccf1


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,
});
}
}
});
}
}

0 comments on commit 5ca9014

Please sign in to comment.