Packet dimensions

Flattr this!

Development has been paused for a while, mostly due to everyone being busy doing other stuff. However, now we are getting back into the swing of things.

Yesterday, I discovered that for some reason, I had decided that it was a good idea to encode a packet’s length in a single byte when I first implemented the game’s networking code.

Clearly, it isn’t. Unless you want to start packing bits to save space (which quite frankly isn’t worth the time and effort), a byte can only represent numbers up to 255. That means packets could only be 255 bytes long. This isn’t very effective, or even practical.

Therefore I decided to use an unsigned short (2 bytes) to encode a packet’s length, and another to encode a packet’s decrypted length (if it is encrypted). This means packets can now be up to 65,025 bytes in length. If I find myself needing to send packets any larger than this, I know I need to redesign the protocol.

Of course, doing this made sure that decoding packets received from the client fucked up. There’s always something. But at least development is back on track.