mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
Check for mismatched inventory slot predictions in transactions
this should limit the problems caused by mismatched gameplay features that result in ghost items, such as #4896.
This commit is contained in:
parent
bf71eb448a
commit
90a8595a40
@ -304,6 +304,28 @@ class InventoryManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function syncMismatchedPredictedSlotChanges() : void{
|
||||||
|
foreach($this->initiatedSlotChanges as $windowId => $slots){
|
||||||
|
if(!isset($this->windowMap[$windowId])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$inventory = $this->windowMap[$windowId];
|
||||||
|
|
||||||
|
foreach($slots as $slot => $expectedItem){
|
||||||
|
if(!$inventory->slotExists($slot)){
|
||||||
|
continue; //TODO: size desync ???
|
||||||
|
}
|
||||||
|
$actualItem = $inventory->getItem($slot);
|
||||||
|
if(!$actualItem->equalsExact($expectedItem)){
|
||||||
|
$this->session->getLogger()->debug("Detected prediction mismatch in inventory " . get_class($inventory) . "#" . spl_object_id($inventory) . " slot $slot");
|
||||||
|
$this->syncSlot($inventory, $slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->initiatedSlotChanges = [];
|
||||||
|
}
|
||||||
|
|
||||||
public function syncData(Inventory $inventory, int $propertyId, int $value) : void{
|
public function syncData(Inventory $inventory, int $propertyId, int $value) : void{
|
||||||
$windowId = $this->getWindowId($inventory);
|
$windowId = $this->getWindowId($inventory);
|
||||||
if($windowId !== null){
|
if($windowId !== null){
|
||||||
|
@ -234,9 +234,13 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
$packetHandled = true;
|
$packetHandled = true;
|
||||||
|
|
||||||
$useItemTransaction = $packet->getItemInteractionData();
|
$useItemTransaction = $packet->getItemInteractionData();
|
||||||
if($useItemTransaction !== null && !$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
|
if($useItemTransaction !== null){
|
||||||
$packetHandled = false;
|
if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
|
||||||
$this->session->getLogger()->debug("Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() . ")");
|
$packetHandled = false;
|
||||||
|
$this->session->getLogger()->debug("Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() . ")");
|
||||||
|
}else{
|
||||||
|
$this->inventoryManager->syncMismatchedPredictedSlotChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$blockActions = $packet->getBlockActions();
|
$blockActions = $packet->getBlockActions();
|
||||||
@ -304,6 +308,8 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
|
|
||||||
if(!$result){
|
if(!$result){
|
||||||
$this->inventoryManager->syncAll();
|
$this->inventoryManager->syncAll();
|
||||||
|
}else{
|
||||||
|
$this->inventoryManager->syncMismatchedPredictedSlotChanges();
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user