aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-04-30 18:15:32 -0700
committerFuwn <[email protected]>2021-04-30 18:15:32 -0700
commitb33b2e40234672f2923cbe94eefa7b026c19e586 (patch)
treedb8eb0f98ff1c69ac682c45c3f96d8fcaa508d52
parentrefactor(cmds): orphan functions to methods (diff)
downloadwhirl-b33b2e40234672f2923cbe94eefa7b026c19e586.tar.xz
whirl-b33b2e40234672f2923cbe94eefa7b026c19e586.zip
refactor(cmds): of2m
-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
-rw-r--r--src/server/hub.rs4
5 files changed, 34 insertions, 67 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,
-}
diff --git a/src/server/hub.rs b/src/server/hub.rs
index eb15c77..f4f92da 100644
--- a/src/server/hub.rs
+++ b/src/server/hub.rs
@@ -27,7 +27,7 @@ use crate::{
room::{create::create_room_id_request, parse::parse_room_id_request},
subscribe_distance::parse::parse_subscribe_distance,
subscribe_room::parse::parse_subscribe_room,
- teleport::parse::parse_teleport,
+ teleport::Teleport,
text::Text,
},
constants::*,
@@ -134,7 +134,7 @@ impl Server for Hub {
username, subscribe_distance);
}
TELEPORT => {
- let teleport = parse_teleport(msg[3..].to_vec());
+ let teleport = Teleport::parse(msg[3..].to_vec());
trace!("received teleport from {}: {:?}",
username, teleport);
}