* TODO: Response length field needs further testing. At least bytes 2 and 3 belong to it, but I have not seen a clear confirmation of 4 and 5 also belonging to it. I tested it with trying to transfer big map files, but they might be compressed for transfer (message begins with "fI" instead of "fH") and the map file transfers I tried failed with the receiving end crashing. * Packet types ** General So far I have seen the first two bytes of the messages be either "fH" or "fI". The latter seems to be used with turn data related messages and might indicate a compressed message body (length of message is less than the size of the corresponding file on disk). Bytes 3-6 are a little-endian 32bit integer telling how many more bytes the message contains after it. So for example in the general info and mod list requests, it's value is 1. 7th byte looks like a message type. Values seen so far: 0x01 client probably "I am playing these nations" 0x02 server no body reply to 0x01 0x03 client no body request general info 0x04 server general info 0x05 client no body probably "Which nations are in the game?" 0x06 server reply to 0x05 0x07 client turn file request 0x0b client no body bye 0x0c server no body bye 0x0d client map file request 0x11 client no body request mod list 0x12 server mod list 0x34 client pretender upload 0x36 client start game ** General info response, 0x04 There are some bytes I don't know the meaning of yet (no variation seen so far) after the type code: 0x23, 0x01, 0x00, 0x00 Byte 12 might be game state code: 0x01 waiting for pretenders 0x02 running The name begins at byte 13 and is nullterminated. The byte after that is the game's era: 0x00 unknown, the game loses the era information once the process ends for the first time in running mode and always has 0x00 for era value after that point 0x01 EA 0x02 MA 0x03 LA Constant 0x2d Time to host, as 32-bit little-endian value. Special values: 0x00000000 the timer is off in running mode 0xffffffff the timer is off in waiting mode Constant 0x00 Next comes information about the nation slots (of which there are 95): First, the status of each nation slot, 1 byte per: 0x00 empty 0x01 human 0x02 AI 0x03 only ever occurs with nation slot 25 (independents) 0xfd closed 0xfe defeated this turn 0xff defeated earlier Second, whether the turn for a nation has been submitted, 1 byte per: 0x00 not submitted 0x01 submitted Third, whether the player for a nation is currently connected, 1 byte per: 0x00 not connected, always this in waiting mode 0x01 connected Next, turn number as 32-bit little-endian integer. The value is 0xffffffff in games in waiting mode. Last, whether clients are allowed to start the game, 1 byte: 0x00 not allowed 0x01 allowed ** Turn file request, 0x07 Byte 8 is number of the nation whose turn file is being requested. The rest of the message body is the nation password as a nullterminated string. TODO: What of the case where user selects more than one nation? The response to this request begins with "fI" and the response body looks compressed. ** Mods info response, 0x12 If there are no mods, bytes 8 and 9 are 0xff Otherwise the 8th byte is number of mods - 1 and 9th byte is 0x00. Or the mods count might be a 2 byte little-endian integer. After that come mod descriptors, which contain: Mod version: 2 2-byte little-endian integers, in order major, minor The mod file name string, nullterminated ** Bye messages 0x0b and 0x0c The 0x0b message is sent by the client when disconnecting from server in the game. The server responds with a 0x0c response. Both messages have an empty body. This is probably not necessary, considering GGS hasn't made games blow up yet.