diff options
| author | Fuwn <[email protected]> | 2021-03-21 11:37:12 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-03-21 11:37:12 +0000 |
| commit | c5a240dbfa594ccfe78e369faf04b3192a64cdd5 (patch) | |
| tree | 6628ee7708aefd8597e8ae8c1522768e3d54bbd1 | |
| parent | Added username support for text (diff) | |
| download | whirl-c5a240dbfa594ccfe78e369faf04b3192a64cdd5.tar.xz whirl-c5a240dbfa594ccfe78e369faf04b3192a64cdd5.zip | |
etc: development testing
append random integer to end of "User" for testing purposes.
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/server/world.rs | 17 |
2 files changed, 14 insertions, 4 deletions
@@ -19,3 +19,4 @@ mio = "0.6" log = "0.4.14" pretty_env_logger = "0.4.0" dotenv = "0.15.0" +rand = "0.8.3" diff --git a/src/server/world.rs b/src/server/world.rs index a7c65b3..340942f 100644 --- a/src/server/world.rs +++ b/src/server/world.rs @@ -6,6 +6,7 @@ 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 rand::Rng; // pub struct ClientSocket { // tcp_stream: TcpStream, @@ -123,10 +124,18 @@ impl WorldServer { ).unwrap(); info!("message: {}", message); - for mut socket in &sockets { - // Using User as a placeholder. Ideally, this would print out the username of the one who sent it. - socket.1.write_all(&create_text_command("User", message)).unwrap(); - } + // Using User as a placeholder. Ideally, this would print out the username of + // the one who sent it. + broadcast_to_all_clients( + &sockets, + &create_text_command( + // Random integer is added to the end of "User", just a development + // proof-of-concept. Since at this stage usernames aren't exactly kept, + // we can identify message senders as their connection token; `token.0`. + &format!("User{}", rand::thread_rng().gen_range(1..150).to_string()), + message + ) + ); } // SESSEXIT 7 => { |