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.");
let mut receivers2: HashMap<String, DateTime<Local>> = HashMap::new();
let mut subscribers: HashMap<String, DateTime<Local>> = 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);
}
}