protected function processPackets($packet_id, array $packets = [])
    {

        // Init array so we can order
        $packs = [];

        // We have multiple packets so we need to get them and order them
        foreach ($packets as $i => $packet) {
            // Make a buffer so we can read this info
            $buffer = new Buffer($packet);

            // Gold source
            if ($this->source_engine == self::GOLDSOURCE_ENGINE) {
                // Grab the packet number (byte)
                $packet_number = $buffer->readInt8();

                // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                if ($i == 0) {
                    $buffer->read(4);
                }

                // Now add the rest of the packet to the new array with the packet_number as the id so we can order it
                $packs[$packet_number] = $buffer->getBuffer();
            } else {
                // Number of packets in this set (byte)
                $buffer->readInt8();

                // The current packet number (byte)
                $packet_number = $buffer->readInt8();

                // Check to see if this is compressed
                // @todo: Check to make sure these decompress correctly, new changes may affect this loop.
                if ($packet_id & 0x80000000) {
                    // Check to see if we have Bzip2 installed
                    if (!function_exists('bzdecompress')) {
                        // @codeCoverageIgnoreStart
                        throw new Exception(
                            'Bzip2 is not installed.  See http://www.php.net/manual/en/book.bzip2.php for more info.',
                            0
                        );
                        // @codeCoverageIgnoreEnd
                    }

                    // Get the length of the packet (long)
                    $packet_length = $buffer->readInt32Signed();

                    // Checksum for the decompressed packet (long), burn it - doesnt work in split responses
                    $buffer->readInt32Signed();

                    // Try to decompress
                    $result = bzdecompress($buffer->getBuffer());

                    // Now verify the length
                    if (strlen($result) != $packet_length) {
                        // @codeCoverageIgnoreStart
                        throw new Exception(
                            "Checksum for compressed packet failed! Length expected: {$packet_length}, length
                            returned: " . strlen($result)
                        );
                        // @codeCoverageIgnoreEnd
                    }

                    // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                    if ($i == 0) {
                        $result = substr($result, 4);
                    }
                } else {
                    // Get the packet length (short), burn it
                    $buffer->readInt16Signed();

                    // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                    if ($i == 0) {
                        $buffer->read(4);
                    }

                    // Grab the rest of the buffer as a result
                    $result = $buffer->getBuffer();
                }

                // Add this packet to the list
                $packs[$packet_number] = $result;
            }

            unset($buffer);
        }

        // Free some memory
        unset($packets, $packet);

        // Sort the packets by packet number
        ksort($packs);

        // Now combine the packs into one and return
        return implode("", $packs);
    }
protected function processPackets($packet_id, array $packets = [])
    {

        // Init array so we can order
        $packs = [];

        // We have multiple packets so we need to get them and order them
        foreach ($packets as $i => $packet) {
            // Make a buffer so we can read this info
            $buffer = new Buffer($packet);

            // Gold source
            if ($this->source_engine == self::GOLDSOURCE_ENGINE) {
                // Grab the packet number (byte)
                $packet_number = $buffer->readInt8();

                // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                if ($i == 0) {
                    $buffer->read(4);
                }

                // Now add the rest of the packet to the new array with the packet_number as the id so we can order it
                $packs[$packet_number] = $buffer->getBuffer();
            } else {
                // Number of packets in this set (byte)
                $buffer->readInt8();

                // The current packet number (byte)
                $packet_number = $buffer->readInt8();

                // Check to see if this is compressed
                // @todo: Check to make sure these decompress correctly, new changes may affect this loop.
                if ($packet_id & 0x80000000) {
                    // Check to see if we have Bzip2 installed
                    if (!function_exists('bzdecompress')) {
                        // @codeCoverageIgnoreStart
                        throw new Exception(
                            'Bzip2 is not installed.  See http://www.php.net/manual/en/book.bzip2.php for more info.',
                            0
                        );
                        // @codeCoverageIgnoreEnd
                    }

                    // Get the length of the packet (long)
                    $packet_length = $buffer->readInt32Signed();

                    // Checksum for the decompressed packet (long), burn it - doesnt work in split responses
                    $buffer->readInt32Signed();

                    // Try to decompress
                    $result = bzdecompress($buffer->getBuffer());

                    // Now verify the length
                    if (strlen($result) != $packet_length) {
                        // @codeCoverageIgnoreStart
                        throw new Exception(
                            "Checksum for compressed packet failed! Length expected: {$packet_length}, length
                            returned: " . strlen($result)
                        );
                        // @codeCoverageIgnoreEnd
                    }

                    // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                    if ($i == 0) {
                        $result = substr($result, 4);
                    }
                } else {
                    // Get the packet length (short), burn it
                    $buffer->readInt16Signed();

                    // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
                    if ($i == 0) {
                        $buffer->read(4);
                    }

                    // Grab the rest of the buffer as a result
                    $result = $buffer->getBuffer();
                }

                // Add this packet to the list
                $packs[$packet_number] = $result;
            }

            unset($buffer);
        }

        // Free some memory
        unset($packets, $packet);

        // Sort the packets by packet number
        ksort($packs);

        // Now combine the packs into one and return
        return implode("", $packs);
    }
