From bfed8a8f06ca6e5721f2de5d3a44f61079466a86 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sat, 3 Feb 2018 16:03:27 +0100 Subject: [PATCH 1/4] Initial push --- client/main.lua | 2 +- config.lua | 2 +- esx_billing.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/main.lua b/client/main.lua index 0fc8eb5c..ebf72009 100644 --- a/client/main.lua +++ b/client/main.lua @@ -37,7 +37,7 @@ function ShowBillsMenu() 'default', GetCurrentResourceName(), 'billing', { title = _U('invoices'), - align = 'top-left', + align = 'bottom-right', elements = elements }, function(data, menu) diff --git a/config.lua b/config.lua index 56a8b5e9..5290495d 100644 --- a/config.lua +++ b/config.lua @@ -1,2 +1,2 @@ Config = {} -Config.Locale = 'fr' +Config.Locale = 'en' diff --git a/esx_billing.sql b/esx_billing.sql index f7571215..014464b7 100644 --- a/esx_billing.sql +++ b/esx_billing.sql @@ -1,4 +1,4 @@ -USE `essentialmode`; +USE `fivem2337`; CREATE TABLE `billing` ( From d052d9804264f6611965e86e658be4f0545b8e0f Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Thu, 22 Feb 2018 16:57:43 +0100 Subject: [PATCH 2/4] Fixed negative bills --- __resource.lua | 2 ++ client/main.lua | 15 ++++++--------- config.lua | 2 +- locales/en.lua | 4 ++-- locales/sv.lua | 8 ++++++++ server/main.lua | 39 +++++++++++++++++---------------------- 6 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 locales/sv.lua diff --git a/__resource.lua b/__resource.lua index eaf5b6de..1b4649c9 100644 --- a/__resource.lua +++ b/__resource.lua @@ -12,6 +12,7 @@ server_scripts { 'locales/en.lua', 'locales/fr.lua', 'locales/es.lua', + 'locales/sv.lua', 'config.lua', 'server/main.lua' } @@ -23,6 +24,7 @@ client_scripts { 'locales/en.lua', 'locales/fr.lua', 'locales/es.lua', + 'locales/sv.lua', 'config.lua', 'client/main.lua' } diff --git a/client/main.lua b/client/main.lua index ebf72009..bfe25dfd 100644 --- a/client/main.lua +++ b/client/main.lua @@ -63,13 +63,10 @@ end -- Key controls Citizen.CreateThread(function() while true do - - Wait(0) - - if IsControlPressed(0, Keys["F7"]) and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') and (GetGameTimer() - GUI.Time) > 150 then - ShowBillsMenu() - GUI.Time = GetGameTimer() - end - - end + Citizen.Wait(25) + if IsControlPressed(0, Keys["F7"]) and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') and (GetGameTimer() - GUI.Time) > 150 then + ShowBillsMenu() + GUI.Time = GetGameTimer() + end + end end) diff --git a/config.lua b/config.lua index 5290495d..926107bc 100644 --- a/config.lua +++ b/config.lua @@ -1,2 +1,2 @@ Config = {} -Config.Locale = 'en' +Config.Locale = 'sv' diff --git a/locales/en.lua b/locales/en.lua index 5271005b..0c17646c 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,9 +1,9 @@ Locales['en'] = { ['invoices'] = 'invoices', - ['received_invoice'] = 'you ~r~received~s~ an invoice', + ['received_invoice'] = 'you have just ~r~received~s~ an invoice', ['paid_invoice'] = 'you ~g~paid~s~ an invoice of ~r~$', ['received_payment'] = 'you ~g~received~s~ a payment of ~r~$', ['player_not_logged'] = 'the player is not logged in', - + ['no_money'] = 'you do not have enough money to pay this bill', } diff --git a/locales/sv.lua b/locales/sv.lua new file mode 100644 index 00000000..ca0cc040 --- /dev/null +++ b/locales/sv.lua @@ -0,0 +1,8 @@ +Locales['sv'] = { + ['invoices'] = 'räkningar', + ['received_invoice'] = 'du har ~r~mottagit~s~ en räkning', + ['paid_invoice'] = 'du ~g~betalade~s~ precis en räkning på ~g~$', + ['received_payment'] = 'u har ~g~mottagit~s~ en räkning på ~g~$', + ['player_not_logged'] = 'spelaren är inte online', + ['no_money'] = 'du har inte råd för att betala räkningen', +} diff --git a/server/main.lua b/server/main.lua index 26cacdc8..b95b0329 100644 --- a/server/main.lua +++ b/server/main.lua @@ -163,30 +163,25 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) end else - TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account) - - MySQL.Async.execute( - 'DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, - function(rowsChanged) - - xPlayer.removeMoney(amount) - account.addMoney(amount) - - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice') .. amount) - - if foundPlayer ~= nil then - TriggerClientEvent('esx:showNotification', foundPlayer.source, _U('received_payment') .. amount) - end - + if xPlayer.get('money') >= amount then + MySQL.Async.execute( + 'DELETE from billing WHERE id = @id', + { + ['@id'] = id + }, + function(rowsChanged) + xPlayer.removeMoney(amount) + account.addMoney(amount) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice') .. amount) + if foundPlayer ~= nil then + TriggerClientEvent('esx:showNotification', foundPlayer.source, _U('received_payment') .. amount) + end cb() - - end - ) - + end) + else + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + end end) end From 93daf17c9a8723691818bb6766ea3a3c8409cc02 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Thu, 22 Feb 2018 17:37:15 +0100 Subject: [PATCH 3/4] Added message to reciver... when the target player doesn't have enough money to pay the bill --- locales/en.lua | 2 +- locales/sv.lua | 9 +++++---- server/main.lua | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/locales/en.lua b/locales/en.lua index 0c17646c..46667262 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,9 +1,9 @@ Locales['en'] = { - ['invoices'] = 'invoices', ['received_invoice'] = 'you have just ~r~received~s~ an invoice', ['paid_invoice'] = 'you ~g~paid~s~ an invoice of ~r~$', ['received_payment'] = 'you ~g~received~s~ a payment of ~r~$', ['player_not_logged'] = 'the player is not logged in', ['no_money'] = 'you do not have enough money to pay this bill', + ['target_no_money'] = 'The player ~r~does not~w~ have enough money to pay the bill!' } diff --git a/locales/sv.lua b/locales/sv.lua index ca0cc040..c5394337 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -1,8 +1,9 @@ Locales['sv'] = { ['invoices'] = 'räkningar', - ['received_invoice'] = 'du har ~r~mottagit~s~ en räkning', - ['paid_invoice'] = 'du ~g~betalade~s~ precis en räkning på ~g~$', - ['received_payment'] = 'u har ~g~mottagit~s~ en räkning på ~g~$', + ['received_invoice'] = 'du har ~y~mottagit~s~ en räkning', + ['paid_invoice'] = 'du ~y~betalade~w~ precis en räkning på ~g~$', + ['received_payment'] = 'du har ~y~mottagit~w~ en räkning på ~g~$', ['player_not_logged'] = 'spelaren är inte online', - ['no_money'] = 'du har inte råd för att betala räkningen', + ['no_money'] = 'du har ~r~inte råd~w~ för att kunna betala räkningen', + ['target_no_money'] = 'Spelaren har ~r~inte råd~w~ för att betala räkningen' } diff --git a/server/main.lua b/server/main.lua index 0c059a8e..148fbc6c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -184,6 +184,9 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) end) else TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + if foundPlayer ~= nil then + TriggerClientEvent('esx:showNotification', foundPlayer.source, _U('target_no_money')) + end end end) From b12d6c139fb1e62e3f4204ce02c5555278926904 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Thu, 22 Feb 2018 18:36:14 +0100 Subject: [PATCH 4/4] Fixed exploit: negative bills Sending negative bills gives the target player money! This adds a simple check to see if the bill is a negative value. --- locales/en.lua | 3 ++- locales/sv.lua | 3 ++- server/main.lua | 11 +++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/locales/en.lua b/locales/en.lua index 46667262..d13b1d8b 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -5,5 +5,6 @@ Locales['en'] = { ['received_payment'] = 'you ~g~received~s~ a payment of ~r~$', ['player_not_logged'] = 'the player is not logged in', ['no_money'] = 'you do not have enough money to pay this bill', - ['target_no_money'] = 'The player ~r~does not~w~ have enough money to pay the bill!' + ['target_no_money'] = 'The player ~r~does not~w~ have enough money to pay the bill!', + ['negative_bill'] = 'You cannot send negative bills!' } diff --git a/locales/sv.lua b/locales/sv.lua index c5394337..654fffdf 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -5,5 +5,6 @@ Locales['sv'] = { ['received_payment'] = 'du har ~y~mottagit~w~ en räkning på ~g~$', ['player_not_logged'] = 'spelaren är inte online', ['no_money'] = 'du har ~r~inte råd~w~ för att kunna betala räkningen', - ['target_no_money'] = 'Spelaren har ~r~inte råd~w~ för att betala räkningen' + ['target_no_money'] = 'Spelaren har ~r~inte råd~w~ för att betala räkningen', + ['negative_bill'] = 'Du kan inte skicka negativa räkningar!' } diff --git a/server/main.lua b/server/main.lua index 148fbc6c..bfb9739a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -6,12 +6,15 @@ RegisterServerEvent('esx_billing:sendBill') AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, label, amount) local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local xPlayer = ESX.GetPlayerFromId(_source) local xPlayers = ESX.GetPlayers() TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account) - if account == nil then + if amount < 0 then + print('esx_billing: ' .. GetPlayerName(_source) .. ' tried sending a negative bill!') + TriggerClientEvent('esx:showNotification', _source, _U('negative_bill')) + elseif account == nil then for i=1, #xPlayers, 1 do @@ -37,9 +40,7 @@ AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, la break end end - else - for i=1, #xPlayers, 1 do local xPlayer2 = ESX.GetPlayerFromId(xPlayers[i]) @@ -64,9 +65,7 @@ AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, la break end end - end - end) end)