From ffbfa37ba2e15f5050989247044c1dcc747e4b26 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 4 Oct 2023 10:15:27 +0200 Subject: [PATCH] variable renamed --- src/main.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4ab29be..4e56d33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,7 @@ fn main() -> std::io::Result<()> { debug!("Morserino chat server started."); - let mut receivers2: HashMap> = HashMap::new(); + let mut subscribers: HashMap> = HashMap::new(); loop { let mut buf = [0; 64]; @@ -138,7 +138,7 @@ fn main() -> std::io::Result<()> { Ok((num, s)) => (num, s), Err(_) => { debug!("Sending keepalive pakets …"); - for rec in &receivers2 { + for rec in &subscribers { socket.send_to(b"", rec.0).unwrap(); } continue; @@ -151,25 +151,25 @@ fn main() -> std::io::Result<()> { thread::sleep(core::time::Duration::from_millis(200)); // Anti floog (?) - if receivers2.contains_key(&client_addr) { + if subscribers.contains_key(&client_addr) { debug!("Client known: {client_addr}"); if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) { debug!("Removing client {client_addr} as requested."); socket .send_to(mopp(speed, b":bye").as_slice(), &client_addr) .unwrap(); - receivers2.remove(&client_addr); + subscribers.remove(&client_addr); } else { - broadcast(&socket, &receivers2, &client_addr, data); - receivers2.insert(client_addr.to_owned(), Local::now()); + broadcast(&socket, &subscribers, &client_addr, data); + subscribers.insert(client_addr.to_owned(), Local::now()); } } else if strip_header(data) == strip_header(mopp(speed, b"hi").as_slice()) { debug!("Adding new client {client_addr}"); - if receivers2.len() < MAX_CLIENTS { - receivers2.insert(client_addr.to_owned(), Local::now()); + if subscribers.len() < MAX_CLIENTS { + subscribers.insert(client_addr.to_owned(), Local::now()); socket .send_to( - mopp(speed, format!("{}{}", ":hi ", receivers2.len()).as_bytes()) + mopp(speed, format!("{}{}", ":hi ", subscribers.len()).as_bytes()) .as_slice(), &client_addr, ) @@ -185,7 +185,7 @@ fn main() -> std::io::Result<()> { } let timestamp = Local::now(); - for cl in &receivers2 { + for cl in &subscribers { if *cl.1 + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp { debug!("Removing outdated client {}", cl.0); socket @@ -193,6 +193,6 @@ fn main() -> std::io::Result<()> { .unwrap(); } } - receivers2.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp); + subscribers.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp); } }