mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
add encode/decode for some new packets
This commit is contained in:
parent
ba39327b28
commit
7fcd40df15
@ -27,15 +27,49 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
|
||||
class AnvilDamagePacket extends DataPacket{
|
||||
class AnvilDamagePacket extends DataPacket/* implements ServerboundPacket*/{
|
||||
public const NETWORK_ID = ProtocolInfo::ANVIL_DAMAGE_PACKET;
|
||||
|
||||
/** @var int */
|
||||
private $x;
|
||||
/** @var int */
|
||||
private $y;
|
||||
/** @var int */
|
||||
private $z;
|
||||
/** @var int */
|
||||
private $damageAmount;
|
||||
|
||||
public static function create(int $x, int $y, int $z, int $damageAmount) : self{
|
||||
$result = new self;
|
||||
[$result->x, $result->y, $result->z] = [$x, $y, $z];
|
||||
$result->damageAmount = $damageAmount;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getDamageAmount() : int{
|
||||
return $this->damageAmount;
|
||||
}
|
||||
|
||||
public function getX() : int{
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
public function getY() : int{
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
public function getZ() : int{
|
||||
return $this->z;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->damageAmount = $this->getByte();
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putByte($this->damageAmount);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
@ -27,15 +27,52 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
|
||||
class EmotePacket extends DataPacket{
|
||||
class EmotePacket extends DataPacket/* implements ClientboundPacket, ServerboundPacket*/{
|
||||
public const NETWORK_ID = ProtocolInfo::EMOTE_PACKET;
|
||||
|
||||
private const FLAG_SERVER = 1 << 0;
|
||||
|
||||
/** @var int */
|
||||
private $entityRuntimeId;
|
||||
/** @var string */
|
||||
private $emoteId;
|
||||
/** @var int */
|
||||
private $flags;
|
||||
|
||||
public static function create(int $entityRuntimeId, string $emoteId, int $flags) : self{
|
||||
$result = new self;
|
||||
$result->entityRuntimeId = $entityRuntimeId;
|
||||
$result->emoteId = $emoteId;
|
||||
$result->flags = $flags;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: we can't call this getEntityRuntimeId() because of base class collision (crap architecture, thanks Shoghi)
|
||||
* @return int
|
||||
*/
|
||||
public function getEntityRuntimeIdField() : int{
|
||||
return $this->entityRuntimeId;
|
||||
}
|
||||
|
||||
public function getEmoteId() : string{
|
||||
return $this->emoteId;
|
||||
}
|
||||
|
||||
public function getFlags() : int{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->entityRuntimeId = $this->getEntityRuntimeId();
|
||||
$this->emoteId = $this->getString();
|
||||
$this->flags = $this->getByte();
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putEntityRuntimeId($this->entityRuntimeId);
|
||||
$this->putString($this->emoteId);
|
||||
$this->putByte($this->flags);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
@ -27,15 +27,31 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
|
||||
class NetworkSettingsPacket extends DataPacket{
|
||||
class NetworkSettingsPacket extends DataPacket/* implements ClientboundPacket*/{
|
||||
public const NETWORK_ID = ProtocolInfo::NETWORK_SETTINGS_PACKET;
|
||||
|
||||
public const COMPRESS_NOTHING = 0;
|
||||
public const COMPRESS_EVERYTHING = 1;
|
||||
|
||||
/** @var int */
|
||||
private $compressionThreshold;
|
||||
|
||||
public static function create(int $compressionThreshold) : self{
|
||||
$result = new self;
|
||||
$result->compressionThreshold = $compressionThreshold;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCompressionThreshold() : int{
|
||||
return $this->compressionThreshold;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->compressionThreshold = $this->getLShort();
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putLShort($this->compressionThreshold);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
@ -27,15 +27,37 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
|
||||
class SettingsCommandPacket extends DataPacket{
|
||||
class SettingsCommandPacket extends DataPacket/* implements ServerboundPacket*/{
|
||||
public const NETWORK_ID = ProtocolInfo::SETTINGS_COMMAND_PACKET;
|
||||
|
||||
/** @var string */
|
||||
private $command;
|
||||
/** @var bool */
|
||||
private $suppressOutput;
|
||||
|
||||
public static function create(string $command, bool $suppressOutput) : self{
|
||||
$result = new self;
|
||||
$result->command = $command;
|
||||
$result->suppressOutput = $suppressOutput;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCommand() : string{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
public function getSuppressOutput() : bool{
|
||||
return $this->suppressOutput;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->command = $this->getString();
|
||||
$this->suppressOutput = $this->getBool();
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putString($this->command);
|
||||
$this->putBool($this->suppressOutput);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
@ -27,15 +27,44 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
|
||||
class TickSyncPacket extends DataPacket{
|
||||
class TickSyncPacket extends DataPacket/* implements ClientboundPacket, ServerboundPacket*/{
|
||||
public const NETWORK_ID = ProtocolInfo::TICK_SYNC_PACKET;
|
||||
|
||||
/** @var int */
|
||||
private $clientSendTime;
|
||||
/** @var int */
|
||||
private $serverReceiveTime;
|
||||
|
||||
public static function request(int $clientTime) : self{
|
||||
$result = new self;
|
||||
$result->clientSendTime = $clientTime;
|
||||
$result->serverReceiveTime = 0; //useless
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function response(int $clientSendTime, int $serverReceiveTime) : self{
|
||||
$result = new self;
|
||||
$result->clientSendTime = $clientSendTime;
|
||||
$result->serverReceiveTime = $serverReceiveTime;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getClientSendTime() : int{
|
||||
return $this->clientSendTime;
|
||||
}
|
||||
|
||||
public function getServerReceiveTime() : int{
|
||||
return $this->serverReceiveTime;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->clientSendTime = $this->getLLong();
|
||||
$this->serverReceiveTime = $this->getLLong();
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putLLong($this->clientSendTime);
|
||||
$this->putLLong($this->serverReceiveTime);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
Loading…
x
Reference in New Issue
Block a user