Skip to content

Commit

Permalink
feat(game/calls): export for checking busy players
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Sep 30, 2023
1 parent f0dc76e commit b8971b3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions apps/game/server/bridge/sv_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { playerLogger } from '../players/player.utils';
import PlayerService from '../players/player.service';
import { PhoneEvents } from '@typings/phone';
import { Player } from '../players/player.class';
import callsService from '../calls/calls.service';

const exp = global.exports;

Expand Down Expand Up @@ -87,3 +88,12 @@ exp('getPlayerData', async (locator: PlayerDataExportArgs): Promise<ExportedPlay
source: player.source,
};
});

exp('isPlayerBusy', (src: number): boolean => {
return PlayerService.isBusy(src);
});


exp("isPhoneNumberBusy", (phoneNumber: string) => {
return callsService.isPhoneNumberInCall(phoneNumber);
})
16 changes: 15 additions & 1 deletion apps/game/server/calls/calls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { emitNetTyped } from '../utils/miscUtils';
import { mainLogger } from '../sv_logger';

class CallsService {
private callMap: Collection<string, ActiveCallRaw>;
public callMap: Collection<string, ActiveCallRaw>;
private readonly callsDB: _CallsRepo;

constructor() {
Expand All @@ -31,6 +31,20 @@ class CallsService {
callLogger.debug(callObj);
}

isPlayerInCall(source: number): boolean {
const phoneNunber = PlayerService.getPlayer(source).getPhoneNumber();

return this.isPhoneNumberInCall(phoneNunber);
}

isPhoneNumberInCall(phoneNumber: string): boolean {
const calls = this.callMap.find((call) => {
return call.transmitter === phoneNumber || call.receiver === phoneNumber;
});

return !!calls;
}

async handleInitializeCall(
reqObj: PromiseRequest<InitializeCallDTO>,
resp: PromiseEventResp<ActiveCall>,
Expand Down
2 changes: 1 addition & 1 deletion apps/game/server/calls/middleware/onCall.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OnCallExportCtx } from '../../../../typings/call';
import { OnCallExportCtx } from '@typings/call';

const exp = global.exports;

Expand Down
7 changes: 7 additions & 0 deletions apps/game/server/players/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Collection from '@discordjs/collection';
import { getPlayerGameLicense } from '../utils/getPlayerGameLicense';
import { playerLogger } from './player.utils';
import MarketplaceService from '../marketplace/marketplace.service';
import CallsService from '../calls/calls.service';
import { Delay } from '../../utils/fivem';
import { config } from '../config';
import { _PlayerRepo, PlayerRepo } from '@npwd/database';
Expand All @@ -14,11 +15,13 @@ class _PlayerService {
private readonly playersBySource: Collection<number, Player>;
private readonly playersByIdentifier: Collection<string, Player>;
private readonly playerDB: _PlayerRepo;
private readonly callService: typeof CallsService;

constructor() {
this.playersBySource = new Collection<number, Player>();
this.playersByIdentifier = new Collection<string, Player>();
this.playerDB = PlayerRepo;
this.callService = CallsService;
playerLogger.debug('Player Service started');
}

Expand Down Expand Up @@ -73,6 +76,10 @@ class _PlayerService {
return player;
}

isBusy(source: number): boolean {
return this.callService.isPlayerInCall(source);
}

/**
* Will return the given identifier from a phone number
* @param phoneNumber - The phone number of the player
Expand Down

0 comments on commit b8971b3

Please sign in to comment.