PacketDefinition
PackedDefinition is serialization template class which derives from PacketBase.
PacketDefinition consists of:
The PacketHeader is always set as Attribute of the PacketDefinition, it is neccessary to unique identify the packet for triggering PacketHandler methods or serializing packets.
[PacketHeader("walk")]
public class WalkPacket : PacketBase
Indicates the index of the serialized Property in the string excluding the PacketHeader.
Example: WalkPacket "walk 22 10 1 2" PacketIndex 0 is x (22), PacketIndex 1 is y (10).
[PacketIndex(0)]
public short XCoordinate { get; set; }
[PacketIndex(1)]
public short YCoordinate { get; set; }
Property in PacketDefinition is one of the basics of our logic, as often we need to use lists of items and amount of them.
Depending on the size of the value, we can use Byte, Short, Int32, Int64 as Property type for Packet-Definition. Byte: 0-255 (NON NULLABLE) Byte?: -1-255 (NULLABLE)
[PacketIndex(3)]
public byte Speed { get; set; }
To specify of which type a Packet is, we use Enum. After defining it in the Domain project, we can simple use it. It must derive from a number type (byte, short, int). It will be serialized to it's number value and not to it's string value.
[PacketIndex(1)]
public CharacterOptionType CharacterOption { get; set; }
- PacketBase without ReturnPacket ONLY WORKS ON SERIALIZATION
- Serialization and Deserialization of sub-packets just by splitting it by space or '^'. PacketBase can be used with the ReturnPackets flag which is defined in the ExtendedPacketDefinition.
- Example: "packetheader 1 2 3 4 3 115 1 11 -1 2 1", this is an example packet where the part 3 115 1 11 is a PacketBase value on index 4.
[PacketIndex(4)]
public WalkPacket Walk { get; set; }
If a Value can only be 0 or 1, we use a boolean in PacketDefinition.
[PacketIndex(3)]
public bool IsAdmin { get; set; }
- Serialization and Deserialization of sub-packet list to simple list of specified type: "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.340.0.0.0 4.340.0.0.0 5.340.0.0.0 6.340.0.0.0 7.340.0.0.0"
- Example: "0.4903.5.0.0 2.340.0.0.0 3.340.0.0.0 4.340.0.0.0 5.340.0.0.0 6.340.0.0.0 7.340.0.0.0" -> List<EquipSubPacket>
[PacketIndex(2)]
public List<EquipSubPacket> EquipEntries { get; set; }
where EquipSubPacket is:
[PacketHeader("sub_equipment")]
public class EquipSubPacket : PacketBase
{
// Properties
}
- Serialization and Deserialization of sub-packet list separated by spaces. Example: "in 1 Character - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1" -> List<short?>, if anything in the list can be -1 the generic list type must be a nullable.
[PacketIndex(12)]
public List<short?> CharacterEquipment { get; set; }
All this features are possible through the PacketDefintion which is a class deriving from PacketBase. If you want to know something about ReturnPacket, SerializeToEnd or Generics, take a look at the Extended Packet-Definitions.