Merge branch 'master' of github.com:Re-Ignited-Development/new-phone-who-dis into feature/messages

This commit is contained in:
erik-sn committed 2020-11-18 16:50:53 -05:00
commit b87baeb12e
52 files changed
+1214 -210

No files matched your search

+23 -4
View File
@@ -12,7 +12,6 @@ onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => {
})
onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
console.log("Client:", credentials.balance, credentials.name)
SendNuiMessage(
JSON.stringify({
app: "BANK",
@@ -26,8 +25,28 @@ RegisterNuiCallbackType(events.BANK_ADD_TRANSFER);
on(`__cfx_nui:${events.BANK_ADD_TRANSFER}`, (data: any) => {
const transfer = data;
emitNet(events.BANK_ADD_TRANSFER, transfer)
})
setTimeout(() => {
emitNet(events.BANK_FETCH_TRANSACTIONS);
}, 500)
onNet(events.BANK_ADD_TRANSFER_SUCCESS, () => {
emitNet(events.BANK_FETCH_TRANSACTIONS);
})
onNet(events.BANK_TRANSACTION_ALERT, (bool: boolean) => {
SendNuiMessage(
JSON.stringify({
app: 'BANK',
method: 'setAlert',
data: bool
})
)
})
onNet(events.BANK_TRANSACTION_NOTIFICATION, (transfer: any) => {
SendNuiMessage(
JSON.stringify({
app: "BANK",
method: 'setNotification',
data: transfer
})
)
})
+24 -3
View File
@@ -17,8 +17,29 @@ on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
const avatar = data.avatar;
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
setTimeout(() => {
emitNet(events.CONTACTS_GET_CONTACTS)
}, 500)
});
onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS)
})
RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_UPDATE_CONTACT, contact)
})
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS)
})
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
const contact = data;
emitNet(events.CONTACTS_DELETE_CONTACT, contact)
})
onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS)
})
+24 -8
View File
@@ -235,10 +235,6 @@ async function Phone() {
isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials')
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.SELLOUT_FETCH_LISTING);
emitNet(events.BANK_FETCH_TRANSACTIONS);
emitNet(events.BANK_GET_CREDENTIALS);
console.log("Sellout fetched from client side")// Gets the credentials. Will eventually most likely only get the phone number and name, idk.
SetCursorLocation(0.90, 0.922) //Experimental
let res = GetActiveScreenResolution()
@@ -274,10 +270,6 @@ async function Phone() {
isPhoneOpen = true;
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials')
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet(events.SELLOUT_FETCH_LISTING);
emitNet(events.BANK_FETCH_TRANSACTIONS);
emitNet(events.BANK_GET_CREDENTIALS);
console.log("Sellout fetched from client side")
SetCursorLocation(0.936, 0.922) //Experimental
let res = GetActiveScreenResolution()
@@ -306,6 +298,30 @@ async function Phone() {
}
}
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
// contacts app
RegisterNuiCallbackType(events.OPEN_APP_CONTACTS);
on(`__cfx_nui:${events.OPEN_APP_CONTACTS}`, () => {
emitNet(events.CONTACTS_GET_CONTACTS);
})
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, () => {
emitNet(events.SELLOUT_FETCH_LISTING);
})
RegisterNuiCallbackType(events.OPEN_APP_NOTES);
on(`__cfx_nui:${events.OPEN_APP_NOTES}`, () => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
})
RegisterNuiCallbackType(events.OPEN_APP_BANK);
on(`__cfx_nui:${events.OPEN_APP_BANK}`, () => {
emitNet(events.BANK_FETCH_TRANSACTIONS);
emitNet(events.BANK_GET_CREDENTIALS);
})
RegisterCommand(
"phone",
() => {
+39
View File
@@ -0,0 +1,39 @@
import events from "../utils/events";
onNet(events.NOTE_SEND_NOTE, (notes: any) => {
SendNuiMessage(
JSON.stringify({
app: "NOTES",
method: "setNotes",
data: notes,
})
);
});
RegisterNuiCallbackType(events.NOTE_ADD_NOTE);
on(`__cfx_nui:${events.NOTE_ADD_NOTE}`, (data: any) => {
const note = data;
emitNet(events.NOTE_ADD_NOTE, note);
});
onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
RegisterNuiCallbackType(events.NOTE_DELETE_NOTE);
on(`__cfx_nui:${events.NOTE_DELETE_NOTE}`, (data: any) => {
const noteId = data;
emitNet(events.NOTE_DELETE_NOTE, noteId);
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE);
on(`__cfx_nui:${events.NOTE_UPDATE_NOTE}`, (data: any) => {
const note = data;
emitNet(events.NOTE_UPDATE_NOTE, note);
});
onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
emitNet(events.NOTE_FETCH_ALL_NOTES);
});
+1
View File
@@ -4,6 +4,7 @@ import './cl_twitter';
import './cl_contacts';
import './cl_sellout';
import './cl_bank';
import './cl_notes';
export let ESX: ESXClient = null;
+30
View File
@@ -57,6 +57,36 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_likes` (
CONSTRAINT `tweet` FOREIGN KEY (`tweet_id`) REFERENCES `npwd_twitter_tweets` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS npwd_notes (
id int(11) NOT NULL AUTO_INCREMENT,
identifier varchar(255) NOT NULL,
title varchar(255) NOT NULL,
content varchar(255) NOT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 5,
AVG_ROW_LENGTH = 4096,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_general_ci;
CREATE TABLE npwd_sellout_listings (
id int(11) NOT NULL AUTO_INCREMENT,
identifier varchar(255) DEFAULT NULL,
name varchar(50) DEFAULT NULL,
number varchar(255) NOT NULL,
title varchar(255) DEFAULT NULL,
url varchar(255) DEFAULT NULL,
description varchar(255) NOT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 26,
AVG_ROW_LENGTH = 2048,
CHARACTER SET utf8mb4,
COLLATE utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
`id` int NOT NULL AUTO_INCREMENT,
`profile_id` int NOT NULL,
+1
View File
@@ -6,6 +6,7 @@ import './sv_main';
import './sv_contacts';
import './sv_sellout';
import './sv_bank';
import './sv_notes';
export let ESX: ESXServer = null;
+48 -36
View File
@@ -2,18 +2,9 @@ import events from '../utils/events';
import { ESX } from './server';
import { getSource } from "./functions";
import { pool } from './db';
import { resourceLimits } from 'worker_threads';
interface Transfer {
targetID: string;
amount: number;
message: string;
}
interface Credentials {
name: string;
balance: number;
}
import { Transfer, Credentials } from '../../phone/src/common/interfaces/bank';
import { useIdentifier } from './functions';
import { type } from 'os';
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
@@ -33,63 +24,84 @@ function fetchCredentials(): Credentials {
balance
}
console.log(result.name, result.balance);
return result;
}
async function addTransfer(identifier: string, transfer: Transfer): Promise<any> {
const xPlayer = ESX.GetPlayerFromId(getSource())
const bankBalance = xPlayer.getAccount('bank').money;
console.log(bankBalance)
if (transfer.amount > bankBalance) {
console.log("poor man")
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You do not have enough money on your account', 'error')
}
else if (transfer.amount <= bankBalance) {
const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message) VALUES (?, ?, ?, ?)"
const sourceName = xPlayer.getName()
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
await pool.query(query, [
if (transfer.transferAmount > bankBalance) {
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
}
else if (transfer.transferAmount < bankBalance) {
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), true);
xTarget.addAccountMoney('bank', transfer.transferAmount);
xPlayer.removeAccountMoney('bank', transfer.transferAmount);
const query = "INSERT INTO npwd_bank_transfers (identifier, target, amount, message, type, source) VALUES (?, ?, ?, ?, ?, ?)"
const [results] = await pool.query(query, [
identifier,
transfer.targetID,
transfer.amount,
transfer.message
transfer.transferAmount,
transfer.message,
"Transfer",
sourceName,
])
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success')
const insertData = <any>results;
return await getTransfer(insertData.insertId)
}
}
/**
* Gets a transfer from its ID
* @param transferId - transfer id
*/
async function getTransfer(transferId: number): Promise<Transfer> {
const query = "SELECT * FROM npwd_bank_transfers WHERE id = ?"
const [ results ] = await pool.query(query, [transferId]);
const transfers = <Transfer[]>results;
const transfer = transfers[0];
return {...transfer};
}
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
try {
const _source = (global as any).source;
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
const _identifier = await useIdentifier()
const transfer = await fetchAllTransactions(_identifier);
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
console.log("WOORK")
} catch (error) {
console.log('Failed to fetch transactions', error)
console.log("Failed to fetch transactions");
}
})
onNet(events.BANK_ADD_TRANSFER, (transfer: Transfer) => {
onNet(events.BANK_ADD_TRANSFER, async (transfer: Transfer) => {
const xTarget = ESX.GetPlayerFromId(transfer.targetID);
const targetSource = xTarget.source;
try {
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
addTransfer(_identifier, transfer)
const _identifier = await useIdentifier()
const transferNotify = await addTransfer(_identifier, transfer)
emitNet(events.BANK_TRANSACTION_NOTIFICATION, targetSource, transferNotify)
emitNet(events.BANK_ADD_TRANSFER_SUCCESS, getSource());
} catch (error) {
console.log('Failed to add transfer', error)
emitNet(events.BANK_TRANSACTION_ALERT, getSource(), false)
}
})
onNet(events.BANK_GET_CREDENTIALS, () => {
try {
const credentials = fetchCredentials()
console.log("New log: ", credentials.balance, credentials.name)
emitNet(events.BANK_SEND_CREDENTIALS, getSource(), credentials)
} catch (error) {
console.log(error)
console.log("Failed to fetch credentials");
}
})
+52 -5
View File
@@ -1,12 +1,20 @@
import { ESX } from "./server";
import { ESX, getSource } from "./server";
import { pool } from "./db";
import events from "../utils/events";
import { useIdentifier } from './functions'
interface Contacts {
id?: number;
display: string;
number: string;
avatar: string;
}
interface ContactId {
id: number;
}
async function fetchAllContacts(identifier: string): Promise<Contacts[]> {
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
const [results] = await pool.query(query, [identifier]);
@@ -26,6 +34,25 @@ async function addContact(
await pool.query(query, [identifier, number, display, avatar]);
}
async function updateContact(contact: Contacts, identifier: string): Promise<any> {
const query = "UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?"
await pool.query(query, [
contact.number,
contact.display,
contact.avatar,
contact.id,
identifier
])
}
async function deleteContact(contact: ContactId, identifier: string): Promise<any> {
const query = "DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?"
await pool.query(query, [
contact.id,
identifier
])
}
onNet(events.CONTACTS_GET_CONTACTS, async () => {
try {
const _source = (global as any).source;
@@ -39,16 +66,36 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
}
})
onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avatar: string) => {
try {
const _source = (global as any).source;
const xPlayer = ESX.GetPlayerFromId(_source);
const _identifier = xPlayer.getIdentifier()
const _identifier = await useIdentifier()
addContact(_identifier, number, display, avatar);
//emit(events.CONTACTS_GET_CONTACTS);
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source)
} catch(error) {
console.log("Failed to add contact: ", error);
}
});
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
try {
const _source = (global as any)._source
const _identifier = await useIdentifier()
updateContact(contact, _identifier)
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source)
} catch (error) {
console.log(error)
}
})
onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
try {
const _identifier = await useIdentifier()
deleteContact(contact, _identifier)
emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource())
} catch (error) {
console.log("DELETE CONTACT ERROR", error)
}
})
+72
View File
@@ -0,0 +1,72 @@
import events from "../utils/events";
import { ESX, getSource } from "./server";
import { pool } from "./db";
import { useIdentifier } from "./functions";
import { Note, NoteId } from "../../phone/src/common/interfaces/notes";
async function addNote(identifier: string, note: Note): Promise<any> {
const query =
"INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)";
await pool.query(query, [identifier, note.title, note.content]);
}
async function fetchAllNotes(identifier: string): Promise<Note[]> {
const query =
"SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC";
const [result] = await pool.query(query, [identifier]);
const notes = <Note[]>result;
return notes;
}
async function deleteNote(noteId: number, identifier: string) {
const query = "DELETE FROM npwd_notes WHERE id = ? AND identifier = ?";
await pool.query(query, [noteId, identifier]);
}
async function updateNote(note: Note, identifier: string): Promise<any> {
const query =
"UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?";
await pool.query(query, [note.title, note.content, note.id, identifier]);
}
onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
try {
const _identifier = await useIdentifier();
addNote(_identifier, note);
emitNet(events.NOTE_SEND_NOTE_SUCCESS, getSource());
} catch (error) {
console.log("NOTES ERROR: ", error);
}
});
onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
try {
const _source = (global as any).source;
const _identifier = await useIdentifier();
const notes = await fetchAllNotes(_identifier);
emitNet(events.NOTE_SEND_NOTE, _source, notes);
} catch (error) {
console.log("NOTE ERROR: ", error);
}
});
onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
try {
const _identifier = await useIdentifier();
const id = noteId.id;
await deleteNote(id, _identifier);
} catch (error) {
console.log("NOTE ERROR:", error);
}
});
onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
const _source = (global as any).source;
try {
const _identifier = await useIdentifier();
updateNote(note, _identifier);
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source);
} catch (error) {
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source);
}
});
+26 -2
View File
@@ -32,7 +32,11 @@ export default {
CONTACTS_GET_CONTACTS: 'phone:getContacts',
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
CONTACTS_ADD_CONTACT: 'contacts:add',
CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts',
CONTACTS_ADD_CONTACT_SUCCESS: 'contacts:addSuccess',
CONTACTS_UPDATE_CONTACT: 'phone:updateContact',
CONTACTS_DELETE_CONTACT: 'phone:deleteContact',
CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess',
CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess',
// Sellout
SELLOUT_ADD_LISTING: 'phone:addListing',
@@ -41,12 +45,32 @@ export default {
//
BANK_ADD_TRANSFER: 'phone:addTransfer',
BANK_ADD_TRANSFER_SUCCESS: 'phone:addTransferSuccess',
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
BANK_SEND_TRANSFERS: 'phone:sendTransfers',
BANK_TRANSACTION_ALERT: 'phone:transactionAlert',
BANK_TRANSACTION_ALERT: 'phone:bankTransactionAlert',
BANK_TRANSACTION_NOTIFICATION: 'phone:bankTransactionNotification',
BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials',
BANK_GET_CREDENTIALS: 'phone:getBankCredentials',
//messages
MESSAGES_SEND_MESSAGE: 'phone:sendMessage',
MESSAGES_GET_MESSAGES: 'phone:getMessage',
// Notes
NOTE_ADD_NOTE: 'phone:addNote',
NOTE_FETCH_ALL_NOTES: 'phone:fetchAllNotes',
NOTE_SEND_NOTE: 'phone:sendNote',
NOTE_SEND_NOTE_SUCCESS: 'phone:sendNoteSuccess',
NOTE_DELETE_NOTE: 'phone:deleteNote',
NOTE_UPDATE_NOTE: 'phone:updateNote',
NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
// DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
OPEN_APP_BANK: 'phone:app:BANK',
OPEN_APP_NOTES: 'phone:app:NOTES',
OPEN_APP_LISTINGS: 'phone:app:SELLOUT'
}