Skip to content

Commit

Permalink
fix(server/inventory): ignore owner/group checks when forcing open in…
Browse files Browse the repository at this point in the history
…ventory (#1769)
  • Loading branch information
SOH69 authored Aug 17, 2024
1 parent 5618523 commit 9f816e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ local GetVehicleNumberPlateText = GetVehicleNumberPlateText
---Atempts to lazily load inventory data from the database or create a new player-owned instance for "personal" stashes
---@param data table
---@param player table
---@param ignoreSecurityChecks boolean
---@return OxInventory | false | nil
local function loadInventoryData(data, player)
local function loadInventoryData(data, player, ignoreSecurityChecks)
local source = source
local inventory

Expand Down Expand Up @@ -178,7 +179,7 @@ local function loadInventoryData(data, player)

if stash then
if stash.jobs then stash.groups = stash.jobs end
if player and stash.groups and not server.hasGroup(player, stash.groups) then return end
if not ignoreSecurityChecks and player and stash.groups and not server.hasGroup(player, stash.groups) then return end

local owner

Expand Down Expand Up @@ -211,20 +212,20 @@ local function loadInventoryData(data, player)
end

setmetatable(Inventory, {
__call = function(self, inv, player)
__call = function(self, inv, player, ignoreSecurityChecks)
if not inv then
return self
elseif type(inv) == 'table' then
if inv.__index then return inv end

return not inv.owner and Inventories[inv.id] or loadInventoryData(inv, player)
return not inv.owner and Inventories[inv.id] or loadInventoryData(inv, player, ignoreSecurityChecks)
end

return Inventories[inv] or loadInventoryData({ id = inv }, player)
return Inventories[inv] or loadInventoryData({ id = inv }, player, ignoreSecurityChecks)
end
})

---@cast Inventory +fun(inv: inventory, player?: inventory): OxInventory|false|nil
---@cast Inventory +fun(inv: inventory, player?: inventory, ignoreSecurityChecks?: boolean): OxInventory|false|nil

---@param inv inventory
---@param owner? string | number
Expand Down
4 changes: 2 additions & 2 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ local function openInventory(source, invType, data, ignoreSecurityChecks)
local isDataTable = type(data) == 'table'

if invType == 'stash' then
right = Inventory(data, left)
right = Inventory(data, left, ignoreSecurityChecks)
if right == false then return false end
elseif isDataTable then
if data.netid then
Expand All @@ -135,7 +135,7 @@ local function openInventory(source, invType, data, ignoreSecurityChecks)
return
end
elseif invType == 'policeevidence' then
if server.hasGroup(left, shared.police) then
if ignoreSecurityChecks or server.hasGroup(left, shared.police) then
right = Inventory(('evidence-%s'):format(data))
end
elseif invType == 'dumpster' then
Expand Down

0 comments on commit 9f816e4

Please sign in to comment.