variable renamed

This commit is contained in:
Martin Brodbeck 2023-10-04 10:15:27 +02:00
parent d5cd57261e
commit ffbfa37ba2

View file

@ -127,7 +127,7 @@ fn main() -> std::io::Result<()> {
debug!("Morserino chat server started."); debug!("Morserino chat server started.");
let mut receivers2: HashMap<String, DateTime<Local>> = HashMap::new(); let mut subscribers: HashMap<String, DateTime<Local>> = HashMap::new();
loop { loop {
let mut buf = [0; 64]; let mut buf = [0; 64];
@ -138,7 +138,7 @@ fn main() -> std::io::Result<()> {
Ok((num, s)) => (num, s), Ok((num, s)) => (num, s),
Err(_) => { Err(_) => {
debug!("Sending keepalive pakets …"); debug!("Sending keepalive pakets …");
for rec in &receivers2 { for rec in &subscribers {
socket.send_to(b"", rec.0).unwrap(); socket.send_to(b"", rec.0).unwrap();
} }
continue; continue;
@ -151,25 +151,25 @@ fn main() -> std::io::Result<()> {
thread::sleep(core::time::Duration::from_millis(200)); // Anti floog (?) 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}"); debug!("Client known: {client_addr}");
if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) { if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) {
debug!("Removing client {client_addr} as requested."); debug!("Removing client {client_addr} as requested.");
socket socket
.send_to(mopp(speed, b":bye").as_slice(), &client_addr) .send_to(mopp(speed, b":bye").as_slice(), &client_addr)
.unwrap(); .unwrap();
receivers2.remove(&client_addr); subscribers.remove(&client_addr);
} else { } else {
broadcast(&socket, &receivers2, &client_addr, data); broadcast(&socket, &subscribers, &client_addr, data);
receivers2.insert(client_addr.to_owned(), Local::now()); subscribers.insert(client_addr.to_owned(), Local::now());
} }
} else if strip_header(data) == strip_header(mopp(speed, b"hi").as_slice()) { } else if strip_header(data) == strip_header(mopp(speed, b"hi").as_slice()) {
debug!("Adding new client {client_addr}"); debug!("Adding new client {client_addr}");
if receivers2.len() < MAX_CLIENTS { if subscribers.len() < MAX_CLIENTS {
receivers2.insert(client_addr.to_owned(), Local::now()); subscribers.insert(client_addr.to_owned(), Local::now());
socket socket
.send_to( .send_to(
mopp(speed, format!("{}{}", ":hi ", receivers2.len()).as_bytes()) mopp(speed, format!("{}{}", ":hi ", subscribers.len()).as_bytes())
.as_slice(), .as_slice(),
&client_addr, &client_addr,
) )
@ -185,7 +185,7 @@ fn main() -> std::io::Result<()> {
} }
let timestamp = Local::now(); let timestamp = Local::now();
for cl in &receivers2 { for cl in &subscribers {
if *cl.1 + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp { if *cl.1 + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp {
debug!("Removing outdated client {}", cl.0); debug!("Removing outdated client {}", cl.0);
socket socket
@ -193,6 +193,6 @@ fn main() -> std::io::Result<()> {
.unwrap(); .unwrap();
} }
} }
receivers2.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp); subscribers.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp);
} }
} }