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