Skip to content

Commit

Permalink
refactor(server/inventory): avoid direct Inventories table access
Browse files Browse the repository at this point in the history
To ensure some actions aren't possible during lockdown.
  • Loading branch information
thelindat committed Jan 30, 2025
1 parent b3d04c3 commit a74e109
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -614,30 +614,30 @@ end
function Inventory.Remove(inv)
inv = Inventory(inv) --[[@as OxInventory]]

if inv then
if inv.type == 'drop' then
TriggerClientEvent('ox_inventory:removeDrop', -1, inv.id)
Inventory.Drops[inv.id] = nil
elseif inv.player then
activeIdentifiers[inv.owner] = nil
end
if not inv then return end

if inv.type == 'drop' then
TriggerClientEvent('ox_inventory:removeDrop', -1, inv.id)
Inventory.Drops[inv.id] = nil
elseif inv.player then
activeIdentifiers[inv.owner] = nil
end

for playerId in pairs(inv.openedBy) do
if inv.id ~= playerId then
local target = Inventories[playerId]
for playerId in pairs(inv.openedBy) do
if inv.id ~= playerId then
local target = Inventories[playerId]

if target then
target:closeInventory()
end
if target then
target:closeInventory()
end
end
end

if not inv.datastore and inv.changed then
Inventory.Save(inv)
end
if not inv.datastore and inv.changed then
Inventory.Save(inv)
end

Inventories[inv.id] = nil
end
Inventories[inv.id] = nil
end

exports('RemoveInventory', Inventory.Remove)
Expand Down Expand Up @@ -1512,7 +1512,7 @@ AddEventHandler('ox_inventory:customDrop', CustomDrop)
exports('CustomDrop', CustomDrop)

exports('CreateDropFromPlayer', function(playerId)
local playerInventory = Inventories[playerId]
local playerInventory = Inventory(playerId)

if not playerInventory or not next(playerInventory.items) then return end

Expand Down Expand Up @@ -1965,7 +1965,7 @@ lib.callback.register('ox_inventory:swapItems', function(source, data)
end)

function Inventory.Confiscate(source)
local inv = Inventories[source]
local inv = Inventory(source)

if inv?.player then
db.saveStash(inv.owner, inv.owner, json.encode(minimal(inv)))
Expand All @@ -1981,7 +1981,7 @@ end
exports('ConfiscateInventory', Inventory.Confiscate)

function Inventory.Return(source)
local inv = Inventories[source]
local inv = Inventory(source)

if not inv?.player then return end

Expand Down Expand Up @@ -2410,8 +2410,8 @@ RegisterServerEvent('ox_inventory:closeInventory', function()
end)

local function giveItem(playerId, slot, target, count)
local fromInventory = Inventories[playerId]
local toInventory = Inventories[target]
local fromInventory = Inventory(playerId)
local toInventory = Inventory(target)

if count <= 0 then count = 1 end

Expand Down Expand Up @@ -2478,7 +2478,7 @@ lib.callback.register('ox_inventory:giveItem', giveItem)
RegisterServerEvent('ox_inventory:giveItem', function(...) giveItem(source, ...) end)

local function updateWeapon(source, action, value, slot, specialAmmo)
local inventory = Inventories[source]
local inventory = Inventory(source)

if not inventory then return end

Expand Down

0 comments on commit a74e109

Please sign in to comment.