diff options
| author | Fuwn <[email protected]> | 2021-04-23 18:27:51 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-04-23 18:27:51 +0000 |
| commit | 70e6a577025651639c745f029fbeb36922438939 (patch) | |
| tree | 354756327afab7744392752db12f421a0040e4f3 /src/server/cmd/text.rs | |
| parent | Merge branch 'tokio-re' of https://github.com/Whirlsplash/whirl into tokio-re (diff) | |
| download | whirl-70e6a577025651639c745f029fbeb36922438939.tar.xz whirl-70e6a577025651639c745f029fbeb36922438939.zip | |
major: :star:
Diffstat (limited to 'src/server/cmd/text.rs')
| -rw-r--r-- | src/server/cmd/text.rs | 71 |
1 files changed, 40 insertions, 31 deletions
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 } |