mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
StandardPacketBroadcaster: Include varint length prefix in length calculation
varints encode 7 bits per byte, so a log with base 128 will tell us how many bytes are required to encode the length of the packet.
This commit is contained in:
parent
337a254768
commit
08ee825d91
@ -30,6 +30,7 @@ use pocketmine\Server;
|
|||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\BinaryStream;
|
use pocketmine\utils\BinaryStream;
|
||||||
use function count;
|
use function count;
|
||||||
|
use function log;
|
||||||
use function spl_object_id;
|
use function spl_object_id;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
|
|
||||||
@ -60,7 +61,8 @@ final class StandardPacketBroadcaster implements PacketBroadcaster{
|
|||||||
$packetBuffers = [];
|
$packetBuffers = [];
|
||||||
foreach($packets as $packet){
|
foreach($packets as $packet){
|
||||||
$buffer = NetworkSession::encodePacketTimed(PacketSerializer::encoder($this->protocolContext), $packet);
|
$buffer = NetworkSession::encodePacketTimed(PacketSerializer::encoder($this->protocolContext), $packet);
|
||||||
$totalLength += strlen($buffer);
|
//varint length prefix + packet buffer
|
||||||
|
$totalLength += (((int) log(strlen($buffer), 128)) + 1) + strlen($buffer);
|
||||||
$packetBuffers[] = $buffer;
|
$packetBuffers[] = $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user