PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
DisconnectPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
18
20 public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET;
21
22 public int $reason; //TODO: add constants / enum
23 public ?string $message;
24
28 public static function create(int $reason, ?string $message) : self{
29 $result = new self;
30 $result->reason = $reason;
31 $result->message = $message;
32 return $result;
33 }
34
35 public function canBeSentBeforeLogin() : bool{
36 return true;
37 }
38
39 protected function decodePayload(PacketSerializer $in) : void{
40 $this->reason = $in->getVarInt();
41 $hideDisconnectionScreen = $in->getBool();
42 $this->message = $hideDisconnectionScreen ? null : $in->getString();
43 }
44
45 protected function encodePayload(PacketSerializer $out) : void{
46 $out->putVarInt($this->reason);
47 $out->putBool($this->message === null);
48 if($this->message !== null){
49 $out->putString($this->message);
50 }
51 }
52
53 public function handle(PacketHandlerInterface $handler) : bool{
54 return $handler->handleDisconnect($this);
55 }
56}
static create(int $reason, ?string $message)