Skip to content

Packets

Duncan edited this page Dec 31, 2019 · 3 revisions

TLDR:

The word 'packet' is used in this project to refer to the data structures defined by the Minecraft protocol here, or additions to that protocol used only between Patchwork servers.

Details

All packets have the same set of headers:

imgur link down

The length field indicates the length of the packet, and we use it to separate the TCP data stream into packets which are processed separately in order of arrival. The packet ID indicates the type of packet we've received. Unfortunately, the packet ID alone is not sufficient to determine the structure of the packet. It also needs to be matched with the state of the connection.

Here's an example packet from the protocol:

imgur link down

The fields indicate how to read the packet.

We've defined a macro that allows us to define all the packets as data. When expanded, the code creates a named struct for each packet type with methods that allow us to read from data streams into named fields, and write that struct back into a data stream. Additionally, we define how each field is to be translated. You can find these definitions in packet.rs.

These structs are all a part of the Packet enum, which is how we pass around a generic packet around the service.

Some Relevant Files

Clone this wiki locally