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:
Dylan K. Taylor 2023-03-15 22:41:19 +00:00
parent 337a254768
commit 08ee825d91
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -30,6 +30,7 @@ use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\utils\BinaryStream;
use function count;
use function log;
use function spl_object_id;
use function strlen;
@ -60,7 +61,8 @@ final class StandardPacketBroadcaster implements PacketBroadcaster{
$packetBuffers = [];
foreach($packets as $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;
}