1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved RakLib::EncapsulatedPacket how to create

Discussion in 'Development' started by gistrec, May 14, 2018.

  1. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    Hi all
    I changed a bit RakLib to Server and Client side, because I would like to do transfer without TransferPacket

    And I have LoginPacket buffer on server-side raklib
    Q: how can I create EncapsulatedPacket with LP buffer?

    As I reed:
    PHP:
        /*
         * These internal "packets" DO NOT exist in the RakNet protocol. They are used by the RakLib API to communicate
         * messages between the RakLib thread and the implementation's thread.
         *
         * Internal Packet:
         * int32 (length without this field)
         * byte (packet ID)
         * payload
         */
        /*
         * ENCAPSULATED payload:
         * byte (identifier length)
         * byte[] (identifier)
         * byte (flags, last 3 bits, priority)
         * payload (binary internal EncapsulatedPacket)
         */
        
    public const PACKET_ENCAPSULATED 0x01;

    I.e:
    PHP:
    create(pocketmine\network\mcpe\protocol\LoginPacket $bufferstring $playerAddressint $playerPort) {
        
    // Internal packet header
        
    $pk chr(RakLib::ENCAPSULATED); // byte (packet ID)
        // Internal packet payload
        
    $pk .= chr(4); // byte (identifier length - 4 bytes or 6 bytes (do I need to add 2 bytes - port length?))
        
    $parts explode("."$playerAddress);
        
    assert(count($parts) === 4"Wrong number of parts in IPv4 IP, expected 4, got " count($parts));
        foreach(
    $parts as $b){
            
    $pk .= chr((~((int) $b)) & 0xff); // byte[] (identifier)
        
    }
        
    $pk .= pack("n"$playerPort); // port (16-bit big-endian number)
        
    $pk .= PacketReliability::UNRELIABLE;
        
        
    $pk .= $buffer;
        return 
    $pk;
    }
    Where is the mistake? :(:(:(
     
  2. gistrec

    gistrec Witch

    Messages:
    68
    GitHub:
    gistrec
    I think, that it will be easier to create new internal packet :) :)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.