summaryrefslogtreecommitdiff
path: root/doc/protocol.md
blob: 4c05cf2b858536bb84738e5f06ef290c45f34691 (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
29
30
31
32
33
34
35
36
37
38
39
# Protocol

Default port is 28555 for TCP and UDP transport.

For TCP, packets are concatenated to a stream.

For UDP, game packets are concatenated in groups of at least one to form one UDP
packet.

## Protocol packets

All packets are preceeded by its length as u32. The next byte indicates the
type. The following bytes are the parameters.

`Vec<T>` is stored as u32 element count followed by the elements. `Res<T>` is
used to denote 256-bit resource hash referring to data of type T. `Obj` refers
128-bit game objects IDs. `String` is stored like `Vec<u8>` but contains UTF-8
encoded text.

```rs
0x00 connect(identity: u128)
0xff disconnect()
0x01 request_resource(name: Res)
0x02 respond_resource(data: Vec<u8>)
0x03 add(ob: Obj, prefab: Res<Prefab>)
0x04 remove(ob: Obj)
0x05 position(ob: Obj, pos: Vec3, rot: Vec3)
0x06 pose(ob: Obj, params: Vec<f32>)
0x07 parent(parent: Obj, child: Obj)
0x08 sound(ob: Obj, data: Vec<u8>)
0x09 prefab_index(res: Res)
0x0a announce_prefab(res: Res)
0x0b chat(ob: Obj, message: String)
```

## Resources

Resources are reusable things. They are identified by the BLAKE3 hash of their
serialized content. See [resources.md](./resources.md)