48 if($ev->isCancelled()){
51 $packets = $ev->getPackets();
56 $targetsByCompressor = [];
57 foreach($recipients as $recipient){
59 $compressor = $recipient->getCompressor();
60 $compressors[spl_object_id($compressor)] = $compressor;
62 $targetsByCompressor[spl_object_id($compressor)][] = $recipient;
67 foreach($packets as $packet){
68 $buffer = NetworkSession::encodePacketTimed(PacketSerializer::encoder(), $packet);
70 $totalLength += (((int) log(strlen($buffer), 128)) + 1) + strlen($buffer);
71 $packetBuffers[] = $buffer;
74 foreach($targetsByCompressor as $compressorId => $compressorTargets){
75 $compressor = $compressors[$compressorId];
77 $threshold = $compressor->getCompressionThreshold();
78 if(count($compressorTargets) > 1 && $threshold !==
null && $totalLength >= $threshold){
80 $stream =
new BinaryStream();
81 PacketBatch::encodeRaw($stream, $packetBuffers);
82 $batchBuffer = $stream->getBuffer();
84 $batch = $this->
server->prepareBatch($batchBuffer, $compressor, timings: Timings::$playerNetworkSendCompressBroadcast);
85 foreach($compressorTargets as $target){
86 $target->queueCompressed($batch);
89 foreach($compressorTargets as $target){
90 foreach($packetBuffers as $packetBuffer){
91 $target->addToSendBuffer($packetBuffer);