diff options
Diffstat (limited to 'crates/whirl_server/src/cmd/commands/teleport.rs')
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/teleport.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/crates/whirl_server/src/cmd/commands/teleport.rs b/crates/whirl_server/src/cmd/commands/teleport.rs index aa4b7dd..f3a5290 100644 --- a/crates/whirl_server/src/cmd/commands/teleport.rs +++ b/crates/whirl_server/src/cmd/commands/teleport.rs @@ -2,9 +2,12 @@ // SPDX-License-Identifier: GPL-3.0-only use { - crate::cmd::extendable::Parsable, + crate::cmd::{ + constants::Command, + extendable::{Creatable, Parsable}, + }, byteorder::{BigEndian, ReadBytesExt}, - bytes::{Buf, BytesMut}, + bytes::{Buf, BufMut, BytesMut}, }; #[derive(Debug)] @@ -17,6 +20,7 @@ pub struct Teleport { pub z: f32, pub direction: f32, } + impl Parsable for Teleport { fn parse(data: Vec<u8>) -> Self { // https://stackoverflow.com/questions/41034635/how-do-i-convert-between-string-str-vecu8-and-u8 @@ -33,3 +37,29 @@ impl Parsable for Teleport { } } } + +impl Creatable for Teleport { + fn create_with_short_object_id(&self, short_object_id: u8) -> Vec<u8> { + let mut command = BytesMut::new(); + + // Header + command.put_u8(short_object_id); // ObjId + command.put_u8(Command::Teleport as u8); // Type + + // Content + command.put_i16(i16::from(self.room_id)); + command.put_u8(self.exit_type); + command.put_u8(self.entry_type); + command.put_i16(self.x as i16); + command.put_i16(self.y as i16); + command.put_i16(self.z as i16); + command.put_i16(self.direction as i16); + + // Length + let mut command_as_vec = command.to_vec(); + command_as_vec.insert(0, command.len() as u8 + 1); + + // Return bytes + command_as_vec + } +} |