diff options
| author | Fuwn <[email protected]> | 2021-03-22 21:50:26 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-03-22 21:50:26 +0000 |
| commit | d4e5c30fd9d2eecdd2af55fd4ee5c0da4cda3f55 (patch) | |
| tree | 32b33ace94dbb89cc67aa3cad6e06e9376902b88 /src/server/auto | |
| parent | feature: Use feature "hash_set_entry" (diff) | |
| download | whirl-d4e5c30fd9d2eecdd2af55fd4ee5c0da4cda3f55.tar.xz whirl-d4e5c30fd9d2eecdd2af55fd4ee5c0da4cda3f55.zip | |
etc: Correct struct names
Diffstat (limited to 'src/server/auto')
| -rw-r--r-- | src/server/auto/cmd/mod.rs | 2 | ||||
| -rw-r--r-- | src/server/auto/cmd/property.rs | 47 | ||||
| -rw-r--r-- | src/server/auto/cmd/room.rs | 27 | ||||
| -rw-r--r-- | src/server/auto/constants.rs | 13 | ||||
| -rw-r--r-- | src/server/auto/mod.rs | 2 | ||||
| -rw-r--r-- | src/server/auto/server.rs | 47 | ||||
| -rw-r--r-- | src/server/auto/utils.rs | 0 |
7 files changed, 84 insertions, 54 deletions
diff --git a/src/server/auto/cmd/mod.rs b/src/server/auto/cmd/mod.rs index f348cd0..addf7a5 100644 --- a/src/server/auto/cmd/mod.rs +++ b/src/server/auto/cmd/mod.rs @@ -1 +1 @@ -pub mod property; +pub mod room; diff --git a/src/server/auto/cmd/property.rs b/src/server/auto/cmd/property.rs deleted file mode 100644 index b75efad..0000000 --- a/src/server/auto/cmd/property.rs +++ /dev/null @@ -1,47 +0,0 @@ -pub fn create_property_update_command() -> [u8; 161] { // 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 - - [ - 0xA1, 0xFF, 0x10, 0x08, 0x80, 0x01, 0x07, 0x31, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x1B, 0x80, - 0x01, 0x0C, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x73, - 0x33, 0x64, 0x2E, 0x63, 0x6F, 0x6D, 0x1A, 0x80, - 0x01, 0x15, 0x6D, 0x61, 0x69, 0x6C, 0x2E, 0x75, - 0x73, 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, 0x33, 0x03, 0x80, 0x01, 0x02, 0x32, - 0x34, 0x01, 0x80, 0x01, 0x0C, 0x57, 0x4F, 0x52, - 0x4C, 0x44, 0x53, 0x4D, 0x41, 0x53, 0x54, 0x45, - 0x52 - ]: [u8; 161] -} - -pub fn create_property_request_command() -> [u8; 22] { - [ - 0x16, 0x01, 0x06, 0x04, 0x01, 0x30, 0x0f, 0x01, - 0x33, 0x08, 0x07, 0x31, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x03, 0x02, 0x32, 0x34 - ]: [u8; 22] -} diff --git a/src/server/auto/cmd/room.rs b/src/server/auto/cmd/room.rs new file mode 100644 index 0000000..ff839f3 --- /dev/null +++ b/src/server/auto/cmd/room.rs @@ -0,0 +1,27 @@ +pub fn create_room_id_redirect_command(room_name: &str, room_id: usize) -> Vec<u8> { + let mut room_id_redirect = Vec::new(); + // room_id_redirect.push(room_id_redirect.len() as u8 + 1); // Data length + room_id_redirect.push(0x01); // ? + room_id_redirect.push(0x1A); // Command type1 + room_id_redirect.push(room_name.len() as u8); // UTF/ room name length + for i in room_name.bytes() { room_id_redirect.push(i); } // Push `room_name` + // for i in "<dimension-1>".bytes() { room_id_redirect.push(i); } // Push room number + + // Room number + room_id_redirect.push(0x00); + room_id_redirect.push(room_id as u8); + + // IP + room_id_redirect.push(0x00); + room_id_redirect.push(0x00); + room_id_redirect.push(0x00); + room_id_redirect.push(0x00); + + // Port + room_id_redirect.push(0x16); + room_id_redirect.push(0x29); + + room_id_redirect.insert(0, room_id_redirect.len() as u8 + 1); // Data length + + room_id_redirect +} diff --git a/src/server/auto/constants.rs b/src/server/auto/constants.rs new file mode 100644 index 0000000..10c9439 --- /dev/null +++ b/src/server/auto/constants.rs @@ -0,0 +1,13 @@ +use std::collections::HashMap; + +pub static ROOM_IDS: phf::Map<&'static str, &'static i32> = phf::phf_map! { +"ChatElevator<dimension-1>" => &4, +"IconViewRoom1Enter<dimension-1>" => &3, +"ChatHall<dimension-1>" => &9, +"IconViewRoom1<dimension-1>" => &12, +"IconViewRoom1g<dimension-1>" => &27230, +"ReceptionView1<dimension-1>" => &6, +"ReceptionView2<dimension-1>" => &5, +"Reception<dimension-1>" => &1, +"staircase1<dimension-1>" => &11, +}; diff --git a/src/server/auto/mod.rs b/src/server/auto/mod.rs index 7ceb58d..741d763 100644 --- a/src/server/auto/mod.rs +++ b/src/server/auto/mod.rs @@ -1,3 +1,3 @@ pub mod cmd; +// pub mod constants; pub mod server; -pub mod utils; diff --git a/src/server/auto/server.rs b/src/server/auto/server.rs index 87f5e07..361ae00 100644 --- a/src/server/auto/server.rs +++ b/src/server/auto/server.rs @@ -1,15 +1,20 @@ use mio::net::{TcpListener, TcpStream}; use std::io::{Read, Write}; use mio::{Poll, Token, Ready, PollOpt, Events}; -use std::collections::HashMap; +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::property::{create_property_update_command, create_property_request_command}; -use crate::server::auto::cmd::property::{create_property_update_command, create_property_request_command}; +use crate::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; +// pub struct ClientSocket { +// tcp_stream: TcpStream, +// username: String, +// } + pub struct AutoServer; impl AutoServer { pub fn new(listener: TcpListener) { @@ -25,6 +30,8 @@ impl AutoServer { let mut sockets: HashMap<Token, TcpStream> = HashMap::new(); let mut requests: HashMap<Token, Vec<u8>> = HashMap::new(); let mut buffer = [0 as u8; 1024]; + // let mut room_ids: HashMap<&str, i32> = HashMap::new(); + let mut room_ids: HashSet<String> = HashSet::new(); let mut events = Events::with_capacity(1024); loop { @@ -102,10 +109,40 @@ impl AutoServer { sockets.get_mut(&token).unwrap() .write_all(&create_buddy_list_notify_command("Wirlaburla")) .unwrap(); - info!("sent buddy notify update command") + info!("sent buddy notify update command"); } // ROOMIDRQ - 20 => info!("received room id request command"), + 20 => { + info!("received room id request command"); + + let room_name = from_utf8( + &buffer[4..*&buffer.get(0).unwrap().to_owned() as usize] + ).unwrap(); + let mut room_id = 0; + if !room_ids.contains(room_name) { + room_ids.insert(room_name.to_string()); + let new = room_ids.iter() + .position(|i| i == room_name) + .unwrap(); + debug!("inserted room '{}' as '{}'", room_name, new); + } else { + let pos = room_ids + .iter() + .position(|i| i == room_name) + .unwrap(); + debug!("found room '{}' as '{}'", room_name, pos); + room_id = pos; + } + debug!("room name: {}, room id: {}", room_name, room_id); + debug!("{:?}", room_ids); + + // Passing `0` as `room_id` parameter as currently there is + // no way to find out a room's ID based on it's name. + sockets.get_mut(&token).unwrap() + .write_all(&create_room_id_redirect_command(room_name, room_id)) + .unwrap(); + info!("sent redirect id command") + } // TEXT 14 => { info!("received text command"); diff --git a/src/server/auto/utils.rs b/src/server/auto/utils.rs deleted file mode 100644 index e69de29..0000000 --- a/src/server/auto/utils.rs +++ /dev/null |