0
0
mirror of https://github.com/pmmp/BedrockProtocol.git synced 2025-08-11 09:12:55 +00:00
Files
BedrockProtocol/src/DisconnectPacket.php
2022-01-10 21:21:59 +00:00

55 lines
1.4 KiB
PHP

<?php
/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol 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.
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
class DisconnectPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET;
public ?string $message;
/**
* @generate-create-func
*/
public static function create(?string $message) : self{
$result = new self;
$result->message = $message;
return $result;
}
public function canBeSentBeforeLogin() : bool{
return true;
}
protected function decodePayload(PacketSerializer $in) : void{
$hideDisconnectionScreen = $in->getBool();
if(!$hideDisconnectionScreen){
$this->message = $in->getString();
}
}
protected function encodePayload(PacketSerializer $out) : void{
$out->putBool($this->message === null);
if($this->message !== null){
$out->putString($this->message);
}
}
public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleDisconnect($this);
}
}