aboutsummaryrefslogtreecommitdiff
path: root/src/server/cmd/commands
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-04-26 13:30:51 +0000
committerFuwn <[email protected]>2021-04-26 13:30:51 +0000
commitaf68ae63e4b0f5f6237bbda4fed9fd2a6022357d (patch)
tree02bbd59bf0a54808e335c1d703d3dac4cdc0773b /src/server/cmd/commands
parentfix: Actually remove legacy server module (diff)
downloadwhirl-af68ae63e4b0f5f6237bbda4fed9fd2a6022357d.tar.xz
whirl-af68ae63e4b0f5f6237bbda4fed9fd2a6022357d.zip
fmt: Rename re_server module to server
Diffstat (limited to 'src/server/cmd/commands')
-rw-r--r--src/server/cmd/commands/action.rs20
-rw-r--r--src/server/cmd/commands/buddy_list/create.rs24
-rw-r--r--src/server/cmd/commands/buddy_list/mod.rs6
-rw-r--r--src/server/cmd/commands/buddy_list/parse.rs17
-rw-r--r--src/server/cmd/commands/buddy_list/structure.rs7
-rw-r--r--src/server/cmd/commands/mod.rs12
-rw-r--r--src/server/cmd/commands/property/create.rs167
-rw-r--r--src/server/cmd/commands/property/mod.rs5
-rw-r--r--src/server/cmd/commands/property/parse.rs14
-rw-r--r--src/server/cmd/commands/register_object_id/create.rs2
-rw-r--r--src/server/cmd/commands/register_object_id/mod.rs4
-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/session/mod.rs2
-rw-r--r--src/server/cmd/commands/session/parse.rs2
-rw-r--r--src/server/cmd/commands/session/structure.rs2
-rw-r--r--src/server/cmd/commands/subscribe/mod.rs5
-rw-r--r--src/server/cmd/commands/subscribe/parse.rs21
-rw-r--r--src/server/cmd/commands/subscribe/structure.rs10
-rw-r--r--src/server/cmd/commands/text/create.rs31
-rw-r--r--src/server/cmd/commands/text/mod.rs6
-rw-r--r--src/server/cmd/commands/text/parse.rs13
-rw-r--r--src/server/cmd/commands/text/structure.rs7
-rw-r--r--src/server/cmd/commands/whisper.rs2
25 files changed, 426 insertions, 0 deletions
diff --git a/src/server/cmd/commands/action.rs b/src/server/cmd/commands/action.rs
new file mode 100644
index 0000000..99da54f
--- /dev/null
+++ b/src/server/cmd/commands/action.rs
@@ -0,0 +1,20 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use bytes::{BufMut, BytesMut};
+
+pub fn create_action() -> Vec<u8> {
+ let mut command = BytesMut::new();
+
+ command.put_slice(&[
+ 0x01, 0x11, 0x00, 0x05, 0x54, 0x52, 0x41, 0x44, 0x45, 0x07, 0x26, 0x7c, 0x2b, 0x69, 0x6e, 0x76,
+ 0x3e,
+ ]);
+
+ // Convert to vector and insert the length
+ let mut command_as_vec = command.to_vec();
+ command_as_vec.insert(0, command.len() as u8 + 1);
+
+ // Return bytes
+ command_as_vec
+}
diff --git a/src/server/cmd/commands/buddy_list/create.rs b/src/server/cmd/commands/buddy_list/create.rs
new file mode 100644
index 0000000..bc4b10a
--- /dev/null
+++ b/src/server/cmd/commands/buddy_list/create.rs
@@ -0,0 +1,24 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use bytes::{BufMut, BytesMut};
+
+use crate::server::cmd::{commands::buddy_list::structure::Buddy, constants::BUDDYLISTNOTIFY};
+
+pub fn create_buddy_list_notify(buddy: &Buddy) -> Vec<u8> {
+ let mut command = BytesMut::new();
+
+ // Header
+ command.put_u8(0x01); // ObjId
+ command.put_u8(BUDDYLISTNOTIFY as u8); // Type
+
+ // Content
+ command.put_u8(buddy.buddy.len() as u8); // Buddy (name) length
+ command.put_slice(buddy.buddy.as_bytes()); // Buddy (name)
+ command.put_u8(buddy.add); // "Is buddy logged on?" (?)
+
+ let mut command_as_vec = command.to_vec();
+ command_as_vec.insert(0, command.len() as u8 + 1);
+
+ command_as_vec
+}
diff --git a/src/server/cmd/commands/buddy_list/mod.rs b/src/server/cmd/commands/buddy_list/mod.rs
new file mode 100644
index 0000000..14440dc
--- /dev/null
+++ b/src/server/cmd/commands/buddy_list/mod.rs
@@ -0,0 +1,6 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub mod create;
+pub mod parse;
+pub mod structure;
diff --git a/src/server/cmd/commands/buddy_list/parse.rs b/src/server/cmd/commands/buddy_list/parse.rs
new file mode 100644
index 0000000..163052c
--- /dev/null
+++ b/src/server/cmd/commands/buddy_list/parse.rs
@@ -0,0 +1,17 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use std::str::from_utf8;
+
+use crate::server::cmd::commands::buddy_list::structure::Buddy;
+
+pub fn parse_buddy_list_update(data: Vec<u8>) -> Buddy {
+ Buddy {
+ buddy: from_utf8(&data[4..data[0] as usize - 1])
+ .unwrap()
+ .to_string(),
+
+ // Get the last byte
+ add: data[data[0] as usize - 1],
+ }
+}
diff --git a/src/server/cmd/commands/buddy_list/structure.rs b/src/server/cmd/commands/buddy_list/structure.rs
new file mode 100644
index 0000000..5da24d5
--- /dev/null
+++ b/src/server/cmd/commands/buddy_list/structure.rs
@@ -0,0 +1,7 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub struct Buddy {
+ pub buddy: String,
+ pub add: u8,
+}
diff --git a/src/server/cmd/commands/mod.rs b/src/server/cmd/commands/mod.rs
new file mode 100644
index 0000000..b484e2f
--- /dev/null
+++ b/src/server/cmd/commands/mod.rs
@@ -0,0 +1,12 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub mod action;
+pub mod buddy_list;
+pub mod property;
+pub mod room;
+pub mod session;
+pub mod subscribe;
+pub mod text;
+pub mod whisper;
+// pub mod register_object_id; // TODO: Implement.
diff --git a/src/server/cmd/commands/property/create.rs b/src/server/cmd/commands/property/create.rs
new file mode 100644
index 0000000..8521a8e
--- /dev/null
+++ b/src/server/cmd/commands/property/create.rs
@@ -0,0 +1,167 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use crate::{
+ config::get_config,
+ server::{
+ cmd::constants::{PROPUPD, SESSINIT},
+ net::{
+ constants::{
+ VAR_APPNAME,
+ VAR_CHANNEL,
+ VAR_ERROR,
+ VAR_EXTERNAL_HTTP_SERVER,
+ VAR_MAIL_DOMAIN,
+ VAR_PRIV,
+ VAR_PROTOCOL,
+ VAR_SCRIPT_SERVER,
+ VAR_SERIAL,
+ VAR_SERVERTYPE,
+ VAR_SMTP_SERVER,
+ VAR_UPDATETIME,
+ },
+ converter::property_list_to_bytes,
+ structure::NetworkProperty,
+ },
+ },
+};
+
+pub fn create_property_update_as_distributor() -> Vec<u8> {
+ property_list_to_bytes(
+ PROPUPD,
+ 0xFF,
+ vec![
+ NetworkProperty {
+ prop_id: VAR_MAIL_DOMAIN,
+ value: "worlds3d.com".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SMTP_SERVER,
+ value: "mail.worlds.net:25".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SCRIPT_SERVER,
+ value: "http://www-dynamic.us.worlds.net/cgi-bin".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_EXTERNAL_HTTP_SERVER,
+ value: "http://www-static.us.worlds.net".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SERVERTYPE,
+ value: "1".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_PROTOCOL,
+ value: "24".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_APPNAME,
+ value: get_config().unwrap().worldsmaster_username,
+ },
+ ],
+ )
+}
+
+pub fn create_property_update_as_hub() -> Vec<u8> {
+ property_list_to_bytes(
+ PROPUPD,
+ 0xFF,
+ vec![
+ NetworkProperty {
+ prop_id: VAR_UPDATETIME,
+ value: "1000000".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_MAIL_DOMAIN,
+ value: "worlds3d.com".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SMTP_SERVER,
+ value: "mail.worlds.net:25".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SCRIPT_SERVER,
+ value: "http://www-dynamic.us.worlds.net/cgi-bin".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_EXTERNAL_HTTP_SERVER,
+ value: "http://www-static.us.worlds.net".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SERVERTYPE,
+ value: "3".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_PROTOCOL,
+ value: "24".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_APPNAME,
+ value: get_config().unwrap().worldsmaster_username,
+ },
+ ],
+ )
+}
+
+pub fn create_property_request_as_distributor() -> Vec<u8> {
+ property_list_to_bytes(
+ SESSINIT as i32,
+ 0x01,
+ vec![
+ NetworkProperty {
+ prop_id: VAR_ERROR,
+ value: "0".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_APPNAME,
+ value: get_config().unwrap().worldsmaster_username,
+ },
+ NetworkProperty {
+ prop_id: VAR_PROTOCOL,
+ value: "24".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SERVERTYPE,
+ value: "1".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SERIAL,
+ value: "DWLV000000000000".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_PRIV,
+ value: "0".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_CHANNEL,
+ value: "dimension-1".to_string(),
+ },
+ ],
+ )
+}
+
+pub fn create_property_request_as_hub() -> Vec<u8> {
+ property_list_to_bytes(
+ SESSINIT as i32,
+ 0x01,
+ vec![
+ NetworkProperty {
+ prop_id: VAR_ERROR,
+ value: "0".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_SERVERTYPE,
+ value: "3".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_UPDATETIME,
+ value: "1000000".to_string(),
+ },
+ NetworkProperty {
+ prop_id: VAR_PROTOCOL,
+ value: "24".to_string(),
+ },
+ ],
+ )
+}
diff --git a/src/server/cmd/commands/property/mod.rs b/src/server/cmd/commands/property/mod.rs
new file mode 100644
index 0000000..0bea58f
--- /dev/null
+++ b/src/server/cmd/commands/property/mod.rs
@@ -0,0 +1,5 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub mod create;
+pub mod parse;
diff --git a/src/server/cmd/commands/property/parse.rs b/src/server/cmd/commands/property/parse.rs
new file mode 100644
index 0000000..1d48db0
--- /dev/null
+++ b/src/server/cmd/commands/property/parse.rs
@@ -0,0 +1,14 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use crate::server::net::structure::NetworkProperty;
+
+pub fn find_property_in_property_list(
+ property_list: &[NetworkProperty],
+ property: i32,
+) -> &NetworkProperty {
+ property_list
+ .iter()
+ .find(|i| i.prop_id == property)
+ .unwrap()
+}
diff --git a/src/server/cmd/commands/register_object_id/create.rs b/src/server/cmd/commands/register_object_id/create.rs
new file mode 100644
index 0000000..858d572
--- /dev/null
+++ b/src/server/cmd/commands/register_object_id/create.rs
@@ -0,0 +1,2 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
diff --git a/src/server/cmd/commands/register_object_id/mod.rs b/src/server/cmd/commands/register_object_id/mod.rs
new file mode 100644
index 0000000..08317e1
--- /dev/null
+++ b/src/server/cmd/commands/register_object_id/mod.rs
@@ -0,0 +1,4 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub mod create;
diff --git a/src/server/cmd/commands/room/create.rs b/src/server/cmd/commands/room/create.rs
new file mode 100644
index 0000000..a195936
--- /dev/null
+++ b/src/server/cmd/commands/room/create.rs
@@ -0,0 +1,34 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use bytes::{BufMut, BytesMut};
+
+use crate::{config::get_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(get_config().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
new file mode 100644
index 0000000..0bea58f
--- /dev/null
+++ b/src/server/cmd/commands/room/mod.rs
@@ -0,0 +1,5 @@
+// Copyleft 2021-2021 Whirlsplash
+// 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
new file mode 100644
index 0000000..70bd0a8
--- /dev/null
+++ b/src/server/cmd/commands/room/parse.rs
@@ -0,0 +1,8 @@
+// Copyleft 2021-2021 Whirlsplash
+// 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/session/mod.rs b/src/server/cmd/commands/session/mod.rs
new file mode 100644
index 0000000..858d572
--- /dev/null
+++ b/src/server/cmd/commands/session/mod.rs
@@ -0,0 +1,2 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
diff --git a/src/server/cmd/commands/session/parse.rs b/src/server/cmd/commands/session/parse.rs
new file mode 100644
index 0000000..858d572
--- /dev/null
+++ b/src/server/cmd/commands/session/parse.rs
@@ -0,0 +1,2 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
diff --git a/src/server/cmd/commands/session/structure.rs b/src/server/cmd/commands/session/structure.rs
new file mode 100644
index 0000000..858d572
--- /dev/null
+++ b/src/server/cmd/commands/session/structure.rs
@@ -0,0 +1,2 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
diff --git a/src/server/cmd/commands/subscribe/mod.rs b/src/server/cmd/commands/subscribe/mod.rs
new file mode 100644
index 0000000..d7fec55
--- /dev/null
+++ b/src/server/cmd/commands/subscribe/mod.rs
@@ -0,0 +1,5 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+mod parse;
+mod structure;
diff --git a/src/server/cmd/commands/subscribe/parse.rs b/src/server/cmd/commands/subscribe/parse.rs
new file mode 100644
index 0000000..2a17cb2
--- /dev/null
+++ b/src/server/cmd/commands/subscribe/parse.rs
@@ -0,0 +1,21 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use byteorder::{BigEndian, ReadBytesExt};
+use bytes::{Buf, BytesMut};
+
+use crate::server::cmd::commands::subscribe::structure::SubscribeRoom;
+
+/// TODO: The functionality of this function has not been tested... TEST IT!
+pub fn parse_subscribe_room(data: Vec<u8>) -> SubscribeRoom {
+ // https://stackoverflow.com/questions/41034635/how-do-i-convert-between-string-str-vecu8-and-u8
+ let mut data = BytesMut::from(data.as_slice()).reader();
+
+ SubscribeRoom {
+ room_number: data.read_i16::<BigEndian>().unwrap(),
+ distance: data.read_i16::<BigEndian>().unwrap(),
+ x: data.read_i16::<BigEndian>().unwrap(),
+ y: data.read_i16::<BigEndian>().unwrap(),
+ z: data.read_i16::<BigEndian>().unwrap(),
+ }
+}
diff --git a/src/server/cmd/commands/subscribe/structure.rs b/src/server/cmd/commands/subscribe/structure.rs
new file mode 100644
index 0000000..6142aaa
--- /dev/null
+++ b/src/server/cmd/commands/subscribe/structure.rs
@@ -0,0 +1,10 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub struct SubscribeRoom {
+ pub room_number: i16,
+ pub distance: i16,
+ pub x: i16,
+ pub y: i16,
+ pub z: i16,
+}
diff --git a/src/server/cmd/commands/text/create.rs b/src/server/cmd/commands/text/create.rs
new file mode 100644
index 0000000..879f9bd
--- /dev/null
+++ b/src/server/cmd/commands/text/create.rs
@@ -0,0 +1,31 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use bytes::{BufMut, BytesMut};
+
+use crate::server::cmd::{commands::text::structure::Text, constants::TEXT};
+
+pub fn create_text(text: Text) -> Vec<u8> {
+ let mut command = BytesMut::new();
+
+ // Header
+ command.put_u8(0x01);
+ command.put_u8(TEXT as u8);
+
+ // Content
+ // The fourth and fifth elements are presumed to be interpreted as a short by
+ // the client, however, usernames aren't (?) allowed to be long enough that
+ // they reach a number high enough to be converted to a short.
+ command.put_u8(0x00);
+ command.put_u8(text.sender.len() as u8);
+ command.put_slice(text.sender.as_bytes());
+ command.put_u8(text.content.len() as u8);
+ command.put_slice(text.content.as_bytes());
+
+ // Convert to vector and insert the length
+ let mut command_as_vec = command.to_vec();
+ command_as_vec.insert(0, command.len() as u8 + 1);
+
+ // Return bytes
+ command_as_vec
+}
diff --git a/src/server/cmd/commands/text/mod.rs b/src/server/cmd/commands/text/mod.rs
new file mode 100644
index 0000000..14440dc
--- /dev/null
+++ b/src/server/cmd/commands/text/mod.rs
@@ -0,0 +1,6 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub mod create;
+pub mod parse;
+pub mod structure;
diff --git a/src/server/cmd/commands/text/parse.rs b/src/server/cmd/commands/text/parse.rs
new file mode 100644
index 0000000..a7f66d0
--- /dev/null
+++ b/src/server/cmd/commands/text/parse.rs
@@ -0,0 +1,13 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+use std::str::from_utf8;
+
+use crate::server::cmd::commands::text::structure::Text;
+
+pub fn parse_text(data: Vec<u8>, username: &str) -> Text {
+ Text {
+ sender: username.to_string(),
+ content: from_utf8(&data[6..]).unwrap().to_string(),
+ }
+}
diff --git a/src/server/cmd/commands/text/structure.rs b/src/server/cmd/commands/text/structure.rs
new file mode 100644
index 0000000..eaeef38
--- /dev/null
+++ b/src/server/cmd/commands/text/structure.rs
@@ -0,0 +1,7 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only
+
+pub struct Text {
+ pub sender: String,
+ pub content: String,
+}
diff --git a/src/server/cmd/commands/whisper.rs b/src/server/cmd/commands/whisper.rs
new file mode 100644
index 0000000..858d572
--- /dev/null
+++ b/src/server/cmd/commands/whisper.rs
@@ -0,0 +1,2 @@
+// Copyleft 2021-2021 Whirlsplash
+// SPDX-License-Identifier: GPL-3.0-only