Fix users not getting registered
This commit is contained in:
parent
e7ccea3c8e
commit
d7b39841be
1 changed files with 10 additions and 9 deletions
|
@ -25,20 +25,21 @@ impl Context {
|
|||
}
|
||||
|
||||
pub fn register_user(&mut self, addr: &SocketAddr) -> Result<(), ()> {
|
||||
let mut user;
|
||||
{
|
||||
user = self.users.lock().unwrap().get_mut(addr).cloned();
|
||||
}
|
||||
match user {
|
||||
Some(mut user) => {
|
||||
if !user.is_valid() || user.is_registered() {
|
||||
let mut users = self.users.lock().unwrap();
|
||||
let cloned = {
|
||||
users.get(addr).cloned()
|
||||
};
|
||||
|
||||
match cloned {
|
||||
Some(cloned) => {
|
||||
if !cloned.is_valid() || cloned.is_registered() {
|
||||
return Err(());
|
||||
}
|
||||
if self.users.lock().unwrap().iter().any(|(k, v)| k != addr && v.nickname == user.nickname) {
|
||||
if users.iter().any(|(k, v)| k != addr && v.nickname == cloned.nickname) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
user.register(); // TODO: This is done on the cloned user -- won't save
|
||||
users.get_mut(addr).unwrap().register();
|
||||
Ok(())
|
||||
},
|
||||
None => Err(())
|
||||
|
|
Loading…
Reference in a new issue