Overview
PacketManager handles the registration and processing of packets in the Ember Client Server API. It maintains a bidirectional mapping between packet IDs and packet classes, and provides methods for serializing and deserializing packets.
Class Definition
Packet Registration
The PacketManager automatically registers all built-in packets with their corresponding IDs:Outgoing Packets (Server to Client)
ID: 1 - Requests the client to register an attestation key
ID: 2 - Requests the client to sign data with their attestation key
Incoming Packets (Client to Server)
ID: 1001 - Response from client with attestation registration result
ID: 1002 - Response from client with signed attestation data
Methods
getData()
Serializes a packet into aByteBufWrapper for transmission.
The packet to serialize
A ByteBufWrapper containing the serialized packet with its ID
This method is primarily used internally by
ECServerAPI.sendPacket(). You typically don’t need to call it directly.handle()
Deserializes and processes an incoming packet from a player.The player who sent the packet
The buffer containing the packet data
- Reads the packet ID from the buffer
- Looks up the corresponding packet class
- Instantiates the packet
- Calls
packet.read(buf)to deserialize data - Calls
packet.handle(player)to process the packet
Packet ID Mapping
The PacketManager uses a bidirectional map (BiMap) to maintain packet ID associations:ID Convention
- Outgoing packets (Server → Client): IDs 1-999
- Incoming packets (Client → Server): IDs 1000+
Internal Structure
Constructor
getPacketId()
Retrieves the packet ID for a given packet instance (private method).Error Handling
- If an unknown packet ID is received, it is silently ignored
- If packet instantiation fails, the exception is printed to console
- Invalid packet data may throw exceptions during
read()operations