aboutsummaryrefslogtreecommitdiff
path: root/src/server/cmd
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-01 12:03:40 +0000
committerFuwn <[email protected]>2021-05-01 12:03:40 +0000
commitb83db32c503c2c818ce513966351020ce7308ce3 (patch)
treeed8194a42a0a86faa0bc7568f11fdeb0b1e1596a /src/server/cmd
parentchore(git): add prepare-commit-hook for commitizen (diff)
downloadwhirl-b83db32c503c2c818ce513966351020ce7308ce3.tar.xz
whirl-b83db32c503c2c818ce513966351020ce7308ce3.zip
refactor(cmds): even more of2m-ifying
Diffstat (limited to 'src/server/cmd')
-rw-r--r--src/server/cmd/commands/mod.rs3
-rw-r--r--src/server/cmd/commands/property/create.rs2
-rw-r--r--src/server/cmd/commands/redirect_id.rs41
-rw-r--r--src/server/cmd/commands/room/create.rs34
-rw-r--r--src/server/cmd/commands/room/mod.rs5
-rw-r--r--src/server/cmd/commands/room/parse.rs8
-rw-r--r--src/server/cmd/commands/room_id_request.rs16
7 files changed, 61 insertions, 48 deletions
diff --git a/src/server/cmd/commands/mod.rs b/src/server/cmd/commands/mod.rs
index d06c061..0d5fc1c 100644
--- a/src/server/cmd/commands/mod.rs
+++ b/src/server/cmd/commands/mod.rs
@@ -4,7 +4,8 @@
pub mod action;
pub mod buddy_list;
pub mod property;
-pub mod room;
+pub mod redirect_id;
+pub mod room_id_request;
pub mod subscribe_distance;
pub mod subscribe_room;
pub mod teleport;
diff --git a/src/server/cmd/commands/property/create.rs b/src/server/cmd/commands/property/create.rs
index 6cfe540..ec4de1e 100644
--- a/src/server/cmd/commands/property/create.rs
+++ b/src/server/cmd/commands/property/create.rs
@@ -1,6 +1,8 @@
// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
+// TODO: of2m-ify
+
use crate::{
config::Config,
server::{
diff --git a/src/server/cmd/commands/redirect_id.rs b/src/server/cmd/commands/redirect_id.rs
new file mode 100644
index 0000000..5153c38
--- /dev/null
+++ b/src/server/cmd/commands/redirect_id.rs
@@ -0,0 +1,41 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+use bytes::{BufMut, BytesMut};
+
+use crate::{config::Config, server::cmd::constants::REDIRID};
+
+#[derive(Debug)]
+pub struct RedirectId {
+ pub room_name: String,
+ pub room_number: i8,
+}
+impl RedirectId {
+ pub fn create(self) -> Vec<u8> {
+ let mut command = BytesMut::new();
+
+ // Header
+ command.put_u8(0x01); // ObjId
+ command.put_u8(REDIRID as u8); // Type
+
+ // Content
+ command.put_u8(self.room_name.len() as u8); // Room name length
+ command.put_slice(self.room_name.as_bytes()); // Room name
+ // command.put_u8(0x00); // Unimplemented byte (?)
+ // command.put_u8(room_id); // Room ID
+ command.put_u16(self.room_number as u16); // Room ID
+
+ // IP
+ for byte in "0.0.0.0".split('.') {
+ command.put_u8(byte.parse::<u8>().unwrap());
+ }
+ command.put_u16(Config::get().unwrap().hub.port as u16); // Port
+
+ // Length
+ let mut command_as_vec = command.to_vec();
+ command_as_vec.insert(0, command.len() as u8 + 1);
+
+ // Return
+ command_as_vec
+ }
+}
diff --git a/src/server/cmd/commands/room/create.rs b/src/server/cmd/commands/room/create.rs
deleted file mode 100644
index 943b7c9..0000000
--- a/src/server/cmd/commands/room/create.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use bytes::{BufMut, BytesMut};
-
-use crate::{config::Config, server::cmd::constants::REDIRID};
-
-pub fn create_room_id_request(room: &str, room_id: u8) -> Vec<u8> {
- let mut command = BytesMut::new();
-
- // Header
- command.put_u8(0x01); // ObjId
- command.put_u8(REDIRID as u8); // Type
-
- // Content
- command.put_u8(room.len() as u8); // Room name length
- command.put_slice(room.as_bytes()); // Room name
- // command.put_u8(0x00); // Unimplemented byte (?)
- // command.put_u8(room_id); // Room ID
- command.put_u16(room_id as u16); // Room ID
-
- // IP
- for byte in "0.0.0.0".split('.') {
- command.put_u8(byte.parse::<u8>().unwrap());
- }
- command.put_u16(Config::get().unwrap().hub.port as u16); // Port
-
- // Length
- let mut command_as_vec = command.to_vec();
- command_as_vec.insert(0, command.len() as u8 + 1);
-
- // Return
- command_as_vec
-}
diff --git a/src/server/cmd/commands/room/mod.rs b/src/server/cmd/commands/room/mod.rs
deleted file mode 100644
index 83b015b..0000000
--- a/src/server/cmd/commands/room/mod.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-pub mod create;
-pub mod parse;
diff --git a/src/server/cmd/commands/room/parse.rs b/src/server/cmd/commands/room/parse.rs
deleted file mode 100644
index 79ec8af..0000000
--- a/src/server/cmd/commands/room/parse.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use std::str::from_utf8;
-
-pub fn parse_room_id_request(data: Vec<u8>) -> String {
- from_utf8(&data[4..data[0] as usize]).unwrap().to_string()
-}
diff --git a/src/server/cmd/commands/room_id_request.rs b/src/server/cmd/commands/room_id_request.rs
new file mode 100644
index 0000000..812374c
--- /dev/null
+++ b/src/server/cmd/commands/room_id_request.rs
@@ -0,0 +1,16 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+use std::str::from_utf8;
+
+#[derive(Debug)]
+pub struct RoomIdRequest {
+ pub room_name: String,
+}
+impl RoomIdRequest {
+ pub fn parse(data: Vec<u8>) -> Self {
+ Self {
+ room_name: from_utf8(&data[4..data[0] as usize]).unwrap().to_string(),
+ }
+ }
+}