Merge branch 'master' into feat/alerts-for-apps

This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-02-28 02:00:34 +01:00
commit 51f9b20857
79 files changed
+1716 -970

No files matched your search

+7 -3
View File
@@ -1,6 +1,6 @@
import events from '../utils/events';
import { ICall } from '../../phone/src/common/typings/call';
import {phoneCallStartAnim, phoneCallEndAnim} from './functions';
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
const exp = (global as any).exports;
@@ -21,6 +21,7 @@ onNet(
app: 'CALL',
method: 'setCaller',
data: {
active: true,
transmitter: transmitter,
receiver: receiver,
isTransmitter: isTransmitter,
@@ -41,12 +42,13 @@ onNet(
events.PHONE_CALL_WAS_ACCEPTED,
(channelId: number, currentCall: ICall, isTransmitter: boolean) => {
exp['mumble-voip'].SetCallChannel(channelId);
phoneCallStartAnim() // Trigger call animation only if the call was accepted.
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
SendNuiMessage(
JSON.stringify({
app: 'CALL',
method: 'setCaller',
data: {
active: true,
transmitter: currentCall.transmitter,
receiver: currentCall.receiver,
isTransmitter: isTransmitter,
@@ -75,13 +77,14 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
receiver: null,
isTransmitter: null,
accepted: false,
active: false,
},
})
);
});
onNet(events.PHONE_CALL_SEND_HANGUP_ANIM, () => {
phoneCallEndAnim()
phoneCallEndAnim();
});
RegisterNuiCallbackType(events.PHONE_END_CALL); // Fires when ending an ACTIVE call
@@ -104,6 +107,7 @@ onNet(events.PHONE_CALL_WAS_ENDED, () => {
receiver: null,
isTransmitter: null,
accepted: false,
active: false,
},
})
);
+36 -62
View File
@@ -1,51 +1,12 @@
import config from '../utils/config';
import events from '../utils/events';
import {phoneCloseAnim, phoneOpenAnim, removePhoneProp} from './functions';
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
let prop = 0;
let isPhoneOpen = false;
let propCreated = false;
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
/* * * * * * * * * * * * *
*
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
async (source: any, args: string[], raw: any) => {
await phoneCloseAnim();
SetNuiFocus(false, false);
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
})
);
},
false
);
RegisterCommand(
'phone',
async () => {
//-- Toggles Phone
await Phone();
},
false
);
RegisterCommand(
'phone:open',
async () => {
await Phone();
},
false
);
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
/* * * * * * * * * * * * *
@@ -66,7 +27,6 @@ const showPhone = async (): Promise<void> => {
data: true,
})
);
sendPhoneConfig();
SetNuiFocus(true, true);
};
@@ -84,13 +44,36 @@ const hidePhone = async (): Promise<void> => {
SetNuiFocus(false, false);
};
const togglePhoneVisible = async (): Promise<void> => {
if (isPhoneOpen) {
/* * * * * * * * * * * * *
*
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
async () => {
await hidePhone();
} else {
},
false
);
RegisterCommand(
'phone',
async () => {
//-- Toggles Phone
await Phone();
},
false
);
RegisterCommand(
'phone:open',
async () => {
await showPhone();
}
};
},
false
);
/* * * * * * * * * * * * *
*
@@ -99,24 +82,17 @@ const togglePhoneVisible = async (): Promise<void> => {
* * * * * * * * * * * * */
async function Phone(): Promise<void> {
fetchOnInitialize()
fetchOnInitialize();
if (config.PhoneAsItem) {
// TODO: Do promise callback here
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
// if (!hasPhoneItem) return
return await togglePhoneVisible();
}
await togglePhoneVisible();
}
function sendPhoneConfig() {
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'phoneConfig',
data: config,
})
);
if (isPhoneOpen) {
await hidePhone();
} else {
await showPhone();
}
}
AddEventHandler('onResourceStop', function (resource: string) {
@@ -144,7 +120,6 @@ onNet('phone:sendCredentials', (number: string) => {
);
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
/* * * * * * * * * * * * *
@@ -157,7 +132,6 @@ function fetchOnInitialize() {
emitNet(events.CONTACTS_GET_CONTACTS);
}
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
emitNet(events.SELLOUT_FETCH_LISTING);
@@ -191,7 +165,7 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
RegisterNuiCallbackType('phone:close');
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
await Phone();
await hidePhone();
cb();
}); // Called for when the phone is closed via the UI.
+1 -1
View File
@@ -1,6 +1,6 @@
-- comment this out if your server has a different table/location for phone_number
-- or if it already exists in the users table
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) NULL DEFAULT NULL;
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL;
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('phone', 'Phone', 1, 0, 1);
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('dphone', 'Destroyed Phone', 1, 0, 1);
+1 -1
View File
@@ -18,7 +18,7 @@ interface ContactId {
}
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
const query = 'SELECT * FROM npwd_phone_contacts WHERE identifier = ?';
const query = 'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC';
const [results] = await pool.query(query, [identifier]);
const contacts = <Contacts[]>results;
return contacts;
+18 -17
View File
@@ -35,26 +35,27 @@ function getRandomPhoneNumber() {
// The numbers inside {} in replace() can be changed to how many digits you want on each side of the dash.
// Example: 123-4567
}
mainLogger.verbose(`Getting random number: ${randomNumber}`);
return randomNumber;
}
async function generatePhoneNumber(identifier: string) {
const _identifier = identifier;
let phoneNumber = await usePhoneNumber(_identifier);
let id = await getIdentifierByPhoneNumber(phoneNumber);
do {
if (!phoneNumber) {
phoneNumber = await getRandomPhoneNumber();
const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?';
await pool.query(query, [phoneNumber, _identifier]);
} else {
break;
}
} while (id);
if (!await usePhoneNumber(identifier)) {
let existingId;
let newNumber;
do {
newNumber = getRandomPhoneNumber();
try {
existingId = await getIdentifierByPhoneNumber(newNumber)
} catch(e) {
existingId = false
}
} while(existingId);
mainLogger.verbose(`Inserting number into Database: ${newNumber}`);
const query = 'UPDATE users SET phone_number = ? WHERE identifier = ?';
await pool.query(query, [newNumber, identifier]);
}
}
async function getCredentials(identifier: string): Promise<string> {
@@ -65,11 +66,11 @@ async function getCredentials(identifier: string): Promise<string> {
return number[0].phone_number;
}
on('playerConnecting', async () => {
onNet('esx:playerLoaded', async (playerId: number, xPlayer: any) => {
const _source = getSource()
try {
const identifier = getIdentifier(_source);
await generatePhoneNumber(identifier)
const identifier = xPlayer.identifier;
await generatePhoneNumber(identifier);
} catch(e) {
mainLogger.error(`Failed to generate a phone number, ${e.message}`, {
source: _source,
+2 -2
View File
@@ -22,8 +22,8 @@ async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
async function deletePhoto(photo: IPhoto, identifier: string) {
const query =
'DELETE FROM npwd_phone_gallery WHERE id = ? AND identifier = ?';
await pool.query(query, [photo.id, identifier]);
'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?';
await pool.query(query, [photo.image, identifier]);
}
onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => {