Skip to content

Networking

Danilo Lemes edited this page Jan 4, 2021 · 2 revisions

Networking is simple.

Inside Net package you will find five main classes:

  • NetworkClient - Holds the current connection and abstract some methods
  • Connection - Handles the TCP connecting itself
  • PacketSerializer - Responsible for handling each byte array we receive and parsing them to the respective PO(C/J)O - Plain Old Java/CLR Object
  • InPacket - Every packet that we receive from servers should implement this interface, in case we don't have a fixed size, the second part of each packet will be its size (the 3rd and 4th bytes)
  • OutPacket - Every packet we send to the server, follow the same principle as the InPacket, every packet that has a variable size, should have its second part as the length/size. Done via ComputeSize method

InPackets are auto registered

Once you create a packet POCO and implement InPacket using the correct PacketHeader and Size the PacketSerializer will pick it up automatically and try calling a registered handler whenever we receive that given packet, in case we don't have any registered handler for that packet, you should see a warning in console.

Note: Sometimes the server sends multiple packets "together"/in a short period of time, and tcp will group them in a single byte array. In such cases if we don't have the first packet implemented we will not be able to see the other packets that came together. It "forces" us to implement each InPacket. However, just creating the class in linking the PacketHeader and Size and returning true is enough to be able to see the remaining packets

Data Types

Emulators send/receive the following types:

  • W: 2 bytes
  • L: 4 bytes
  • B: 1 byte
  • POS: 6 bytes

Which can be roughly translated to

  • W: short
  • L: int
  • B: byte
  • POS: short[]
Clone this wiki locally