maybe fix bug with rejoining

This commit is contained in:
Arthur Beck 2025-03-04 16:43:36 -06:00
parent 541abd1d6a
commit c77a44f596
Signed by: ArthurB
GPG key ID: ACE3D14F5CEF14BF

View file

@ -119,14 +119,6 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
if user.token != String::from_utf8_lossy(&(buf[..i])) { if user.token != String::from_utf8_lossy(&(buf[..i])) {
break 'bufreadloop2; 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; break 'bufreadloop;
} }
if i < 50 { if i < 50 {
@ -167,6 +159,14 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
token: format!("{:x}", random::random::<u128>()), token: format!("{:x}", random::random::<u128>()),
}; };
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 stream
.write_fmt(format_args!( .write_fmt(format_args!(
"\x1b[0m\x1b[32;1mYour token to rejoin after quitting is {}.\x1b[0m\n", "\x1b[0m\x1b[32;1mYour token to rejoin after quitting is {}.\x1b[0m\n",