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

This commit is contained in:
erik-sn committed 2020-10-28 17:06:16 -04:00
commit 8c1f823bcb
30 files changed
+873 -52

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import events from '../utils/events';
onNet(events.BANK_SEND_TRANSFERS, (transfer: any) => {
SendNuiMessage(
JSON.stringify({
app: "BANK",
method: "setTransaction",
data: transfer
})
)
})
onNet(events.BANK_SEND_CREDENTIALS, (credentials: any) => {
console.log("Client:", credentials.balance, credentials.name)
SendNuiMessage(
JSON.stringify({
app: "BANK",
method: "setCredentials",
data: credentials
})
)
})
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)
})
+4
View File
@@ -237,6 +237,8 @@ async function Phone() {
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,6 +276,8 @@ async function Phone() {
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()
+1
View File
@@ -3,6 +3,7 @@ import './cl_main';
import './cl_twitter';
import './cl_contacts';
import './cl_sellout';
import './cl_bank';
export let ESX: ESXClient = null;
+1
View File
@@ -5,6 +5,7 @@ import './sv_twitter';
import './sv_main';
import './sv_contacts';
import './sv_sellout';
import './sv_bank';
export let ESX: ESXServer = null;
+94
View File
@@ -0,0 +1,94 @@
import events from '../utils/events';
import { ESX, getSource } from './server';
import { pool } from './db';
import { resourceLimits } from 'worker_threads';
interface Transfer {
targetID: string;
amount: number;
message: string;
}
interface Credentials {
name: string;
balance: number;
}
async function fetchAllTransactions(identifier: string): Promise<Transfer[]> {
const query = "SELECT * FROM npwd_bank_transfers WHERE identifier = ? ORDER BY id DESC"
const [ results ] = await pool.query(query, [identifier])
const transactions = <Transfer[]>results;
return transactions;
}
function fetchCredentials(): Credentials {
const name = ESX.GetPlayerFromId(getSource()).getName();
const balance = ESX.GetPlayerFromId(getSource()).getAccount('bank').money
const result = {
name,
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 (?, ?, ?, ?)"
await pool.query(query, [
identifier,
transfer.targetID,
transfer.amount,
transfer.message
])
emitNet(events.BANK_TRANSACTION_ALERT, getSource, 'You succesfully transferred money to someone', 'success')
}
}
onNet(events.BANK_FETCH_TRANSACTIONS, async () => {
try {
const _source = (global as any).source;
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
const transfer = await fetchAllTransactions(_identifier);
emitNet(events.BANK_SEND_TRANSFERS, _source, transfer)
console.log("WOORK")
} catch (error) {
console.log('Failed to fetch transactions', error)
}
})
onNet(events.BANK_ADD_TRANSFER, (transfer: Transfer) => {
try {
const _identifier = ESX.GetPlayerFromId(getSource()).getIdentifier()
addTransfer(_identifier, transfer)
} catch (error) {
console.log('Failed to add transfer', error)
}
})
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)
}
})
+9 -1
View File
@@ -34,5 +34,13 @@ export default {
// Sellout
SELLOUT_ADD_LISTING: 'phone:addListing',
SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
SELLOUT_SEND_LISTING: 'phone:sendAllListings'
SELLOUT_SEND_LISTING: 'phone:sendAllListings',
// Bank
BANK_ADD_TRANSFER: 'phone:addTransfer',
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
BANK_SEND_TRANSFERS: 'phone:sendTransfers',
BANK_TRANSACTION_ALERT: 'phone:transactionAlert',
BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials',
BANK_GET_CREDENTIALS: 'phone:getBankCredentials'
}