diff --git a/server/src/user_handler.rs b/server/src/user_handler.rs index fedad2b..53f4ce9 100644 --- a/server/src/user_handler.rs +++ b/server/src/user_handler.rs @@ -192,6 +192,28 @@ impl UserHandler { .unwrap() .contains_key(&new_name) { + // Copy over new tx + self.state + .offline_users + .read() + .unwrap() + .get(&new_name) + .unwrap() + .write() + .unwrap() + .tx = self + .state + .online_users + .read() + .unwrap() + .get(&addr) + .unwrap() + .read() + .unwrap() + .tx + .clone(); + + // Move offline user object to online self.state .online_users .write() @@ -258,15 +280,6 @@ impl UserHandler { .unwrap() .change_name(username); - // send the user their new name - self.send_message_addr( - addr, - SendUserUpdate(UserUpdate { - username: new_name.clone(), - }), - ) - .await; - // Send chat updates let msg = format! { "{0} changed name to {1}.", @@ -278,6 +291,15 @@ impl UserHandler { .unwrap(); } + // Send the user their new name + self.send_message_addr( + addr, + SendUserUpdate(UserUpdate { + username: new_name.clone(), + }), + ) + .await; + // Send client updates broadcast_tx .send(meta_games_browser_update(&self.state))