whoops the fix made your user duplicate

This commit is contained in:
Arthur Beck 2025-03-04 16:46:38 -06:00
parent c77a44f596
commit 1a1e56aef0
Signed by: ArthurB
GPG key ID: ACE3D14F5CEF14BF

View file

@ -159,14 +159,6 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
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
.write_fmt(format_args!(
"\x1b[0m\x1b[32;1mYour token to rejoin after quitting is {}.\x1b[0m\n",
@ -180,7 +172,19 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
token: "".to_owned(),
};
channel.lock().unwrap().online_users.push(user.clone());
let mut broke = false;
for usr in &mut channel.lock().unwrap().online_users {
if usr.name == user.name {
usr.status = user.status.clone();
usr.token = user.token.clone();
broke = true;
break;
}
}
if !broke {
channel.lock().unwrap().online_users.push(user.clone());
}
let (recieve_terminate_send, recieve_terminate_recv) = std::sync::mpsc::channel::<()>();
let recieve_thread: JoinHandle<_>;