aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-03-20 17:46:22 -0700
committerFuwn <[email protected]>2021-03-20 17:46:22 -0700
commitfcb9f40eac3b512d5c6f4c9fa77d3b15c30d993a (patch)
tree488a1c6866bcd53512e31f638eed430b8ef49f23 /src
parentformat: remove unnecessary debug statements, format (diff)
downloadwhirl-fcb9f40eac3b512d5c6f4c9fa77d3b15c30d993a.tar.xz
whirl-fcb9f40eac3b512d5c6f4c9fa77d3b15c30d993a.zip
chore: create broadcast_to_all_clients() function, rename sub directory
Diffstat (limited to 'src')
-rw-r--r--src/cmd/buddy_list.rs (renamed from src/sub/buddy_list.rs)0
-rw-r--r--src/cmd/mod.rs (renamed from src/sub/mod.rs)0
-rw-r--r--src/cmd/property.rs (renamed from src/sub/property.rs)2
-rw-r--r--src/cmd/text.rs (renamed from src/sub/text.rs)0
-rw-r--r--src/lib.rs4
-rw-r--r--src/server/world.rs38
6 files changed, 26 insertions, 18 deletions
diff --git a/src/sub/buddy_list.rs b/src/cmd/buddy_list.rs
index 95b0fdd..95b0fdd 100644
--- a/src/sub/buddy_list.rs
+++ b/src/cmd/buddy_list.rs
diff --git a/src/sub/mod.rs b/src/cmd/mod.rs
index 05e4344..05e4344 100644
--- a/src/sub/mod.rs
+++ b/src/cmd/mod.rs
diff --git a/src/sub/property.rs b/src/cmd/property.rs
index 6bacc4e..9ec89a8 100644
--- a/src/sub/property.rs
+++ b/src/cmd/property.rs
@@ -55,7 +55,7 @@ pub fn create_property_update_command() -> [u8; 147] { // Vec<u8>
]: [u8; 147]
}
-// src\sub\property.rs:20:1
+// src\cmd\property.rs:20:1
pub fn create_property_request_command() -> [u8; 61] {
[
0x3D, 0x01, 0x06, 0x04, 0x01, 0x30, 0x01, 0x0C,
diff --git a/src/sub/text.rs b/src/cmd/text.rs
index b2cecef..b2cecef 100644
--- a/src/sub/text.rs
+++ b/src/cmd/text.rs
diff --git a/src/lib.rs b/src/lib.rs
index df9deae..58e81a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,8 +1,8 @@
-#![feature(type_ascription)] // src\sub\property.rs:37:2
+#![feature(type_ascription)] // src\cmd\property.rs:37:2
#[macro_use]
extern crate log;
-pub mod sub;
+pub mod cmd;
pub mod server;
pub mod utils;
diff --git a/src/server/world.rs b/src/server/world.rs
index 10f895a..ddefd39 100644
--- a/src/server/world.rs
+++ b/src/server/world.rs
@@ -3,9 +3,23 @@ use std::io::{Read, Write};
use mio::{Poll, Token, Ready, PollOpt, Events};
use std::collections::HashMap;
use std::str::from_utf8;
-use crate::sub::buddy_list::create_buddy_list_notify_command;
-use crate::sub::text::create_text_command;
-use crate::sub::property::{create_property_update_command, create_property_request_command};
+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};
+
+// pub struct ClientSocket {
+// tcp_stream: TcpStream,
+// username: String,
+// }
+
+fn broadcast_to_all_clients(
+ sockets: &HashMap<Token, TcpStream>,
+ message: &[u8]
+) -> () {
+ for mut socket in sockets {
+ socket.1.write_all(message).unwrap();
+ }
+}
pub struct WorldServer;
impl WorldServer {
@@ -76,19 +90,13 @@ impl WorldServer {
// PROPREQ
10 => {
info!("received property request command");
- sockets.get_mut(&token)
- .unwrap()
- .write_all(&create_property_update_command())
- .unwrap();
+ broadcast_to_all_clients(&sockets, &create_property_update_command());
info!("sent property update");
}
// SESSINIT
6 => {
info!("received session initialization command");
- sockets.get_mut(&token)
- .unwrap()
- .write_all(&create_property_request_command())
- .unwrap();
+ broadcast_to_all_clients(&sockets, &create_property_request_command());
info!("sent session initialization command")
}
// PROPSET
@@ -97,10 +105,10 @@ impl WorldServer {
29 => {
info!("received buddy list update command");
- sockets.get_mut(&token)
- .unwrap()
- .write_all(&create_buddy_list_notify_command("Wirlaburla"))
- .unwrap();
+ broadcast_to_all_clients(
+ &sockets,
+ &create_buddy_list_notify_command("Wirlaburla")
+ );
info!("sent buddy notify update command")
}
// ROOMIDRQ