mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
feat(resources): remove all esx code, almost
This commit is contained in:
1 parent
6b6080c4b2
commit
c99d0780ae
12 files changed
+121
-84
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { IPlayer } from '../typings/players';
|
||||
import { pool } from './db';
|
||||
import { ESX } from './server';
|
||||
import { XPlayer } from 'esx.js/@types/server';
|
||||
import { Players } from './sv_main';
|
||||
|
||||
interface IPhoneNumber {
|
||||
phone_number: string;
|
||||
@@ -10,11 +10,27 @@ interface Identifier {
|
||||
identifier: string;
|
||||
}
|
||||
|
||||
export async function usePhoneNumber(identifier: string): Promise<string> {
|
||||
const query = 'SELECT phone_number FROM users WHERE identifier = ?';
|
||||
export async function usePlayer(
|
||||
identifier: string,
|
||||
): Promise<Pick<IPlayer, 'name' | 'phone_number'>> {
|
||||
const query = `SELECT firstname, lastname, phone_number FROM users WHERE identifier = ?`;
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
const phoneNumber = <IPhoneNumber[]>results;
|
||||
return phoneNumber[0].phone_number;
|
||||
const creds = <{ firstname: string; lastname: string; phone_number: string }[]>results;
|
||||
|
||||
const name = `${creds[0].firstname} ${creds[0].lastname}`;
|
||||
const phone_number = creds[0].phone_number;
|
||||
|
||||
return { name, phone_number };
|
||||
}
|
||||
|
||||
export function usePhoneNumber(identifier: string) {
|
||||
const player = getPlayerFromIdentifier(identifier);
|
||||
return player?.phone_number || null;
|
||||
}
|
||||
|
||||
export function useName(identifer: string) {
|
||||
const player = getPlayerFromIdentifier(identifer);
|
||||
return player?.name || null;
|
||||
}
|
||||
|
||||
export const getSource = () => (global as any).source;
|
||||
@@ -22,7 +38,8 @@ export const getSource = () => (global as any).source;
|
||||
// we might need to run a db query on this.
|
||||
// to make it more standalone
|
||||
export function getIdentifier(source: number): string {
|
||||
return ESX.GetPlayerFromId(source).getIdentifier();
|
||||
const player = getPlayerBySource(source);
|
||||
return player?.identifier || null;
|
||||
}
|
||||
|
||||
export async function getIdentifierByPhoneNumber(phoneNumber: string): Promise<string> {
|
||||
@@ -32,26 +49,19 @@ export async function getIdentifierByPhoneNumber(phoneNumber: string): Promise<s
|
||||
return identifier[0].identifier;
|
||||
}
|
||||
|
||||
export const getPlayerBySource = (source: any) => {
|
||||
return Players.get(source);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the player phoneNumber for a passed identifier
|
||||
* @param identifier The players phone number
|
||||
*/
|
||||
export async function getPlayerFromIdentifier(
|
||||
identifier: string
|
||||
): Promise<XPlayer> {
|
||||
return new Promise((res, rej) => {
|
||||
const xPlayers = ESX.GetPlayers();
|
||||
|
||||
for (const player of xPlayers) {
|
||||
const xPlayer = ESX.GetPlayerFromId(player);
|
||||
if (
|
||||
xPlayer.getIdentifier() != null &&
|
||||
xPlayer.getIdentifier() == identifier
|
||||
) {
|
||||
res(xPlayer);
|
||||
}
|
||||
export function getPlayerFromIdentifier(identifier: string) {
|
||||
for (const player of Array.from(Players.entries())) {
|
||||
if (player[1].identifier === identifier) {
|
||||
return player[1];
|
||||
}
|
||||
|
||||
rej(new Error('Call Target Identifier was not found in xPlayers array'));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user