PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
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
19
26 public const NETWORK_ID = ProtocolInfo::NETWORK_SETTINGS_PACKET;
27
28 public const COMPRESS_NOTHING = 0;
29 public const COMPRESS_EVERYTHING = 1;
30
31 private int $compressionThreshold;
32 private int $compressionAlgorithm;
33 private bool $enableClientThrottling;
34 private int $clientThrottleThreshold;
35 private float $clientThrottleScalar;
36
40 public static function create(int $compressionThreshold, int $compressionAlgorithm, bool $enableClientThrottling, int $clientThrottleThreshold, float $clientThrottleScalar) : self{
41 $result = new self;
42 $result->compressionThreshold = $compressionThreshold;
43 $result->compressionAlgorithm = $compressionAlgorithm;
44 $result->enableClientThrottling = $enableClientThrottling;
45 $result->clientThrottleThreshold = $clientThrottleThreshold;
46 $result->clientThrottleScalar = $clientThrottleScalar;
47 return $result;
48 }
49
50 public function canBeSentBeforeLogin() : bool{
51 return true;
52 }
53
54 public function getCompressionThreshold() : int{
55 return $this->compressionThreshold;
56 }
57
61 public function getCompressionAlgorithm() : int{ return $this->compressionAlgorithm; }
62
63 public function isEnableClientThrottling() : bool{ return $this->enableClientThrottling; }
64
65 public function getClientThrottleThreshold() : int{ return $this->clientThrottleThreshold; }
66
67 public function getClientThrottleScalar() : float{ return $this->clientThrottleScalar; }
68
69 protected function decodePayload(PacketSerializer $in) : void{
70 $this->compressionThreshold = $in->getLShort();
71 $this->compressionAlgorithm = $in->getLShort();
72 $this->enableClientThrottling = $in->getBool();
73 $this->clientThrottleThreshold = $in->getByte();
74 $this->clientThrottleScalar = $in->getLFloat();
75 }
76
77 protected function encodePayload(PacketSerializer $out) : void{
78 $out->putLShort($this->compressionThreshold);
79 $out->putLShort($this->compressionAlgorithm);
80 $out->putBool($this->enableClientThrottling);
81 $out->putByte($this->clientThrottleThreshold);
82 $out->putLFloat($this->clientThrottleScalar);
83 }
84
85 public function handle(PacketHandlerInterface $handler) : bool{
86 return $handler->handleNetworkSettings($this);
87 }
88}
static create(int $compressionThreshold, int $compressionAlgorithm, bool $enableClientThrottling, int $clientThrottleThreshold, float $clientThrottleScalar)