NetworkInventoryAction: Allow returning null to ignore weird transactions

Revert "Return null on unmatched inventory action and log details"

This reverts commit fd7fb10223f7373919701008970e7e87abc2654e.
This commit is contained in:
Dylan K. Taylor 2017-11-29 12:43:16 +00:00
parent 78cf875080
commit 2cb81b5f8d
2 changed files with 16 additions and 15 deletions

View File

@ -2210,15 +2210,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var InventoryAction[] $actions */ /** @var InventoryAction[] $actions */
$actions = []; $actions = [];
foreach($packet->actions as $networkInventoryAction){ foreach($packet->actions as $networkInventoryAction){
try{
$action = $networkInventoryAction->createInventoryAction($this); $action = $networkInventoryAction->createInventoryAction($this);
if($action !== null){
if($action === null){ $actions[] = $action;
$this->server->getLogger()->debug("Unmatched inventory action from " . $this->getName() . ": " . json_encode($networkInventoryAction)); }
}catch(\Throwable $e){
$this->server->getLogger()->debug("Unhandled inventory action from " . $this->getName() . ": " . $e->getMessage());
$this->sendAllInventories(); $this->sendAllInventories();
return false; return false;
} }
$actions[] = $action;
} }
if($packet->isCraftingPart){ if($packet->isCraftingPart){

View File

@ -170,13 +170,13 @@ class NetworkInventoryAction{
return new SlotChangeAction($window, $this->inventorySlot, $this->oldItem, $this->newItem); return new SlotChangeAction($window, $this->inventorySlot, $this->oldItem, $this->newItem);
} }
return null; throw new \InvalidStateException("Player " . $player->getName() . " has no open container with window ID $this->windowId");
case self::SOURCE_WORLD: case self::SOURCE_WORLD:
if($this->inventorySlot === self::ACTION_MAGIC_SLOT_DROP_ITEM){ if($this->inventorySlot !== self::ACTION_MAGIC_SLOT_DROP_ITEM){
return new DropItemAction($this->oldItem, $this->newItem); throw new \UnexpectedValueException("Only expecting drop-item world actions from the client!");
} }
return null; return new DropItemAction($this->oldItem, $this->newItem);
case self::SOURCE_CREATIVE: case self::SOURCE_CREATIVE:
switch($this->inventorySlot){ switch($this->inventorySlot){
case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM: case self::ACTION_MAGIC_SLOT_CREATIVE_DELETE_ITEM:
@ -186,7 +186,7 @@ class NetworkInventoryAction{
$type = CreativeInventoryAction::TYPE_CREATE_ITEM; $type = CreativeInventoryAction::TYPE_CREATE_ITEM;
break; break;
default: default:
return null; throw new \UnexpectedValueException("Unexpected creative action type $this->inventorySlot");
} }
@ -210,16 +210,16 @@ class NetworkInventoryAction{
//DROP_CONTENTS doesn't bother telling us what slot the item is in, so we find it ourselves //DROP_CONTENTS doesn't bother telling us what slot the item is in, so we find it ourselves
$inventorySlot = $window->first($this->oldItem, true); $inventorySlot = $window->first($this->oldItem, true);
if($inventorySlot === -1){ if($inventorySlot === -1){
return null; throw new \InvalidStateException("Fake container " . get_class($window) . " for " . $player->getName() . " does not contain $this->oldItem");
} }
return new SlotChangeAction($window, $inventorySlot, $this->oldItem, $this->newItem); return new SlotChangeAction($window, $inventorySlot, $this->oldItem, $this->newItem);
} }
//TODO: more stuff //TODO: more stuff
return null; throw new \UnexpectedValueException("Player " . $player->getName() . " has no open container with window ID $this->windowId");
default:
throw new \UnexpectedValueException("Unknown inventory source type $this->sourceType");
} }
return null;
} }
} }