feat(config): configure an export to be called at toggle to control phone access

Can serve as a primitive form of access control that can for example call a client side inventory check
This commit is contained in:
Taso committed 2021-07-27 23:06:13 -04:00
1 parent b00bee0217
commit fc939885a8
3 files changed
+31 -12

No files matched your search

+5 -1
View File
@@ -2,7 +2,11 @@
"Locale": "en",
"KeyTogglePhone": 288,
"KeyTakeCall": 38,
"PhoneAsItem": false,
"PhoneAsItem": {
"enabled": false,
"exportResource": "my-core-resource",
"exportName": "myCheckerFunction"
},
"SwimDestroy": false,
"RunRate": 10,
"DestroyChance": 100,
+19 -10
View File
@@ -7,8 +7,12 @@ import { PhotoEvents } from '../../typings/photo';
import { CallEvents } from '../../typings/call';
import { config } from './client';
import { animationService } from './animations/animation.controller';
import { RegisterNuiCB } from './cl_utils';
let isPhoneOpen = false;
const exps = global.exports;
/* * * * * * * * * * * * *
*
* Phone initialize data
@@ -75,7 +79,7 @@ RegisterCommand(
'phone',
async () => {
//-- Toggles Phone
await Phone();
await togglePhone();
},
false,
);
@@ -96,17 +100,22 @@ RegisterCommand(
*
* * * * * * * * * * * * */
async function Phone(): Promise<void> {
if (config.PhoneAsItem) {
// TODO: Do promise callback here
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
// if (!hasPhoneItem) return
const checkExportCanOpen = (): boolean => {
const exportResp = exps[config.PhoneAsItem.exportResource][config.PhoneAsItem.exportFunction]();
if (typeof exportResp !== 'number' && typeof exportResp !== 'boolean') {
throw new Error('You must return either a boolean or number from your export function');
}
if (isPhoneOpen) {
await hidePhone();
} else {
await showPhone();
return !!exportResp;
};
async function togglePhone(): Promise<void> {
if (config.PhoneAsItem.enabled) {
const canAccess = checkExportCanOpen();
if (!canAccess) return;
}
if (isPhoneOpen) return await hidePhone();
await showPhone();
}
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
+7 -1
View File
@@ -43,12 +43,18 @@ interface DatabaseConfig {
useIdentifierPrefix: boolean;
}
interface PhoneAsItemConfig {
enabled: boolean;
exportResource: string;
exportFunction: string;
}
export interface ResourceConfig {
database: DatabaseConfig;
Locale: string;
KeyTogglePhone: number;
KeyTakeCall: number;
PhoneAsItem: boolean;
PhoneAsItem: PhoneAsItemConfig;
SwimDestroy: boolean;
RunRate: number;
twitter: TwitterConfig;