From 981104d94c6a68b0f0d85a3ccdbfc72fb106733f Mon Sep 17 00:00:00 2001 From: Lation Date: Fri, 16 Aug 2024 09:37:23 -0400 Subject: [PATCH 1/7] Add ClearStash export --- server/functions.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index 7c5b9743b..1b2244f39 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -460,6 +460,18 @@ end exports('OpenInventoryById', OpenInventoryById) +-- Clears a given stash of all items inside +--- @param identifier string +function ClearStash(identifier) + if not identifier then return end + local inventory = Inventories[identifier] + if not inventory then return end + inventory.items = {} + MySQL.prepare('UPDATE inventories SET items = ? WHERE identifier = ?', { json.encode(inventory.items), identifier }) +end + +exports('ClearStash', ClearStash) + --- @param shopData table The data of the shop to create. function CreateShop(shopData) if shopData.name then From d10f3a60da240ac2b513a95d9c3289129ecc0ffe Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 11:50:17 -0700 Subject: [PATCH 2/7] fix(drops): drop deletion due to incorrect table length with empty indexes --- server/main.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/main.lua b/server/main.lua index 6aff6530f..e613fd3c6 100644 --- a/server/main.lua +++ b/server/main.lua @@ -294,11 +294,18 @@ QBCore.Functions.CreateCallback('qb-inventory:server:createDrop', function(sourc local bag = CreateObjectNoOffset(Config.ItemDropObject, playerCoords.x + 0.5, playerCoords.y + 0.5, playerCoords.z, true, true, false) local dropId = NetworkGetNetworkIdFromEntity(bag) local newDropId = 'drop-' .. dropId + local itemsTable = setmetatable({ item }, { + __len = function(t) + local length = 0 + for _ in pairs(t) do length += 1 end + return length + end + }) if not Drops[newDropId] then Drops[newDropId] = { name = newDropId, label = 'Drop', - items = { item }, + items = itemsTable, entityId = dropId, createdTime = os.time(), coords = playerCoords, From ff01fc467db51dfccefcf529f988d9ecdd4ded60 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 12:35:22 -0700 Subject: [PATCH 3/7] chore(lint): fix unused and inacessible variables --- client/drops.lua | 37 ++++++++++++++++++------------------- client/main.lua | 1 + 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/drops.lua b/client/drops.lua index 69a23de0d..298d75e7a 100644 --- a/client/drops.lua +++ b/client/drops.lua @@ -1,4 +1,4 @@ -local holdingDrop = false +holdingDrop = false local bagObject = nil local heldDrop = nil CurrentDrop = nil @@ -7,24 +7,23 @@ CurrentDrop = nil function GetDrops() QBCore.Functions.TriggerCallback('qb-inventory:server:GetCurrentDrops', function(drops) - if drops then - for k, v in pairs(drops) do - local bag = NetworkGetEntityFromNetworkId(v.entityId) - if DoesEntityExist(bag) then - exports['qb-target']:AddTargetEntity(bag, { - options = { - { - icon = 'fas fa-backpack', - label = Lang:t('menu.o_bag'), - action = function() - TriggerServerEvent('qb-inventory:server:openDrop', k) - CurrentDrop = dropId - end, - }, + if not drops then return end + for k, v in pairs(drops) do + local bag = NetworkGetEntityFromNetworkId(v.entityId) + if DoesEntityExist(bag) then + exports['qb-target']:AddTargetEntity(bag, { + options = { + { + icon = 'fas fa-backpack', + label = Lang:t('menu.o_bag'), + action = function() + TriggerServerEvent('qb-inventory:server:openDrop', k) + CurrentDrop = k + end, }, - distance = 2.5, - }) - end + }, + distance = 2.5, + }) end end end) @@ -59,7 +58,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId) label = 'Pick up bag', action = function() if IsPedArmed(PlayerPedId(), 4) then - return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500) + return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500) end if holdingDrop then return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500) diff --git a/client/main.lua b/client/main.lua index 161ecd7b5..5d675ffa7 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,4 +1,5 @@ QBCore = exports['qb-core']:GetCoreObject() +PlayerData = nil local hotbarShown = false -- Handlers From e1fbaaf4908a8247763f15e2c1abf96bc5a7a42e Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 16:25:05 -0700 Subject: [PATCH 4/7] fix(ui): prevent irrelevant amount sending on swap --- html/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/app.js b/html/app.js index ff00bea84..da8940f16 100644 --- a/html/app.js +++ b/html/app.js @@ -482,7 +482,7 @@ const InventoryContainer = Vue.createApp({ targetInventory[targetSlotNumber] = sourceItem; sourceInventory[this.currentlyDraggingSlot].slot = this.currentlyDraggingSlot; targetInventory[targetSlotNumber].slot = targetSlotNumber; - this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, amountToTransfer, targetItem.amount); + this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, sourceItem.amount, targetItem.amount); } } else { sourceItem.amount -= amountToTransfer; From c543e8c499940b518d0ab2b1a867c0148a874645 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 16:29:12 -0700 Subject: [PATCH 5/7] fix: prevent item dupe exploit on item swap --- server/main.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/main.lua b/server/main.lua index e613fd3c6..3bfa405f1 100644 --- a/server/main.lua +++ b/server/main.lua @@ -495,9 +495,12 @@ RegisterNetEvent('qb-inventory:server:SetInventoryData', function(fromInventory, end else if toItem then - if RemoveItem(fromId, fromItem.name, fromAmount, fromSlot, 'swapped item') and RemoveItem(toId, toItem.name, toAmount, toSlot, 'swapped item') then - AddItem(toId, fromItem.name, fromAmount, toSlot, fromItem.info, 'swapped item') - AddItem(fromId, toItem.name, toAmount, fromSlot, toItem.info, 'swapped item') + local fromItemAmount = fromItem.amount + local toItemAmount = toItem.amount + + if RemoveItem(fromId, fromItem.name, fromItemAmount, fromSlot, 'swapped item') and RemoveItem(toId, toItem.name, toItemAmount, toSlot, 'swapped item') then + AddItem(toId, fromItem.name, fromItemAmount, toSlot, fromItem.info, 'swapped item') + AddItem(fromId, toItem.name, toItemAmount, fromSlot, toItem.info, 'swapped item') end else if RemoveItem(fromId, fromItem.name, toAmount, fromSlot, 'moved item') then From c5a7c91de4af84048d2642a87a628e088bac6c91 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 16:56:23 -0700 Subject: [PATCH 6/7] fix(ui): prevent give item if no one around --- html/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/html/app.js b/html/app.js index da8940f16..a11f4b530 100644 --- a/html/app.js +++ b/html/app.js @@ -698,12 +698,14 @@ const InventoryContainer = Vue.createApp({ } try { - await axios.post("https://qb-inventory/GiveItem", { + const response = await axios.post("https://qb-inventory/GiveItem", { item: selectedItem, amount: amountToGive, slot: selectedItem.slot, info: selectedItem.info, }); + if (!response.data) return; + this.playerInventory[selectedItem.slot].amount -= amountToGive; if (this.playerInventory[selectedItem.slot].amount === 0) { delete this.playerInventory[selectedItem.slot]; From fc9f32b4f3dfd75ff231fab711b08a1cc6eeb558 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 17:25:25 -0700 Subject: [PATCH 7/7] fix(ui): update player inventory on item drop --- html/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/html/app.js b/html/app.js index a11f4b530..55d8585e4 100644 --- a/html/app.js +++ b/html/app.js @@ -589,6 +589,7 @@ const InventoryContainer = Vue.createApp({ }); if (response.data) { + delete this.playerInventory[playerItemKey]; this.otherInventory[1] = newItem; this.otherInventoryName = response.data; this.otherInventoryLabel = response.data;