Skip to content

Technical: Packets: Command Packet

Tom Anderson edited this page Feb 10, 2023 · 2 revisions

With the exception of the ACK packet, every Avara Packet contains 1 or more Command Packets which are packets each with a single command in them. In order to keep the command packet as compact as possible, the presence of many of the fields is indicated by the flags variable. Thus the Command Packet structure is quite variable. Here is what the Command Packet structure looks like:

Field Type Required Description
serialNumber int16 Yes Sequential number that increases by 2 for every new command packet sent out.
sendCount uint8 Yes Number of times this message has been sent before. Zero indicates this is the first try sending this command packet. This is used by the receiver to determine how often the first packet was lost or received out of order.
flags uint8 Yes Bit-mask of 8 flags that indicate which other fields are being sent.
command int8 Yes Command identifier. See Commands for more information.
distribution int16 flags & 0x40 Bit-mask indicating which clients should receive this packet. For example, the server always has an ID of 0 so if you want a message to go to the server then the distribution would be 0x0001. This field suggests an upper limit of 16 players is technically possible even though it might not be viable.
p3 int32 or uint16 flags & 0x24 General purpose variable used for different things by different commands. If the flags & 0x04 is set then it will be of type int32. If flags & 0x20 is set then it is a smaller uint16 field. If neither of those flags is set then this field is not present in the packet.
p2 int16 flags & 0x02 General purpose variable used for different things by different commands. If the flags & 0x02 then this field is present in the packet.
dataLen int16 or int8 flags & 0x18 Length of the dataBuffer in bytes. If the flags & 0x08 is set then it will be of type int16. If flags & 0x10 is set then it is a smaller int8 field. If neither of those flags is set then this field is not present in the packet.
p1 int16 flags & 0x01 General purpose variable used for different things by different commands. If the flags & 0x01 then this field is present in the packet.
sender int8 flags & 0x80 The ID of the sender. The server always has an ID of 0 the client/players have IDs from 1 to kMaxAvaraPlayers. Often in the code you will see code like this (1 << myId) to convert a player's zero-based ID to a distribution list for that player.
dataBuffer int8[dataLen] flags & 0x18 A buffer of extra data that doesn't fit in the p1, p2, p3 variables.