diff options
| author | Fuwn <[email protected]> | 2021-03-23 13:03:15 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-03-23 13:03:15 -0700 |
| commit | 4e7697c558fa2134e1fc01efc72990138f2745e0 (patch) | |
| tree | 553ae8fdaa8cd09e984994c7b8edcc7ba769ea84 | |
| parent | fix: `room_id` not being set and sent (diff) | |
| download | whirl-4e7697c558fa2134e1fc01efc72990138f2745e0.tar.xz whirl-4e7697c558fa2134e1fc01efc72990138f2745e0.zip | |
feature: Send WORLDSMASTER greeting on join
Created function `create_text_command_with_action` which is stable, but only with the preset action. Will expand on this once an understanding of how actions work is met.
| -rw-r--r-- | src/cmd/text.rs | 28 | ||||
| -rw-r--r-- | src/server/auto/server.rs | 20 |
2 files changed, 44 insertions, 4 deletions
diff --git a/src/cmd/text.rs b/src/cmd/text.rs index 6fc42be..a0ada32 100644 --- a/src/cmd/text.rs +++ b/src/cmd/text.rs @@ -17,4 +17,30 @@ pub fn create_text_command(user: &str, message: &str) -> Vec<u8> { // from_utf8( // &buffer[6..*&buffer.get(0).unwrap().to_owned() as usize] // ).unwrap() -// }
\ No newline at end of file +// } + +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/auto/server.rs b/src/server/auto/server.rs index 21a978c..7437501 100644 --- a/src/server/auto/server.rs +++ b/src/server/auto/server.rs @@ -4,7 +4,7 @@ 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; +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 super::cmd::room::create_room_id_redirect_command; use rand::Rng; @@ -99,13 +99,27 @@ impl AutoServer { info!("received session initialization command"); sockets.get_mut(&token).unwrap() .write_all(&create_property_request_command()).unwrap(); - info!("sent session initialization command") + info!("sent session initialization command"); } // PROPSET - 15 => info!("received property set command"), + 15 => { + info!("received property set command"); + sockets.get_mut(&token).unwrap() + .write_all(&create_text_command_with_action( + "WORLDSMASTER", + "Welcome to Whirlsplash!" + )).unwrap(); + info!("sent worldsmaster greeting"); + }, // BUDDYLISTUPDATE 29 => { info!("received buddy list update command"); + + let received_buddy = from_utf8( + &buffer[4..*&buffer.get(3).unwrap().to_owned() as usize] + ).unwrap(); + debug!("received buddy: {}", received_buddy); + sockets.get_mut(&token).unwrap() .write_all(&create_buddy_list_notify_command("Wirlaburla")) .unwrap(); |