diff options
| author | Fuwn <[email protected]> | 2021-05-17 10:16:42 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-17 10:16:42 +0000 |
| commit | 1b482ab22031ab9a895b2567ba10a2e553752303 (patch) | |
| tree | db4874c46b25655ba7c94b0ab435fdb0d681af55 /src/server/cmd/commands/text.rs | |
| parent | refactor(global): whirl_config modulized (diff) | |
| download | whirl-1b482ab22031ab9a895b2567ba10a2e553752303.tar.xz whirl-1b482ab22031ab9a895b2567ba10a2e553752303.zip | |
refactor(global): even more modules becoming crates
I did multiple checks and **yes**, everything still works perfectly fine.
Diffstat (limited to 'src/server/cmd/commands/text.rs')
| -rw-r--r-- | src/server/cmd/commands/text.rs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/server/cmd/commands/text.rs b/src/server/cmd/commands/text.rs deleted file mode 100644 index 5019fc1..0000000 --- a/src/server/cmd/commands/text.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective -// SPDX-License-Identifier: GPL-3.0-only - -use std::str::from_utf8; - -use bytes::{BufMut, BytesMut}; - -use crate::server::cmd::{ - constants::TEXT, - extendable::{Creatable, ParsableWithArguments}, -}; - -pub struct Text { - pub sender: String, - pub content: String, -} -impl Creatable for Text { - fn create(self) -> Vec<u8> { - let mut command = BytesMut::new(); - - // Header - command.put_u8(0x01); - command.put_i8(TEXT as i8); - - // Content - // TODO: Find a way to parse ObjIds. - // - // The below byte is suspected to be the sender's short ObjId. - command.put_i8(0x00); - - command.put_u8(self.sender.len() as u8); - command.put_slice(self.sender.as_bytes()); - command.put_u8(self.content.len() as u8); - command.put_slice(self.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 - } -} -impl ParsableWithArguments for Text { - /// The first and only element of `args` *should* be the username of the - /// sender. - /// - /// There isn't anything currently stopping someone from passing some other - /// value so that might be annoying at times. - /// - /// Realistically, this method is mostly static so the username will *always* - /// be passed properly unless someone intentionally commits breaking changes - /// on purpose regarding what is passed to to this method where called. - /// - /// It would be neat to have some sort of ability to statically check if the - /// `args` argument contains x number of elements at compile time or - /// something of the sort but the Rust RFC is probably not focused on that. - /// - /// So, right now, trust is in the developers' hands to make sure to pass the - /// right -- number -- of elements to `args`. - fn parse(data: Vec<u8>, args: &[&str]) -> Self { - Self { - sender: args[0].to_string(), - content: from_utf8(&data[6..]).unwrap().to_string(), - } - } -} |