PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
PacketViolationWarningPacket.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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21
23 public const NETWORK_ID = ProtocolInfo::PACKET_VIOLATION_WARNING_PACKET;
24
25 public const TYPE_MALFORMED = 0;
26
27 public const SEVERITY_WARNING = 0;
28 public const SEVERITY_FINAL_WARNING = 1;
29 public const SEVERITY_TERMINATING_CONNECTION = 2;
30
31 private int $type;
32 private int $severity;
33 private int $packetId;
34 private string $message;
35
39 public static function create(int $type, int $severity, int $packetId, string $message) : self{
40 $result = new self;
41 $result->type = $type;
42 $result->severity = $severity;
43 $result->packetId = $packetId;
44 $result->message = $message;
45 return $result;
46 }
47
48 public function getType() : int{ return $this->type; }
49
50 public function getSeverity() : int{ return $this->severity; }
51
52 public function getPacketId() : int{ return $this->packetId; }
53
54 public function getMessage() : string{ return $this->message; }
55
56 protected function decodePayload(ByteBufferReader $in) : void{
57 $this->type = VarInt::readSignedInt($in);
58 $this->severity = VarInt::readSignedInt($in);
59 $this->packetId = VarInt::readSignedInt($in);
60 $this->message = CommonTypes::getString($in);
61 }
62
63 protected function encodePayload(ByteBufferWriter $out) : void{
64 VarInt::writeSignedInt($out, $this->type);
65 VarInt::writeSignedInt($out, $this->severity);
66 VarInt::writeSignedInt($out, $this->packetId);
67 CommonTypes::putString($out, $this->message);
68 }
69
70 public function handle(PacketHandlerInterface $handler) : bool{
71 return $handler->handlePacketViolationWarning($this);
72 }
73}
static create(int $type, int $severity, int $packetId, string $message)