InventoryTransaction: prevent client-authoritative item overstacking

this cheat is often used to carry more items in the inventory, wear multiple pieces of armour in one slot, and more.
This commit is contained in:
Dylan K. Taylor 2022-08-21 20:35:23 +01:00
parent af2babec23
commit 5426b41447
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 9 additions and 0 deletions

View File

@ -42,6 +42,9 @@ class DropItemAction extends InventoryAction{
if($this->targetItem->isNull()){
throw new TransactionValidationException("Cannot drop an empty itemstack");
}
if($this->targetItem->getCount() > $this->targetItem->getMaxStackSize()){
throw new TransactionValidationException("Target item exceeds item type max stack size");
}
}
public function onPreExecute(Player $source) : bool{

View File

@ -70,6 +70,12 @@ class SlotChangeAction extends InventoryAction{
if(!$this->inventory->getItem($this->inventorySlot)->equalsExact($this->sourceItem)){
throw new TransactionValidationException("Slot does not contain expected original item");
}
if($this->targetItem->getCount() > $this->targetItem->getMaxStackSize()){
throw new TransactionValidationException("Target item exceeds item type max stack size");
}
if($this->targetItem->getCount() > $this->inventory->getMaxStackSize()){
throw new TransactionValidationException("Target item exceeds inventory max stack size");
}
}
/**