mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Airgap Attribute, fix decoding of non-registered attributes for protocol debugging
This commit is contained in:
parent
83a3adecff
commit
da7ff9b1fe
@ -50,6 +50,7 @@ use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket;
|
||||
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetActorDataPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetActorMotionPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\Attribute as NetworkAttribute;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
@ -62,6 +63,7 @@ use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\World;
|
||||
use function abs;
|
||||
use function array_map;
|
||||
use function assert;
|
||||
use function cos;
|
||||
use function count;
|
||||
@ -1518,7 +1520,9 @@ abstract class Entity{
|
||||
$pk->yaw = $this->location->yaw;
|
||||
$pk->headYaw = $this->location->yaw; //TODO
|
||||
$pk->pitch = $this->location->pitch;
|
||||
$pk->attributes = $this->attributeMap->getAll();
|
||||
$pk->attributes = array_map(function(Attribute $attr) : NetworkAttribute{
|
||||
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
|
||||
}, $this->attributeMap->getAll());
|
||||
$pk->metadata = $this->getSyncedNetworkData(false);
|
||||
|
||||
$player->getNetworkSession()->sendDataPacket($pk);
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\network\mcpe;
|
||||
|
||||
use Mdanter\Ecc\Crypto\Key\PublicKeyInterface;
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\entity\Living;
|
||||
@ -70,6 +71,7 @@ use pocketmine\network\mcpe\protocol\TransferPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\command\CommandData;
|
||||
use pocketmine\network\mcpe\protocol\types\command\CommandEnum;
|
||||
use pocketmine\network\mcpe\protocol\types\command\CommandParameter;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\Attribute as NetworkAttribute;
|
||||
use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
||||
@ -658,7 +660,9 @@ class NetworkSession{
|
||||
public function syncAttributes(Living $entity, bool $sendAll = false) : void{
|
||||
$entries = $sendAll ? $entity->getAttributeMap()->getAll() : $entity->getAttributeMap()->needSend();
|
||||
if(count($entries) > 0){
|
||||
$this->sendDataPacket(UpdateAttributesPacket::create($entity->getId(), $entries));
|
||||
$this->sendDataPacket(UpdateAttributesPacket::create($entity->getId(), array_map(function(Attribute $attr) : NetworkAttribute{
|
||||
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
|
||||
}, $entries)));
|
||||
foreach($entries as $entry){
|
||||
$entry->markSynchronized();
|
||||
}
|
||||
|
@ -25,10 +25,9 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\handler\PacketHandler;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
|
||||
@ -190,20 +189,7 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
|
||||
$min = $in->getLFloat();
|
||||
$current = $in->getLFloat();
|
||||
$max = $in->getLFloat();
|
||||
$attr = Attribute::get($id);
|
||||
|
||||
if($attr !== null){
|
||||
try{
|
||||
$attr->setMinValue($min);
|
||||
$attr->setMaxValue($max);
|
||||
$attr->setValue($current);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
throw BadPacketException::wrap($e); //TODO: address this properly
|
||||
}
|
||||
$this->attributes[] = $attr;
|
||||
}else{
|
||||
throw new BadPacketException("Unknown attribute type \"$id\"");
|
||||
}
|
||||
$this->attributes[] = new Attribute($id, $min, $max, $current, $current);
|
||||
}
|
||||
|
||||
$this->metadata = $in->getEntityMetadata();
|
||||
@ -226,9 +212,9 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
|
||||
$out->putUnsignedVarInt(count($this->attributes));
|
||||
foreach($this->attributes as $attribute){
|
||||
$out->putString($attribute->getId());
|
||||
$out->putLFloat($attribute->getMinValue());
|
||||
$out->putLFloat($attribute->getValue());
|
||||
$out->putLFloat($attribute->getMaxValue());
|
||||
$out->putLFloat($attribute->getMin());
|
||||
$out->putLFloat($attribute->getCurrent());
|
||||
$out->putLFloat($attribute->getMax());
|
||||
}
|
||||
|
||||
$out->putEntityMetadata($this->metadata);
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\network\mcpe\handler\PacketHandler;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
|
||||
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
|
||||
use function array_values;
|
||||
|
||||
|
65
src/network/mcpe/protocol/types/entity/Attribute.php
Normal file
65
src/network/mcpe/protocol/types/entity/Attribute.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\protocol\types\entity;
|
||||
|
||||
final class Attribute{
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var float */
|
||||
private $min;
|
||||
/** @var float */
|
||||
private $max;
|
||||
/** @var float */
|
||||
private $current;
|
||||
/** @var float */
|
||||
private $default;
|
||||
|
||||
public function __construct(string $id, float $min, float $max, float $current, float $default){
|
||||
$this->id = $id;
|
||||
$this->min = $min;
|
||||
$this->max = $max;
|
||||
$this->current = $current;
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
public function getId() : string{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMin() : float{
|
||||
return $this->min;
|
||||
}
|
||||
|
||||
public function getMax() : float{
|
||||
return $this->max;
|
||||
}
|
||||
|
||||
public function getCurrent() : float{
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
public function getDefault() : float{
|
||||
return $this->default;
|
||||
}
|
||||
}
|
@ -25,7 +25,6 @@ namespace pocketmine\network\mcpe\serializer;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\item\Durable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
@ -37,6 +36,7 @@ use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\TreeRoot;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\protocol\types\command\CommandOriginData;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\BlockPosMetadataProperty;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\CompoundTagMetadataProperty;
|
||||
@ -362,17 +362,7 @@ class NetworkBinaryStream extends BinaryStream{
|
||||
$default = $this->getLFloat();
|
||||
$id = $this->getString();
|
||||
|
||||
$attr = Attribute::get($id);
|
||||
if($attr !== null){
|
||||
$attr->setMinValue($min);
|
||||
$attr->setMaxValue($max);
|
||||
$attr->setValue($current);
|
||||
$attr->setDefaultValue($default);
|
||||
|
||||
$list[] = $attr;
|
||||
}else{
|
||||
throw new BadPacketException("Unknown attribute type \"$id\"");
|
||||
}
|
||||
$list[] = new Attribute($id, $min, $max, $current, $default);
|
||||
}
|
||||
|
||||
return $list;
|
||||
@ -386,10 +376,10 @@ class NetworkBinaryStream extends BinaryStream{
|
||||
public function putAttributeList(Attribute ...$attributes) : void{
|
||||
$this->putUnsignedVarInt(count($attributes));
|
||||
foreach($attributes as $attribute){
|
||||
$this->putLFloat($attribute->getMinValue());
|
||||
$this->putLFloat($attribute->getMaxValue());
|
||||
$this->putLFloat($attribute->getValue());
|
||||
$this->putLFloat($attribute->getDefaultValue());
|
||||
$this->putLFloat($attribute->getMin());
|
||||
$this->putLFloat($attribute->getMax());
|
||||
$this->putLFloat($attribute->getCurrent());
|
||||
$this->putLFloat($attribute->getDefault());
|
||||
$this->putString($attribute->getId());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user