aboutsummaryrefslogtreecommitdiff
path: root/protocol.md
blob: 093bce58e58cb0d3f147ff4552fb2a1851f91cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# undercooked protocol

The protocol schema is defined in [`protocol.ts`](./test-client/protocol.ts)

1. Connect to the server via TCP (on port 27031) or WebSocket (on port 27032)
   and send/receive json on individual lines / text messages.
2. Send the join packet with your username.
3. Receive initial packets. The server will send the current game state.
   - `joined` including your ID and Gamedata
   - `update_map` for every tile
   - `produce_item` for every item on a tile
   - `add_player` for every player in the game
4. Run the game loop
   - Send your position every 40ms.
   - Send `interact` when the player interacts with a tile. Make sure to set the
     `edge` parameter consistently.
   - Receive packets

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.

## Movement

Movement is handled mostly client-side. Therefore it is implement three times: 
- In the test-client: [movement.ts](./test-client/movement.ts)
- For customers in the server: [movement.rs](./server/src/customer/movement.rs)
- In the client: [movement.rs](./client/scripts/player.gd)