re-roll if name is taken
This commit is contained in:
parent
04b350d598
commit
3b2a5b2c49
1 changed files with 18 additions and 9 deletions
|
@ -37,20 +37,29 @@ pub async fn websocket_on_connection(stream: WebSocket, state: Arc<AppState>, ad
|
|||
let mut map = HashMap::new();
|
||||
map.insert(addr, dm_tx.clone());
|
||||
|
||||
state
|
||||
.users_tx
|
||||
.send(UserHandlerMessage::NewUser(
|
||||
User::new(
|
||||
format!(
|
||||
// Roll for username and re-roll if taken
|
||||
let mut username;
|
||||
|
||||
loop {
|
||||
username = format!(
|
||||
"{} {}",
|
||||
state.first_names.choose(&mut rand::thread_rng()).unwrap(),
|
||||
state.last_names.choose(&mut rand::thread_rng()).unwrap(),
|
||||
),
|
||||
dm_tx.clone(),
|
||||
),
|
||||
);
|
||||
|
||||
if !state.reserved_names.read().unwrap().contains(&username) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
state
|
||||
.users_tx
|
||||
.send(UserHandlerMessage::NewUser(
|
||||
User::new(username, dm_tx.clone()),
|
||||
addr,
|
||||
))
|
||||
.await.expect("User handler is down");
|
||||
.await
|
||||
.expect("User handler is down");
|
||||
|
||||
// Subscribe to receive from global broadcast channel
|
||||
let mut rx = state.broadcast_tx.subscribe();
|
||||
|
|
Loading…
Add table
Reference in a new issue