Avoid useless throwaway PacketBatch objects

This commit is contained in:
Dylan K. Taylor
2023-02-19 16:50:03 +00:00
parent 9cdb641936
commit 2a3288c4f9
2 changed files with 12 additions and 2 deletions

View File

@ -411,7 +411,13 @@ class NetworkSession{
}
try{
foreach((new PacketBatch($decompressed))->getPackets($this->packetPool, $this->packetSerializerContext, 1300) as [$packet, $buffer]){
$stream = new BinaryStream($decompressed);
$count = 0;
foreach(PacketBatch::decodeRaw($stream) as $buffer){
if(++$count > 1300){
throw new PacketHandlingException("Too many packets in batch");
}
$packet = $this->packetPool->getPacket($buffer);
if($packet === null){
$this->logger->debug("Unknown packet: " . base64_encode($buffer));
throw new PacketHandlingException("Unknown packet received");