| Constructor and Description |
|---|
PacketProtocol() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearPackets()
Clears all currently registered packets.
|
Packet |
createIncomingPacket(int id,
NetInput in)
Creates a new instance of an incoming packet with the given id and read the incoming input.
|
Packet |
createOutgoingPacket(int id,
NetInput in)
Creates a new instance of an outgoing packet with the given id and read the outgoing input.
|
abstract PacketEncryption |
getEncryption()
Gets this protocol's active packet encryption.
|
Class<? extends Packet> |
getOutgoingClass(int id)
Gets the packet class for a packet id.
|
int |
getOutgoingId(Class<? extends Packet> packetClass)
Gets the registered id of an outgoing packet class.
|
int |
getOutgoingId(Packet packet)
Gets the registered id of an outgoing
Packet instance. |
abstract PacketHeader |
getPacketHeader()
Gets the packet header of this protocol.
|
abstract String |
getSRVRecordPrefix()
Gets the prefix used when locating SRV records for this protocol.
|
abstract void |
newClientSession(Session session)
Called when a client session is created with this protocol.
|
abstract void |
newServerSession(Server server,
Session session)
Called when a server session is created with this protocol.
|
<T extends Packet> |
register(int id,
Class<T> packet,
PacketFactory<T> factory)
Registers a packet to this protocol as both incoming and outgoing.
|
void |
register(PacketDefinition<? extends Packet> definition)
Registers a packet to this protocol as both incoming and outgoing.
|
<T extends Packet> |
registerIncoming(int id,
Class<T> packet,
PacketFactory<T> factory)
Registers an incoming packet to this protocol.
|
void |
registerIncoming(PacketDefinition<? extends Packet> definition)
Registers an incoming packet to this protocol.
|
<T extends Packet> |
registerOutgoing(int id,
Class<T> packet,
PacketFactory<T> factory)
Registers an outgoing packet to this protocol.
|
void |
registerOutgoing(PacketDefinition<? extends Packet> definition)
Registers an outgoing packet to this protocol.
|
public abstract String getSRVRecordPrefix()
public abstract PacketHeader getPacketHeader()
public abstract PacketEncryption getEncryption()
public abstract void newClientSession(Session session)
session - The created session.public abstract void newServerSession(Server server, Session session)
server - The server that the session belongs to.session - The created session.public final void clearPackets()
public final <T extends Packet> void register(int id, Class<T> packet, PacketFactory<T> factory)
id - Id to register the packet to.packet - Packet to register.factory - The packet factory.IllegalArgumentException - If the packet fails a test creation when being registered as incoming.public final void register(PacketDefinition<? extends Packet> definition)
definition - The packet definition.IllegalArgumentException - If the packet fails a test creation when being registered as incoming.public final <T extends Packet> void registerIncoming(int id, Class<T> packet, PacketFactory<T> factory)
id - Id to register the packet to.packet - Packet to register.factory - The packet factory.IllegalArgumentException - If the packet fails a test creation.public final void registerIncoming(PacketDefinition<? extends Packet> definition)
definition - The packet definition.public final <T extends Packet> void registerOutgoing(int id, Class<T> packet, PacketFactory<T> factory)
id - Id to register the packet to.packet - Packet to register.factory - The packet factory.public final void registerOutgoing(PacketDefinition<? extends Packet> definition)
definition - The packet definition.public final Packet createIncomingPacket(int id, NetInput in) throws IOException
id - Id of the packet to create.IOException - if there was an IO error whilst reading the packet.IllegalArgumentException - If the packet ID is not registered.public final Packet createOutgoingPacket(int id, NetInput in) throws IOException
id - Id of the packet to create.IOException - if there was an IO error whilst reading the packet.IllegalArgumentException - If the packet ID is not registered.public final int getOutgoingId(Class<? extends Packet> packetClass)
packetClass - Class of the packet to get the id for.IllegalArgumentException - If the packet is not registered.public final int getOutgoingId(Packet packet)
Packet instance.packet - Instance of Packet to get the id for.IllegalArgumentException - If the packet is not registered.public final Class<? extends Packet> getOutgoingClass(int id)
id - The packet id.IllegalArgumentException - If the packet ID is not registered.Copyright © 2021. All rights reserved.