protected function processPackets ( $ packet_id , array $ packets = [ ] ) { // Init array so we can order $ packs = [ ] ; // We have multiple packets so we need to get them and order them foreach ( $ packets as $ i => $ packet ) { // Make a buffer so we can read this info $ buffer = new Buffer ( $ packet ) ; // Gold source if ( $ this -> source_engine == self :: GOLDSOURCE_ENGINE ) { // Grab the packet number (byte) $ packet_number = $ buffer -> readInt8 ( ) ; // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop if ( $ i == 0 ) { $ buffer -> read ( 4 ) ; } // Now add the rest of the packet to the new array with the packet_number as the id so we can order it $ packs [ $ packet_number ] = $ buffer -> getBuffer ( ) ; } else { // Number of packets in this set (byte) $ buffer -> readInt8 ( ) ; // The current packet number (byte) $ packet_number = $ buffer -> readInt8 ( ) ; // Check to see if this is compressed // @todo: Check to make sure these decompress correctly, new changes may affect this loop. if ( $ packet_id & 0x80000000 ) { // Check to see if we have Bzip2 installed if ( ! function_exists ( 'bzdecompress' ) ) { // @codeCoverageIgnoreStart throw new Exception ( 'Bzip2 is not installed.  See http://www.php.net/manual/en/book.bzip2.php for more info.' , 0 ) ; // @codeCoverageIgnoreEnd } // Get the length of the packet (long) $ packet_length = $ buffer -> readInt32Signed ( ) ; // Checksum for the decompressed packet (long), burn it - doesnt work in split responses $ buffer -> readInt32Signed ( ) ; // Try to decompress $ result = bzdecompress ( $ buffer -> getBuffer ( ) ) ; // Now verify the length if ( strlen ( $ result ) != $ packet_length ) { // @codeCoverageIgnoreStart throw new Exception ( "Checksum for compressed packet failed! Length expected: {$packet_length}, length
                            returned: " . strlen ( $ result ) ) ; // @codeCoverageIgnoreEnd } // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop if ( $ i == 0 ) { $ result = substr ( $ result , 4 ) ; } } else { // Get the packet length (short), burn it $ buffer -> readInt16Signed ( ) ; // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop if ( $ i == 0 ) { $ buffer -> read ( 4 ) ; } // Grab the rest of the buffer as a result $ result = $ buffer -> getBuffer ( ) ; } // Add this packet to the list $ packs [ $ packet_number ] = $ result ; } unset ( $ buffer ) ; } // Free some memory unset ( $ packets , $ packet ) ; // Sort the packets by packet number ksort ( $ packs ) ; // Now combine the packs into one and return return implode ( "" , $ packs ) ; }
Process the split packets and decompress if necessary

@SuppressWarnings(PHPMD.UnusedLocalVariable)

@param       $packet_id
@param array $packets

@return string
@throws \GameQ\Exception\Protocol
Process the split packets and decompress if necessary