Created Server Query Protocol (markdown)

fgsfds committed 2024-01-14 20:14:08 +01:00
1 parent 948f7eb04e
commit ad5e3afeb8
1 file changed
+38
+38
@@ -0,0 +1,38 @@
This only applies to the `port-net` branch.
It is possible to query game information from the server without connecting to it. This is done by sending a special UDP packet to the server, to the same port that is used for the game itself. For a basic example in Python, check out [this script](https://github.com/fgsfdsfgs/perfect_dark/blob/port-net/tools/query.py).
### Request packet
`"PDQM\x01"` (bytes `50 44 51 4D 01`)
### Response packet
```
struct {
char magic[5] = "PDQM\x01"; // same as query
u16 size; // total size of this packet
u32 protocol // protocol version (NET_PROTOCOL_VER)
u8 flags; // currently just 1 if game is in progress and 0 otherwise
u8 numclients; // currently connected clients
u8 maxclients; // max connected clients
u8 stagenum; // current stage number (see stagetable.txt)
u8 scenario; // combat sim scenario
dstring hostname; // nickname of hosting player
dstring romname; // ROM file name
dstring moddir; // mod directory if a mod is loaded, empty string otherwise
u16 checksum; // checksum of all the packet data before this point
};
```
where `dstring` is
```
u16 length; // including null terminator
char data[length]; // null terminated
```
The checksum function used is as follows:
```
u32 chk = 1;
for (u32 i = 0; i < datalen; ++i) {
chk = (chk + data[i]) % 65521;
}
```