Merge pull request #1161 from Kenshiin13/Security-Updates

Security Enhancement: Distance Check for 'esx:onPickup' Event
This commit is contained in:
Gellipapa
2023-08-25 17:43:39 +02:00
committed by GitHub
5 changed files with 52 additions and 46 deletions
+27 -27
View File
@@ -70,17 +70,17 @@ function ESX.Progressbar(message, length, Options)
print("[^1ERROR^7] ^5ESX Progressbar^7 is Missing!")
end
function ESX.ShowNotification(message, type, length)
function ESX.ShowNotification(message, notifyType, length)
if GetResourceState("esx_notify") ~= "missing" then
return exports["esx_notify"]:Notify(type, length, message)
return exports["esx_notify"]:Notify(notifyType, length, message)
end
print("[^1ERROR^7] ^5ESX Notify^7 is Missing!")
end
function ESX.TextUI(message, type)
function ESX.TextUI(message, notifyType)
if GetResourceState("esx_textui") ~= "missing" then
return exports["esx_textui"]:TextUI(message, type)
return exports["esx_textui"]:TextUI(message, notifyType)
end
print("[^1ERROR^7] ^5ESX TextUI^7 is Missing!")
@@ -167,17 +167,17 @@ ESX.RegisterInput = function(command_name, label, input_group, key, on_press, on
RegisterKeyMapping(on_release ~= nil and "+" .. command_name or command_name, label, input_group, key)
end
function ESX.UI.Menu.RegisterType(type, open, close)
ESX.UI.Menu.RegisteredTypes[type] = {
function ESX.UI.Menu.RegisterType(menuType, open, close)
ESX.UI.Menu.RegisteredTypes[menuType] = {
open = open,
close = close
}
end
function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, close)
function ESX.UI.Menu.Open(menuType, namespace, name, data, submit, cancel, change, close)
local menu = {}
menu.type = type
menu.type = menuType
menu.namespace = namespace
menu.resourceName = (GetInvokingResource() or "Unknown")
menu.name = name
@@ -187,11 +187,11 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
menu.change = change
menu.close = function()
ESX.UI.Menu.RegisteredTypes[type].close(namespace, name)
ESX.UI.Menu.RegisteredTypes[menuType].close(namespace, name)
for i = 1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and
if ESX.UI.Menu.Opened[i].type == menuType and ESX.UI.Menu.Opened[i].namespace == namespace and
ESX.UI.Menu.Opened[i].name == name then
ESX.UI.Menu.Opened[i] = nil
end
@@ -222,7 +222,7 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
end
menu.refresh = function()
ESX.UI.Menu.RegisteredTypes[type].open(namespace, name, menu.data)
ESX.UI.Menu.RegisteredTypes[menuType].open(namespace, name, menu.data)
end
menu.setElement = function(i, key, val)
@@ -251,15 +251,15 @@ function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, c
end
ESX.UI.Menu.Opened[#ESX.UI.Menu.Opened + 1] = menu
ESX.UI.Menu.RegisteredTypes[type].open(namespace, name, data)
ESX.UI.Menu.RegisteredTypes[menuType].open(namespace, name, data)
return menu
end
function ESX.UI.Menu.Close(type, namespace, name)
function ESX.UI.Menu.Close(menuType, namespace, name)
for i = 1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and
if ESX.UI.Menu.Opened[i].type == menuType and ESX.UI.Menu.Opened[i].namespace == namespace and
ESX.UI.Menu.Opened[i].name == name then
ESX.UI.Menu.Opened[i].close()
ESX.UI.Menu.Opened[i] = nil
@@ -277,10 +277,10 @@ function ESX.UI.Menu.CloseAll()
end
end
function ESX.UI.Menu.GetOpened(type, namespace, name)
function ESX.UI.Menu.GetOpened(menuType, namespace, name)
for i = 1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and
if ESX.UI.Menu.Opened[i].type == menuType and ESX.UI.Menu.Opened[i].namespace == namespace and
ESX.UI.Menu.Opened[i].name == name then
return ESX.UI.Menu.Opened[i]
end
@@ -292,8 +292,8 @@ function ESX.UI.Menu.GetOpenedMenus()
return ESX.UI.Menu.Opened
end
function ESX.UI.Menu.IsOpen(type, namespace, name)
return ESX.UI.Menu.GetOpened(type, namespace, name) ~= nil
function ESX.UI.Menu.IsOpen(menuType, namespace, name)
return ESX.UI.Menu.GetOpened(menuType, namespace, name) ~= nil
end
function ESX.UI.ShowInventoryItemNotification(add, item, count)
@@ -1156,7 +1156,7 @@ function ESX.ShowInventory()
}
ESX.OpenContext("right", elements2, function(_, element2)
local item, type = element2.value, element2.type
local item, itemType = element2.value, element2.type
if element2.action == "give" then
local playersNearby = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
@@ -1189,8 +1189,8 @@ function ESX.ShowInventory()
local selectedPlayerPed = GetPlayerPed(selectedPlayer)
if IsPedOnFoot(selectedPlayerPed) and not IsPedFalling(selectedPlayerPed) then
if type == 'item_weapon' then
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, nil)
if itemType == 'item_weapon' then
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, itemType, item, nil)
ESX.CloseContext()
else
local elementsG = {
@@ -1203,7 +1203,7 @@ function ESX.ShowInventory()
local quantity = tonumber(menuG.eles[2].inputValue)
if quantity and quantity > 0 and element.count >= quantity then
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, quantity)
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, itemType, item, quantity)
ESX.CloseContext()
else
ESX.ShowNotification(TranslateCap('amount_invalid'))
@@ -1225,12 +1225,12 @@ function ESX.ShowInventory()
local dict, anim = 'weapons@first_person@aim_rng@generic@projectile@sticky_bomb@', 'plant_floor'
ESX.Streaming.RequestAnimDict(dict)
if type == 'item_weapon' then
if itemType == 'item_weapon' then
ESX.CloseContext()
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false)
RemoveAnimDict(dict)
Wait(1000)
TriggerServerEvent('esx:removeInventoryItem', type, item)
TriggerServerEvent('esx:removeInventoryItem', itemType, item)
else
local elementsR = {
{ unselectable = true, icon = "fas fa-trash", title = element.title },
@@ -1246,7 +1246,7 @@ function ESX.ShowInventory()
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false)
RemoveAnimDict(dict)
Wait(1000)
TriggerServerEvent('esx:removeInventoryItem', type, item, quantity)
TriggerServerEvent('esx:removeInventoryItem', itemType, item, quantity)
else
ESX.ShowNotification(TranslateCap('amount_invalid'))
end
@@ -1302,8 +1302,8 @@ function ESX.ShowInventory()
end
RegisterNetEvent('esx:showNotification')
AddEventHandler('esx:showNotification', function(msg, type, length)
ESX.ShowNotification(msg, type, length)
AddEventHandler('esx:showNotification', function(msg, notifyType, length)
ESX.ShowNotification(msg, notifyType, length)
end)
RegisterNetEvent('esx:showAdvancedNotification')
+3 -3
View File
@@ -349,7 +349,7 @@ end)
if not Config.OxInventory then
RegisterNetEvent('esx:createPickup')
AddEventHandler('esx:createPickup', function(pickupId, label, coords, type, name, components, tintIndex)
AddEventHandler('esx:createPickup', function(pickupId, label, coords, itemType, name, components, tintIndex)
local function setObjectProperties(object)
SetEntityAsMissionEntity(object, true, false)
PlaceObjectOnGroundProperly(object)
@@ -360,11 +360,11 @@ if not Config.OxInventory then
obj = object,
label = label,
inRange = false,
coords = vector3(coords.x, coords.y, coords.z)
coords = coords
}
end
if type == 'item_weapon' then
if itemType == 'item_weapon' then
local weaponHash = joaat(name)
ESX.Streaming.RequestWeaponAsset(weaponHash)
local pickupObject = CreateWeaponObject(weaponHash, 50, coords.x, coords.y, coords.z, true, 1.0, 0)
+2 -2
View File
@@ -564,8 +564,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
function self.showNotification(msg, type, length)
self.triggerEvent('esx:showNotification', msg, type, length)
function self.showNotification(msg, notifyType, length)
self.triggerEvent('esx:showNotification', msg, notifyType, length)
end
function self.showAdvancedNotification(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
+5 -5
View File
@@ -476,19 +476,19 @@ function ESX.GetUsableItems()
end
if not Config.OxInventory then
function ESX.CreatePickup(type, name, count, label, playerId, components, tintIndex)
function ESX.CreatePickup(itemType, name, count, label, playerId, components, tintIndex, coords)
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
local xPlayer = ESX.Players[playerId]
local coords = xPlayer.getCoords()
coords = ( (type(coords) == "vector3" or type(coords) == "vector4") and coords.xyz or xPlayer.getCoords(true))
Core.Pickups[pickupId] = { type = type, name = name, count = count, label = label, coords = coords }
Core.Pickups[pickupId] = { type = itemType, name = name, count = count, label = label, coords = coords }
if type == 'item_weapon' then
if itemType == 'item_weapon' then
Core.Pickups[pickupId].components = components
Core.Pickups[pickupId].tintIndex = tintIndex
end
TriggerClientEvent('esx:createPickup', -1, pickupId, label, coords, type, name, components, tintIndex)
TriggerClientEvent('esx:createPickup', -1, pickupId, label, coords, itemType, name, components, tintIndex)
Core.PickupId = pickupId
end
end
+15 -9
View File
@@ -415,7 +415,7 @@ if not Config.OxInventory then
end)
RegisterNetEvent('esx:giveInventoryItem')
AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
AddEventHandler('esx:giveInventoryItem', function(target, itemType, itemName, itemCount)
local playerId = source
local sourceXPlayer = ESX.GetPlayerFromId(playerId)
local targetXPlayer = ESX.GetPlayerFromId(target)
@@ -425,7 +425,7 @@ if not Config.OxInventory then
return
end
if type == 'item_standard' then
if itemType == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
if itemCount > 0 and sourceItem.count >= itemCount then
@@ -441,7 +441,7 @@ if not Config.OxInventory then
else
sourceXPlayer.showNotification(TranslateCap('imp_invalid_quantity'))
end
elseif type == 'item_account' then
elseif itemType == 'item_account' then
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name)
targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name)
@@ -452,7 +452,7 @@ if not Config.OxInventory then
else
sourceXPlayer.showNotification(TranslateCap('imp_invalid_amount'))
end
elseif type == 'item_weapon' then
elseif itemType == 'item_weapon' then
if sourceXPlayer.hasWeapon(itemName) then
local weaponLabel = ESX.GetWeaponLabel(itemName)
if not targetXPlayer.hasWeapon(itemName) then
@@ -485,7 +485,7 @@ if not Config.OxInventory then
targetXPlayer.showNotification(TranslateCap('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
end
end
elseif type == 'item_ammo' then
elseif itemType == 'item_ammo' then
if sourceXPlayer.hasWeapon(itemName) then
local _, weapon = sourceXPlayer.getWeapon(itemName)
@@ -512,11 +512,11 @@ if not Config.OxInventory then
end)
RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
AddEventHandler('esx:removeInventoryItem', function(itemType, itemName, itemCount)
local playerId = source
local xPlayer = ESX.GetPlayerFromId(playerId)
if type == 'item_standard' then
if itemType == 'item_standard' then
if itemCount == nil or itemCount < 1 then
xPlayer.showNotification(TranslateCap('imp_invalid_quantity'))
else
@@ -531,7 +531,7 @@ if not Config.OxInventory then
xPlayer.showNotification(TranslateCap('threw_standard', itemCount, xItem.label))
end
end
elseif type == 'item_account' then
elseif itemType == 'item_account' then
if itemCount == nil or itemCount < 1 then
xPlayer.showNotification(TranslateCap('imp_invalid_amount'))
else
@@ -546,7 +546,7 @@ if not Config.OxInventory then
xPlayer.showNotification(TranslateCap('threw_account', ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
end
end
elseif type == 'item_weapon' then
elseif itemType == 'item_weapon' then
itemName = string.upper(itemName)
if xPlayer.hasWeapon(itemName) then
@@ -587,6 +587,12 @@ if not Config.OxInventory then
local pickup, xPlayer, success = Core.Pickups[pickupId], ESX.GetPlayerFromId(source)
if pickup then
local playerPickupDistance = #(pickup.coords - xPlayer.getCoords(true))
if(playerPickupDistance > 5.0) then
print(('[^3WARNING^7] Player Detected Cheating (Out of range pickup): ^5%s^7'):format(xPlayer.getIdentifier()))
return
end
if pickup.type == 'item_standard' then
if xPlayer.canCarryItem(pickup.name, pickup.count) then
xPlayer.addInventoryItem(pickup.name, pickup.count)