PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
NetworkSettingsPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
23
30 public const NETWORK_ID = ProtocolInfo::NETWORK_SETTINGS_PACKET;
31
32 public const COMPRESS_NOTHING = 0;
33 public const COMPRESS_EVERYTHING = 1;
34
35 private int $compressionThreshold;
36 private int $compressionAlgorithm;
37 private bool $enableClientThrottling;
38 private int $clientThrottleThreshold;
39 private float $clientThrottleScalar;
40
44 public static function create(int $compressionThreshold, int $compressionAlgorithm, bool $enableClientThrottling, int $clientThrottleThreshold, float $clientThrottleScalar) : self{
45 $result = new self;
46 $result->compressionThreshold = $compressionThreshold;
47 $result->compressionAlgorithm = $compressionAlgorithm;
48 $result->enableClientThrottling = $enableClientThrottling;
49 $result->clientThrottleThreshold = $clientThrottleThreshold;
50 $result->clientThrottleScalar = $clientThrottleScalar;
51 return $result;
52 }
53
54 public function canBeSentBeforeLogin() : bool{
55 return true;
56 }
57
58 public function getCompressionThreshold() : int{
59 return $this->compressionThreshold;
60 }
61
65 public function getCompressionAlgorithm() : int{ return $this->compressionAlgorithm; }
66
67 public function isEnableClientThrottling() : bool{ return $this->enableClientThrottling; }
68
69 public function getClientThrottleThreshold() : int{ return $this->clientThrottleThreshold; }
70
71 public function getClientThrottleScalar() : float{ return $this->clientThrottleScalar; }
72
73 protected function decodePayload(ByteBufferReader $in) : void{
74 $this->compressionThreshold = LE::readUnsignedShort($in);
75 $this->compressionAlgorithm = LE::readUnsignedShort($in);
76 $this->enableClientThrottling = CommonTypes::getBool($in);
77 $this->clientThrottleThreshold = Byte::readUnsigned($in);
78 $this->clientThrottleScalar = LE::readFloat($in);
79 }
80
81 protected function encodePayload(ByteBufferWriter $out) : void{
82 LE::writeUnsignedShort($out, $this->compressionThreshold);
83 LE::writeUnsignedShort($out, $this->compressionAlgorithm);
84 CommonTypes::putBool($out, $this->enableClientThrottling);
85 Byte::writeUnsigned($out, $this->clientThrottleThreshold);
86 LE::writeFloat($out, $this->clientThrottleScalar);
87 }
88
89 public function handle(PacketHandlerInterface $handler) : bool{
90 return $handler->handleNetworkSettings($this);
91 }
92}
static create(int $compressionThreshold, int $compressionAlgorithm, bool $enableClientThrottling, int $clientThrottleThreshold, float $clientThrottleScalar)