diff options
-rw-r--r-- | doc/protocol.md | 11 | ||||
-rw-r--r-- | shared/src/packets.rs | 9 |
2 files changed, 15 insertions, 5 deletions
diff --git a/doc/protocol.md b/doc/protocol.md index 7324637..4c05cf2 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -22,14 +22,15 @@ encoded text. 0xff disconnect() 0x01 request_resource(name: Res) 0x02 respond_resource(data: Vec<u8>) -0x03 add(id: Obj, prefab: Res<Prefab>) -0x04 remove(id: Obj) -0x05 position(id: Obj, pos: Vec3, rot: Vec3) -0x06 pose(id: Obj, params: Vec<f32>) +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(id: Obj, data: Vec<u8>) +0x08 sound(ob: Obj, data: Vec<u8>) 0x09 prefab_index(res: Res) 0x0a announce_prefab(res: Res) +0x0b chat(ob: Obj, message: String) ``` ## Resources diff --git a/shared/src/packets.rs b/shared/src/packets.rs index 1c457d3..a5c017d 100644 --- a/shared/src/packets.rs +++ b/shared/src/packets.rs @@ -47,6 +47,8 @@ pub struct Object(pub u128); #[derive(Clone)] pub struct Data(pub Vec<u8>); +#[derive(Debug, Clone)] +pub struct Message(pub String); #[derive(Debug, Clone)] pub enum Packet { @@ -62,6 +64,7 @@ pub enum Packet { Sound(Object, Data), PrefabIndex(Resource<PrefabIndex>), AnnouncePrefab(Resource<Prefab>), + Chat(Object, Message), } impl Object { @@ -126,6 +129,11 @@ impl Packet { w.write_all(&[0x0a])?; resource.write(w)?; } + Packet::Chat(object, message) => { + w.write_all(&[0x0b])?; + object.write(w)?; + message.write(w)?; + } } Ok(()) } @@ -156,6 +164,7 @@ impl ReadWrite for Packet { 0x08 => Packet::Sound(Object::read(r)?, Data::read(r)?), 0x09 => Packet::PrefabIndex(Resource::read(r)?), 0x0a => Packet::AnnouncePrefab(Resource::read(r)?), + 0x0b => Packet::Chat(Object::read(r)?, Message::read(r)?), _ => { for _ in 0..packet_len.max(1) - 1 { r.read_exact(&mut [0])?; |