Chronos Documentation

Packet handling

Packet handling was designed to be dynamic, therefore easier to change if need be. All packet handlers should implement the PacketHandler interface and contain the following method:
void handlePacket(PacketContext ctx, Player player)

PacketContext is a class that holds attributes specific to a certain packet. To obtain said attribute, use the following method:

Whereas, ATTRIBUTE_NAME is your attribute. Attributes are set via the packetDef-####.xml file in ./data/packets/.

For example, opcode 14 in login is the session key request. The client sends a single unsigned byte to the server that signifies the "name hash", said to be used for picking which login server to use. The xml markup for this is as follows:
	<packet opcode="14" name="session key request" class="">
		<field type="ubyte">name_hash</field>

To obtain the name hash, we can do this:
int nameHash = (Integer) ctx.getAttribute("name_hash");

NOTE: This should all be done in a class named SessionKeyRequestPacketHandler in package, as specified by the XML markup.
NOTE: Check the PacketManager class for information on casting, DO NOT CAST TO A DIFFERENT CLASS!
NOTE: Do NOT add the opcode in the xml markup, unless there is a sub-opcode that needs to be read!

Last edited May 20, 2010 at 9:01 PM by amherst, version 7


No comments yet.