From c77a44f596bec7811a557bb67f433308162061c1 Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Tue, 4 Mar 2025 16:43:36 -0600 Subject: [PATCH] maybe fix bug with rejoining --- src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1c0fc7e..8e573e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,14 +119,6 @@ fn handle_client(mut stream: TcpStream, channel: Channel) { if user.token != String::from_utf8_lossy(&(buf[..i])) { break 'bufreadloop2; } - let mut i = 0usize; - for user in &channel.lock().unwrap().online_users { - if user.name == new_name { - channel.lock().unwrap().online_users.swap_remove(i); - break; - } - i += 1; - } break 'bufreadloop; } if i < 50 { @@ -167,6 +159,14 @@ fn handle_client(mut stream: TcpStream, channel: Channel) { token: format!("{:x}", random::random::()), }; + for usr in &mut channel.lock().unwrap().online_users { + if usr.name == user.name { + usr.status = user.status.clone(); + usr.token = user.token.clone(); + break; + } + } + stream .write_fmt(format_args!( "\x1b[0m\x1b[32;1mYour token to rejoin after quitting is {}.\x1b[0m\n",