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<(), ()> {
|
pub fn register_user(&mut self, addr: &SocketAddr) -> Result<(), ()> {
|
||||||
let mut user;
|
let mut users = self.users.lock().unwrap();
|
||||||
{
|
let cloned = {
|
||||||
user = self.users.lock().unwrap().get_mut(addr).cloned();
|
users.get(addr).cloned()
|
||||||
}
|
};
|
||||||
match user {
|
|
||||||
Some(mut user) => {
|
match cloned {
|
||||||
if !user.is_valid() || user.is_registered() {
|
Some(cloned) => {
|
||||||
|
if !cloned.is_valid() || cloned.is_registered() {
|
||||||
return Err(());
|
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(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
user.register(); // TODO: This is done on the cloned user -- won't save
|
users.get_mut(addr).unwrap().register();
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
None => Err(())
|
None => Err(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue