Questions about packet format

Do you want to help out with Freeciv development? Then check out this forum.
Post Reply
Elefant
Hardened
Posts: 245
Joined: Sat May 28, 2022 3:55 am

Questions about packet format

Post by Elefant »

I'm trying to write a python interface for the freeciv server, and I'm having trouble understanding the packet formats.
This packet is able to trick the server into thinking a client is trying to connect:

Code: Select all

\x00T\x04username\x00+Freeciv-3.1-network city-original rsdesc32 obsinv ids32\x00\x00\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x03
and here is the packets.def definition for it:

Code: Select all

PACKET_SERVER_JOIN_REQ = 4; cs, dsend, no-delta, no-handle
  STRING username[48];
  STRING capability[512];
  STRING version_label[48];
  UINT32 major_version, minor_version, patch_version;
end
A few questions:
What does the \x00T at the beginning mean?
I am assuming that 04username is the packet number and the username string.
Why, then, is the username string shorter than 48 characters?
Also, why aren't they separate?
The next chunk is obviously the capability string.
Why is the version_label string empty?
Also, there are 5 x00 blocks between capability and major_version. I am assuming that each block is a byte, in hexadecimal. So then, three are the most significant three bytes of major_version, and one would be the empty version_label. What is the last one for?
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
cazfi
Elite
Posts: 3395
Joined: Tue Jan 29, 2013 6:54 pm

Re: Questions about packet format

Post by cazfi »

See README.delta.
Elefant wrote: Tue Sep 16, 2025 8:43 pmWhat does the \x00T at the beginning mean?
I think that's the two byte length of the packet (to know where's the boundary between packets) ASCII "T" = 84.
Elefant wrote: Tue Sep 16, 2025 8:43 pmI am assuming that 04username is the packet number and the username string.
Why, then, is the username string shorter than 48 characters?
It's transferred NULL-terminated, i.e., the \x00 terminates it.
Elefant wrote: Tue Sep 16, 2025 8:43 pmAlso, why aren't they separate?
What do you mean? Hmm... Note that it was \x04, and not "04" like you wrote.

One complication is that historically packet type was 8bit value, and for that reason it's just one byte in these initial packets. But as soon as the server and the client have established that the other party is new enough to understand 16bit type fields, the following packets will use 2 bytes for the type.
Elefant wrote: Tue Sep 16, 2025 8:43 pmThe next chunk is obviously the capability string.
Why is the version_label string empty?
Because you are using a version that has no version label?
Elefant wrote: Tue Sep 16, 2025 8:43 pmAlso, there are 5 x00 blocks between capability and major_version. I am assuming that each block is a byte, in hexadecimal. So then, three are the most significant three bytes of major_version, and one would be the empty version_label. What is the last one for?
First one terminates capability string.
Post Reply