From b1db0e0f201fa1551e3fe98bc41e56e3f802d7af Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 5 Dec 2025 15:27:58 +0100 Subject: update protocol doc --- README.md | 8 ++++---- protocol.md | 35 +++++++++++++---------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7cd838d6..36d7b8a2 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,11 @@ The game protocol is outlined in [protocol.md](./protocol.md). ## Building The high-level build system is Make. But Rust's Cargo is also used. There are is -a `all` target for everything and `all_`_component_ for each component. +a `all` target for everything and `all_` for each component. ```sh make all # Build everything -make all_client # Build only client -make all_server # Build only server +make all_{client,server,book,data,testclient} # Build only one component make clean # Remove build files ``` @@ -53,10 +52,11 @@ make clean # Remove build files - [sed](https://www.gnu.org/software/sed) - Test client: - [Rustup](https://rustup.rs) - - esbuild + - [esbuild](https://esbuild.github.io/) - Book export: - [Godot](https://godotengine.org) (>=4.5) - [Rustup](https://rustup.rs) + - (Optional) [Graphviz](https://graphviz.org/) ## Contributing diff --git a/protocol.md b/protocol.md index 7a70736a..a014d17e 100644 --- a/protocol.md +++ b/protocol.md @@ -2,27 +2,19 @@ The protocol schema is defined in [`protocol.ts`](./test-client/protocol.ts) -1. Connect to the server via WebSocket and send/receive json in WebSocket "Text" - messages. The binary protocol uses "Binary" messages and is optional for - servers and clients. +1. Connect to the server via WebSocket and send/receive JSON in text messages. 2. Wait for `version` packet and check version compatibiliy (see below). -3. Send the join packet with your username. -4. The server will send the current game state: - - `data` once for setting important look-up tables - - `update_map` for every tile - - `set_tile_item` for every item on a tile - - `add_player` for every player in the game - - `set_player_item` for every item held by a player +3. The server will send the current game data and state, then finishes with + `set_ingame(state=true)` +4. Send `join` with your username, the server will confirm your join with + `joined`. 5. Run the game loop - - Send your position every 20ms - 40ms. + - Send a `keepalive` packet every 1000ms. + - Send your position via `movement` every 20ms - 40ms. - Send `interact` when the player interacts with a tile. - Receive packets -6. The Game ends. The server will remove all players and tiles. Then continue at - step 4. - -Collisions are handled by the clients. Whenever to players collide the player -with the greater PlayerID is responsible for updating their own momentum and -sending a packet to update that of the other player. +6. The Game ends. The server will remove all players and tiles, then send + `set_ingame(state=false)`. Then continue at step 4. ## Ports @@ -32,7 +24,7 @@ sending a packet to update that of the other player. - 27034: Lobby Server Websocket - 27035: Map Editor Server Websocket -## Binary Protocol + ## Protocol Versioning The `init` packet sends minor and major version numbers of the protocol is use by the server. These are to be interpreted according to -[SemVer](https://semver.org/) for the JSON protocol. The binary protocol can not -be used if either minor or major version differs. +[SemVer](https://semver.org/) for the JSON protocol. ## Movement @@ -56,7 +47,7 @@ latency. For this reason it implemented three times: - In GDscript (for the Godot client): [controllable_player.gd](./client/player/controllable_player.gd) -- In Rust (for server, pixelcurry and customers): +- In Rust (for server and standalone bots): [movement.rs](./server/protocol/src/movement.rs) - In TypeScript (for test-client): [movement.ts](./test-client/movement.ts) -- cgit v1.3