aboutsummaryrefslogtreecommitdiff
path: root/src/server/cmd
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-04-30 18:15:32 +0000
committerFuwn <[email protected]>2021-04-30 18:15:32 +0000
commit19555b59fb6640757c500c4f094968aaca9ec8b3 (patch)
tree03a89ce14b0c9a92b467fd8d7fb68de91689c766 /src/server/cmd
parentrefactor(cmds): orphan functions to methods (diff)
downloadwhirl-19555b59fb6640757c500c4f094968aaca9ec8b3.tar.xz
whirl-19555b59fb6640757c500c4f094968aaca9ec8b3.zip
refactor(cmds): of2m
Diffstat (limited to 'src/server/cmd')
-rw-r--r--src/server/cmd/commands/teleport.rs32
-rw-r--r--src/server/cmd/commands/teleport/mod.rs5
-rw-r--r--src/server/cmd/commands/teleport/parse.rs36
-rw-r--r--src/server/cmd/commands/teleport/structure.rs24
4 files changed, 32 insertions, 65 deletions
diff --git a/src/server/cmd/commands/teleport.rs b/src/server/cmd/commands/teleport.rs
new file mode 100644
index 0000000..2f7b7c5
--- /dev/null
+++ b/src/server/cmd/commands/teleport.rs
@@ -0,0 +1,32 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+use byteorder::{BigEndian, ReadBytesExt};
+use bytes::{Buf, BytesMut};
+
+#[derive(Debug)]
+pub struct Teleport {
+ pub room_id: i8,
+ pub exit_type: u8,
+ pub entry_type: u8,
+ pub x: f32, // i16
+ pub y: f32,
+ pub z: f32,
+ pub direction: f32,
+}
+impl Teleport {
+ pub fn parse(data: Vec<u8>) -> Self {
+ // https://stackoverflow.com/questions/41034635/how-do-i-convert-between-string-str-vecu8-and-u8
+ let mut data = BytesMut::from(data.as_slice()).reader();
+
+ Self {
+ room_id: data.read_u16::<BigEndian>().unwrap() as i8,
+ exit_type: data.read_u8().unwrap(),
+ entry_type: data.read_u8().unwrap(),
+ x: data.read_i16::<BigEndian>().unwrap() as f32,
+ y: data.read_i16::<BigEndian>().unwrap() as f32,
+ z: data.read_i16::<BigEndian>().unwrap() as f32,
+ direction: data.read_i16::<BigEndian>().unwrap() as f32,
+ }
+ }
+}
diff --git a/src/server/cmd/commands/teleport/mod.rs b/src/server/cmd/commands/teleport/mod.rs
deleted file mode 100644
index a72d443..0000000
--- a/src/server/cmd/commands/teleport/mod.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-pub mod parse;
-mod structure;
diff --git a/src/server/cmd/commands/teleport/parse.rs b/src/server/cmd/commands/teleport/parse.rs
deleted file mode 100644
index 07f3133..0000000
--- a/src/server/cmd/commands/teleport/parse.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use byteorder::{BigEndian, ReadBytesExt};
-use bytes::{Buf, BytesMut};
-
-use crate::server::cmd::commands::teleport::structure::{Teleport, TeleportLiteral};
-
-pub fn parse_teleport(data: Vec<u8>) -> Teleport {
- // https://stackoverflow.com/questions/41034635/how-do-i-convert-between-string-str-vecu8-and-u8
- let mut data = BytesMut::from(data.as_slice()).reader();
-
- Teleport {
- room_id: data.read_u16::<BigEndian>().unwrap() as i8,
- exit_type: data.read_u8().unwrap(),
- entry_type: data.read_u8().unwrap(),
- x: data.read_i16::<BigEndian>().unwrap(),
- y: data.read_i16::<BigEndian>().unwrap(),
- z: data.read_i16::<BigEndian>().unwrap(),
- direction: data.read_i16::<BigEndian>().unwrap(),
- }
-}
-
-pub fn parse_teleport_literal(data: Vec<u8>) -> TeleportLiteral {
- let teleport = parse_teleport(data);
-
- TeleportLiteral {
- room_id: teleport.room_id,
- exit_type: teleport.exit_type,
- entry_type: teleport.entry_type,
- x: teleport.x as f32,
- y: teleport.y as f32,
- z: teleport.z as f32,
- direction: teleport.direction as f32,
- }
-}
diff --git a/src/server/cmd/commands/teleport/structure.rs b/src/server/cmd/commands/teleport/structure.rs
deleted file mode 100644
index 8a38c60..0000000
--- a/src/server/cmd/commands/teleport/structure.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-#[derive(Debug)]
-pub struct Teleport {
- pub room_id: i8,
- pub exit_type: u8,
- pub entry_type: u8,
- pub x: i16,
- pub y: i16,
- pub z: i16,
- pub direction: i16,
-}
-
-#[derive(Debug)]
-pub struct TeleportLiteral {
- pub room_id: i8,
- pub exit_type: u8,
- pub entry_type: u8,
- pub x: f32,
- pub y: f32,
- pub z: f32,
- pub direction: f32,
-}