aboutsummaryrefslogtreecommitdiff
path: root/src/server/cmd
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-04-23 18:27:51 -0700
committerFuwn <[email protected]>2021-04-23 18:27:51 -0700
commitc58057b38550b94be623526481a31c7fc346a929 (patch)
tree7d851d0cf761fe4261dd5563f99e18d6c974d80b /src/server/cmd
parentMerge branch 'tokio-re' of https://github.com/Whirlsplash/whirl into tokio-re (diff)
downloadwhirl-c58057b38550b94be623526481a31c7fc346a929.tar.xz
whirl-c58057b38550b94be623526481a31c7fc346a929.zip
major: :star:
Diffstat (limited to 'src/server/cmd')
-rw-r--r--src/server/cmd/action.rs6
-rw-r--r--src/server/cmd/buddy_list.rs20
-rw-r--r--src/server/cmd/mod.rs1
-rw-r--r--src/server/cmd/property.rs5
-rw-r--r--src/server/cmd/session.rs8
-rw-r--r--src/server/cmd/text.rs71
6 files changed, 65 insertions, 46 deletions
diff --git a/src/server/cmd/action.rs b/src/server/cmd/action.rs
new file mode 100644
index 0000000..1cf9086
--- /dev/null
+++ b/src/server/cmd/action.rs
@@ -0,0 +1,6 @@
+pub fn create_action_command() -> [u8; 18] {
+ [
+ 0x12, 0x01, 0x11, 0x00, 0x05, 0x54, 0x52, 0x41, 0x44, 0x45, 0x07, 0x26, 0x7c, 0x2b, 0x69, 0x6e,
+ 0x76, 0x3e,
+ ]
+}
diff --git a/src/server/cmd/buddy_list.rs b/src/server/cmd/buddy_list.rs
index cbddc19..ba938f5 100644
--- a/src/server/cmd/buddy_list.rs
+++ b/src/server/cmd/buddy_list.rs
@@ -1,12 +1,14 @@
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); // ^
+ 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
+ buddy_list_notify // Return created array
}
diff --git a/src/server/cmd/mod.rs b/src/server/cmd/mod.rs
index 5e5bcd9..6db7826 100644
--- a/src/server/cmd/mod.rs
+++ b/src/server/cmd/mod.rs
@@ -1,3 +1,4 @@
+pub mod action;
pub mod buddy_list;
pub mod property;
pub mod session;
diff --git a/src/server/cmd/property.rs b/src/server/cmd/property.rs
index eaa4cc1..1530f58 100644
--- a/src/server/cmd/property.rs
+++ b/src/server/cmd/property.rs
@@ -1,6 +1,7 @@
-use bytes::BytesMut;
use std::str::from_utf8;
+use bytes::BytesMut;
+
pub fn parse_property_set_command(command: BytesMut) -> String {
- from_utf8(command.get(8..).unwrap()).unwrap().to_string()
+ from_utf8(command.get(8..).unwrap()).unwrap().to_string()
}
diff --git a/src/server/cmd/session.rs b/src/server/cmd/session.rs
index 9d48bcc..97efc8f 100644
--- a/src/server/cmd/session.rs
+++ b/src/server/cmd/session.rs
@@ -1,6 +1,6 @@
pub struct SessionInitializationCommand {
- // pub protocol: usize,
- // pub client: String,
- pub username: String,
- // pub password: String,
+ // pub protocol: usize,
+ // pub client: String,
+ pub username: String,
+ // pub password: String,
}
diff --git a/src/server/cmd/text.rs b/src/server/cmd/text.rs
index a0ada32..cc306db 100644
--- a/src/server/cmd/text.rs
+++ b/src/server/cmd/text.rs
@@ -1,46 +1,55 @@
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.
+ 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
+ text // Return created array
}
// TODO: Get this working!
-// pub fn get_message_from_text_command(buffer: &'static [u8; 1024]) -> &'static str {
-// from_utf8(
+// 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.
+ 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 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); }
+ 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.insert(0, text.len() as u8 + 1); // Insert data length as first byte.
- text // Return created array
+ text // Return created array
}