Packets¶
Pending rewrite of this page
This page will be rewritten in the near future and split it into multiple pages for the individual game states, with the play state possibly being subdivided into even more pages. Currently, this page shows all implemented packets in mcproto. This split will happen once play state packets are introduced.
Base classes and interaction functions¶
mcproto.packets.Packet
¶
mcproto.packets.PacketDirection
¶
mcproto.packets.async_read_packet
async
¶
async_read_packet(reader: BaseAsyncReader, packet_map: Mapping[int, type[T_Packet]], *, compression_threshold: int = -1) -> T_Packet
Read a packet.
:param reader: The connection/reader to receive this packet from. :param packet_map: A mapping of packet id (number) -> Packet (class).
This mapping should contain all of the packets for the current gamestate and direction.
See :func:`~mcproto.packets.packet_map.generate_packet_map`
:param compression_threshold: A threshold packet length, whcih if crossed compression should be enabled.
You can get this number from :class:`~mcproto.packets.login.login.LoginSetCompression` packet.
If this packet wasn't sent by the server, set this to -1 (default).
Note that during reading, we don't actually need to know the specific threshold, just
whether or not is is non-negative (whether compression is enabled), as the packet format
fundamentally changes when it is. That means you can pass any positive number here to
enable compresison, regardess of what it actually is.
mcproto.packets.async_write_packet
async
¶
async_write_packet(writer: BaseAsyncWriter, packet: Packet, *, compression_threshold: int = -1) -> None
Write given packet
.
:param writer: The connection/writer to send this packet to. :param packet: The packet to be sent. :param compression_threshold: A threshold packet length, whcih if crossed compression should be enabled.
You can get this number from :class:`~mcproto.packets.login.login.LoginSetCompression` packet.
If this packet wasn't sent by the server, set this to -1 (default).
mcproto.packets.generate_packet_map
cached
¶
Dynamically generated a packet map for given direction
and state
.
This generation is done by dynamically importing all of the modules containing these packets, filtering them to only contain those pacekts with the specified parameters, and storing those into a dictionary, using the packet id as key, and the packet class itself being the value.
As this fucntion is likely to be called quite often, and it uses dynamic importing to obtain the packet classes, this function is cached, which means the logic only actually runs once, after which, for the same arguments, the same dict will be returned.
mcproto.packets.sync_read_packet
¶
sync_read_packet(reader: BaseSyncReader, packet_map: Mapping[int, type[T_Packet]], *, compression_threshold: int = -1) -> T_Packet
Read a packet.
:param reader: The connection/reader to receive this packet from. :param packet_map: A mapping of packet id (number) -> Packet (class).
This mapping should contain all of the packets for the current gamestate and direction.
See :func:`~mcproto.packets.packet_map.generate_packet_map`
:param compression_threshold: A threshold packet length, whcih if crossed compression should be enabled.
You can get this number from :class:`~mcproto.packets.login.login.LoginSetCompression` packet.
If this packet wasn't sent by the server, set this to -1 (default).
Note that during reading, we don't actually need to know the specific threshold, just
whether or not is is non-negative (whether compression is enabled), as the packet format
fundamentally changes when it is. That means you can pass any positive number here to
enable compresison, regardess of what it actually is.
mcproto.packets.sync_write_packet
¶
sync_write_packet(writer: BaseSyncWriter, packet: Packet, *, compression_threshold: int = -1) -> None
Write given packet
.
:param writer: The connection/writer to send this packet to. :param packet: The packet to be sent. :param compression_threshold: A threshold packet length, whcih if crossed compression should be enabled.
You can get this number from :class:`~mcproto.packets.login.login.LoginSetCompression` packet.
If this packet wasn't sent by the server, set this to -1 (default).
Handshaking gamestate¶
mcproto.packets.handshaking.handshake.Handshake
¶
Bases: ServerBoundPacket
Initializes connection between server and client. (Client -> Server).
Initialize the Handshake packet.
:param protocol_version: Protocol version number to be used. :param server_address: The host/address the client is connecting to. :param server_port: The port the client is connecting to. :param next_state: The next state for the server to move into.
Status gamestate¶
mcproto.packets.status.ping.PingPong
¶
Bases: ClientBoundPacket
, ServerBoundPacket
Ping request/Pong response (Server <-> Client).
Initialize the PingPong packet.
:param payload: Random number to test out the connection. Ideally, this number should be quite big, however it does need to fit within the limit of a signed long long (-2 ** 63 to 2 ** 63 - 1).
mcproto.packets.status.status.StatusRequest
¶
Bases: ServerBoundPacket
Request from the client to get information on the server. (Client -> Server).
mcproto.packets.status.status.StatusResponse
¶
Bases: ClientBoundPacket
Response from the server to requesting client with status data information. (Server -> Client).
Initialize the StatusResponse packet.
:param data: JSON response data sent back to the client.
Login gamestate¶
mcproto.packets.login.login.LoginDisconnect
¶
Bases: ClientBoundPacket
Sent by the server to kick a player while in the login state. (Server -> Client).
Initialize the LoginDisconnect packet.
:param reason: The reason for disconnection (kick).
mcproto.packets.login.login.LoginEncryptionRequest
¶
Bases: ClientBoundPacket
Used by the server to ask the client to encrypt the login process. (Server -> Client).
Initialize the LoginEncryptionRequest packet.
:param public_key: Server's public key. :param verify_token: Sequence of random bytes generated by server for verification. :param server_id: Empty on minecraft versions 1.7.X and higher (20 random chars pre 1.7).
mcproto.packets.login.login.LoginEncryptionResponse
¶
Bases: ServerBoundPacket
Response from the client to :class:LoginEncryptionRequest
packet. (Client -> Server).
Initialize the LoginEncryptionResponse packet.
:param shared_secret: Shared secret value, encrypted with server's public key. :param verify_token: Verify token value, encrypted with same public key.
mcproto.packets.login.login.LoginPluginRequest
¶
Bases: ClientBoundPacket
Sent by the server to implement a custom handshaking flow. (Server -> Client).
Initialize the LoginPluginRequest.
:param message_id: Message id, generated by the server, should be unique to the connection. :param channel: Channel identifier, name of the plugin channel used to send data. :param data: Data that is to be sent.
mcproto.packets.login.login.LoginPluginResponse
¶
Bases: ServerBoundPacket
Response to LoginPluginRequest from client. (Client -> Server).
Initialize the LoginPluginRequest packet.
:param message_id: Message id, generated by the server, should be unique to the connection. :param data: Optional response data, present if client understood request.
mcproto.packets.login.login.LoginSetCompression
¶
Bases: ClientBoundPacket
Sent by the server to specify whether to use compression on future packets or not (Server -> Client).
Initialize the LoginSetCompression packet.
:param threshold: Maximum size of a packet before it is compressed. All packets smaller than this will remain uncompressed. To disable compression completely, threshold can be set to -1.
.. note:: This packet is optional, and if not set, the compression will not be enabled at all.
mcproto.packets.login.login.LoginStart
¶
Bases: ServerBoundPacket
Packet from client asking to start login process. (Client -> Server).
Initialize the LoginStart packet.
:param username: Username of the client who sent the request.
:param uuid: UUID of the player logging in (if the player doesn't have a UUID, this can be None
)
mcproto.packets.login.login.LoginSuccess
¶
Bases: ClientBoundPacket
Sent by the server to denote a successful login. (Server -> Client).
Initialize the LoginSuccess packet.
:param uuid: The UUID of the connecting player/client. :param username: The username of the connecting player/client.
Play gamestate¶
Work In Progress
Packets for the Play gamestate aren't yet implemented.