Skip to content

Commit

Permalink
Merge pull request #573 from Qwerty1Verified/main
Browse files Browse the repository at this point in the history
fix: prevent item dupe exploit on item swap
  • Loading branch information
GhzGarage authored Sep 7, 2024
2 parents e8c6805 + fc9f32b commit f31e85a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -698,12 +699,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];
Expand Down
9 changes: 6 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f31e85a

Please sign in to comment.