Unencoding data from login packet

Viewed 23

Creating a server for Minecraft. Protocol is documented here: https://wiki.vg/Bedrock_Protocol I'm trying to decode the login packet. https://wiki.vg/Bedrock_Protocol#Login I understand the ID is the first byte, the Protocol version is the next 4 bytes, but how do I find Chain data and Skin data in Python?

Current code:

packet/login.py https://www.toptal.com/developers/hastebin/ovoxuyavax.py

from packet import *
import struct


class Login_Packet(Packet):
    """
    A login packet sent from the client.
    """

    def __init__(self, original_bytes: bytes):
        super().__init__(original_bytes)
        if self.id != b'\x01':
            raise IncorrectPacketID(f"Expected packet with ID 48, not {self.id}")

    def get_protocol_version(self):
        return struct.unpack('i', self.data[:4])

    def get_chain_data(self):
        pass # What do I do here?

packet/packet.py https://www.toptal.com/developers/hastebin/hamecazude.py

class Packet(object):
    def __init__(self, original_bytes: bytes):
        self.original_bytes = original_bytes
        self.id = original_bytes[0:1]
        self.data = original_bytes[1:]


class IncorrectPacketID(Exception):
    pass

packet/init.py imports all from login.py and packet.py

main.py https://www.toptal.com/developers/hastebin/hucedupare.py

import packet

# Example login packet:
login = (b'\x01\x00\x00\x00\x00 )\x18K\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x124Vx\x97e:\x82\x90\x01\xef\xc5')
login_packet = packet.Login_Packet(login)
print(login_packet.get_protocol_version()) # (0,)

Any help is appreciated.

0 Answers
Related