From ad5e3afeb8ef5261424c8eb70dc696369c04450f Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 14 Jan 2024 20:14:08 +0100 Subject: [PATCH] Created Server Query Protocol (markdown) --- Server-Query-Protocol.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Server-Query-Protocol.md diff --git a/Server-Query-Protocol.md b/Server-Query-Protocol.md new file mode 100644 index 0000000..4fd1647 --- /dev/null +++ b/Server-Query-Protocol.md @@ -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; +} +``` \ No newline at end of file