aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-03-24 11:39:16 +0000
committerFuwn <[email protected]>2021-03-24 11:39:16 +0000
commit6b03628352aeda71c794dc19750edf2497a88185 (patch)
tree64f48199f0b6716c52052fb81a9a8973431f2efb /src/server
parentetc: Remove unused module and implement structures (diff)
downloadwhirl-6b03628352aeda71c794dc19750edf2497a88185.tar.xz
whirl-6b03628352aeda71c794dc19750edf2497a88185.zip
format: Move server type specific functions to correct modules
Diffstat (limited to 'src/server')
-rw-r--r--src/server/auto/cmd/mod.rs1
-rw-r--r--src/server/auto/cmd/property.rs71
-rw-r--r--src/server/auto/server.rs6
-rw-r--r--src/server/cmd/buddy_list.rs14
-rw-r--r--src/server/cmd/mod.rs3
-rw-r--r--src/server/cmd/text.rs46
-rw-r--r--src/server/mod.rs1
-rw-r--r--src/server/room/server.rs4
8 files changed, 141 insertions, 5 deletions
diff --git a/src/server/auto/cmd/mod.rs b/src/server/auto/cmd/mod.rs
index addf7a5..5430662 100644
--- a/src/server/auto/cmd/mod.rs
+++ b/src/server/auto/cmd/mod.rs
@@ -1 +1,2 @@
+pub mod property;
pub mod room;
diff --git a/src/server/auto/cmd/property.rs b/src/server/auto/cmd/property.rs
new file mode 100644
index 0000000..01d4f43
--- /dev/null
+++ b/src/server/auto/cmd/property.rs
@@ -0,0 +1,71 @@
+// struct NetToProperty {
+// _prop_id: i32,
+// _flags: i32,
+// _access: i32,
+// _string_value: String,
+// _bin_value: Vec<i32>,
+// }
+// impl NetToProperty {
+// fn parse_net_data() -> Self {
+// NetToProperty {
+// _prop_id: 0,
+// _flags: 0,
+// _access: 0,
+// _string_value: "".to_string(),
+// _bin_value: vec![]
+// }
+// }
+// }
+
+// TODO: Decode received data and send back a valid response.
+pub fn create_property_update_command() -> [u8; 147] { // Vec<u8>
+ // let mut property = Vec::with_capacity(2);
+ // property.push(0x01); // ?
+ // property.push(0x10); // Command type
+ //
+ // // Meaningful Data
+ // property.push(); // Property ID
+ // property.push(); // Flags
+ // property.push(); // Access
+ //
+ // // Insert data length as first byte.
+ // property.insert(0, property.len() as u8 + 1); // ^
+ //
+ // property // Return created array
+
+ [
+ 0x93, 0xFF, 0x10, 0x1B, 0x80, 0x01, 0x0C, 0x77, 0x6F,
+ 0x72, 0x6C, 0x64, 0x73, 0x33, 0x64, 0x2E, 0x63, 0x6F,
+ 0x6D, 0x1A, 0x80, 0x01, 0x12, 0x6D, 0x61, 0x69, 0x6C,
+ 0x2E, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x73, 0x2E, 0x6E,
+ 0x65, 0x74, 0x3A, 0x32, 0x35, 0x19, 0x80, 0x01, 0x28,
+ 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77,
+ 0x77, 0x2D, 0x64, 0x79, 0x6E, 0x61, 0x6D, 0x69, 0x63,
+ 0x2E, 0x75, 0x73, 0x2E, 0x77, 0x6F, 0x72, 0x6C, 0x64,
+ 0x73, 0x2E, 0x6E, 0x65, 0x74, 0x2F, 0x63, 0x67, 0x69,
+ 0x2D, 0x62, 0x69, 0x6E, 0x18, 0x80, 0x01, 0x1F, 0x68,
+ 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77,
+ 0x2D, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x2E, 0x75,
+ 0x73, 0x2E, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x73, 0x2E,
+ 0x6E, 0x65, 0x74, 0x0F, 0x80, 0x01, 0x01, 0x31, 0x03,
+ 0x80, 0x01, 0x02, 0x32, 0x34, 0x01, 0x80, 0x01, 0x0C,
+ 0x57, 0x4F, 0x52, 0x4C, 0x44, 0x53, 0x4D, 0x41, 0x53,
+ 0x54, 0x45, 0x52
+ ]: [u8; 147]
+}
+
+pub fn create_property_request_command() -> [u8; 61] {
+ [
+ 0x3D, 0x01, 0x06, 0x04, 0x01, 0x30, 0x01, 0x0C,
+ 0x57, 0x4F, 0x52, 0x4C, 0x44, 0x53, 0x4D, 0x41,
+ 0x53, 0x54, 0x45, 0x52, 0x03, 0x02, 0x32, 0x34,
+ 0x0F, 0x01, 0x31, 0x0A, 0x10,
+
+ // VAR_SERIAL
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x16, 0x01, 0x30, 0x05, 0x0B, 0x64, 0x69, 0x6D,
+ 0x65, 0x6E, 0x73, 0x69, 0x6F, 0x6E, 0x2D, 0x31
+ ]: [u8; 61]
+}
diff --git a/src/server/auto/server.rs b/src/server/auto/server.rs
index d9a8d0e..381852f 100644
--- a/src/server/auto/server.rs
+++ b/src/server/auto/server.rs
@@ -3,9 +3,9 @@ use std::io::{Read, Write};
use mio::{Poll, Token, Ready, PollOpt, Events};
use std::collections::{HashMap, HashSet};
use std::str::from_utf8;
-use crate::cmd::buddy_list::create_buddy_list_notify_command;
-use crate::cmd::text::{create_text_command, create_text_command_with_action};
-use crate::cmd::property::{create_property_update_command, create_property_request_command};
+use crate::server::cmd::buddy_list::create_buddy_list_notify_command;
+use crate::server::cmd::text::{create_text_command, create_text_command_with_action};
+use super::cmd::property::{create_property_update_command, create_property_request_command};
use super::cmd::room::create_room_id_redirect_command;
use rand::Rng;
use crate::server::utils::broadcast_to_all_clients;
diff --git a/src/server/cmd/buddy_list.rs b/src/server/cmd/buddy_list.rs
new file mode 100644
index 0000000..1423808
--- /dev/null
+++ b/src/server/cmd/buddy_list.rs
@@ -0,0 +1,14 @@
+/// In the future, this will take a `Vec` of buddies and dynamically
+/// create a response packet based on the amount of buddies given.
+pub fn create_buddy_list_notify_command(buddy: &str) -> Vec<u8> {
+ let mut buddy_list_notify = Vec::with_capacity(5 + buddy.len());
+ buddy_list_notify.push(0x01); // ?
+ buddy_list_notify.push(0x1E); // BUDDYLISTNOTIFY
+ buddy_list_notify.push(buddy.len() as u8); // Buddy name length
+ for i in buddy.bytes() { buddy_list_notify.push(i); } // Buddy name
+ buddy_list_notify.push(0x01); // Is buddy logged on?
+ // Insert data length as first byte.
+ buddy_list_notify.insert(0, buddy_list_notify.len() as u8 + 1); // ^
+
+ buddy_list_notify // Return created array
+}
diff --git a/src/server/cmd/mod.rs b/src/server/cmd/mod.rs
new file mode 100644
index 0000000..c211484
--- /dev/null
+++ b/src/server/cmd/mod.rs
@@ -0,0 +1,3 @@
+pub mod buddy_list;
+// pub mod property;
+pub mod text;
diff --git a/src/server/cmd/text.rs b/src/server/cmd/text.rs
new file mode 100644
index 0000000..a0ada32
--- /dev/null
+++ b/src/server/cmd/text.rs
@@ -0,0 +1,46 @@
+pub fn create_text_command(user: &str, message: &str) -> Vec<u8> {
+ let mut text = Vec::with_capacity(6 + user.len() + message.len());
+ text.push(0x01); // ?
+ text.push(0x0E); // Command type
+ text.push(0x00); // Assumed to be a divider.
+ text.push(user.len() as u8); // 'user' length
+ for i in user.bytes() { text.push(i); } // Pushing 'user'
+ text.push(message.len() as u8); // 'message' length
+ for i in message.bytes() { text.push(i); } // Pushing `message`
+ text.insert(0, text.len() as u8 + 1); // Insert data length as first byte.
+
+ text // Return created array
+}
+
+// TODO: Get this working!
+// pub fn get_message_from_text_command(buffer: &'static [u8; 1024]) -> &'static str {
+// from_utf8(
+// &buffer[6..*&buffer.get(0).unwrap().to_owned() as usize]
+// ).unwrap()
+// }
+
+pub fn create_text_command_with_action(
+ user: &str,
+ message: &str,
+ // action: &str // Not accepting input until I figure out how actions work.
+) -> Vec<u8> {
+ let mut text = Vec::with_capacity(6 + user.len() + message.len());
+ text.push(0x01); // ?
+ text.push(0x0E); // Command type
+ text.push(0x00); // Assumed to be a divider.
+ text.push(user.len() as u8); // 'user' length
+ for i in user.bytes() { text.push(i); } // Pushing 'user'
+ text.push(message.len() as u8); // 'message' length
+ for i in message.bytes() { text.push(i); } // Pushing `message`
+
+ let action: [u8; 18] = [
+ 0x12, 0x01, 0x11, 0x00, 0x05, 0x54, 0x52, 0x41,
+ 0x44, 0x45, 0x07, 0x26, 0x7c, 0x2b, 0x69, 0x6e,
+ 0x76, 0x3e
+ ];
+ for i in action.iter() { text.push(*i); }
+
+ text.insert(0, text.len() as u8 + 1); // Insert data length as first byte.
+
+ text // Return created array
+}
diff --git a/src/server/mod.rs b/src/server/mod.rs
index e741e07..cb241f2 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -1,3 +1,4 @@
pub mod auto;
+pub mod cmd;
pub mod room;
pub mod utils;
diff --git a/src/server/room/server.rs b/src/server/room/server.rs
index 4e857a3..c005e40 100644
--- a/src/server/room/server.rs
+++ b/src/server/room/server.rs
@@ -3,8 +3,8 @@ use std::io::{Read, Write};
use mio::{Poll, Token, Ready, PollOpt, Events};
use std::collections::HashMap;
use std::str::from_utf8;
-use crate::cmd::buddy_list::create_buddy_list_notify_command;
-use crate::cmd::text::create_text_command;
+use crate::server::cmd::buddy_list::create_buddy_list_notify_command;
+use crate::server::cmd::text::create_text_command;
// use crate::cmd::property::{create_property_update_command, create_property_request_command};
use crate::server::room::cmd::property::{create_property_update_command, create_property_request_command};
use rand::Rng;