Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent item dupe exploit on item swap #573

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading