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:
Dylan K. Taylor 2022-03-22 17:42:19 +00:00
parent bf71eb448a
commit 90a8595a40
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 31 additions and 3 deletions

View File

@ -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{
$windowId = $this->getWindowId($inventory);
if($windowId !== null){

View File

@ -234,9 +234,13 @@ class InGamePacketHandler extends PacketHandler{
$packetHandled = true;
$useItemTransaction = $packet->getItemInteractionData();
if($useItemTransaction !== null && !$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
$packetHandled = false;
$this->session->getLogger()->debug("Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() . ")");
if($useItemTransaction !== null){
if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
$packetHandled = false;
$this->session->getLogger()->debug("Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() . ")");
}else{
$this->inventoryManager->syncMismatchedPredictedSlotChanges();
}
}
$blockActions = $packet->getBlockActions();
@ -304,6 +308,8 @@ class InGamePacketHandler extends PacketHandler{
if(!$result){
$this->inventoryManager->syncAll();
}else{
$this->inventoryManager->syncMismatchedPredictedSlotChanges();
}
return $result;
}