Typo
This commit is contained in:
parent
30a8894f76
commit
8edf4cad62
1 changed files with 14 additions and 1 deletions
|
|
@ -37,6 +37,8 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let db = Users::default();
|
let db = Users::default();
|
||||||
|
|
||||||
|
let mut valid_name = true;
|
||||||
|
|
||||||
// Infinite loop to always listen to new connections on this IP/PORT
|
// Infinite loop to always listen to new connections on this IP/PORT
|
||||||
loop {
|
loop {
|
||||||
let (stream, address) = listener.accept().await?;
|
let (stream, address) = listener.accept().await?;
|
||||||
|
|
@ -57,13 +59,14 @@ async fn main() -> Result<()> {
|
||||||
// we won't process until we find one.
|
// we won't process until we find one.
|
||||||
match framed.next().await {
|
match framed.next().await {
|
||||||
Some(Ok(username)) => {
|
Some(Ok(username)) => {
|
||||||
if !username.is_empty() && name.chars().all(char::is_alphanumeric) {
|
if !username.is_empty() && username.chars().all(char::is_alphanumeric) {
|
||||||
name = username.clone();
|
name = username.clone();
|
||||||
db.0.lock().unwrap().insert(username.clone(), address);
|
db.0.lock().unwrap().insert(username.clone(), address);
|
||||||
let message = compose_message(username.clone(), db.clone());
|
let message = compose_message(username.clone(), db.clone());
|
||||||
info!("Adding username: {username} to db");
|
info!("Adding username: {username} to db");
|
||||||
let _ = framed.send(message).await;
|
let _ = framed.send(message).await;
|
||||||
} else {
|
} else {
|
||||||
|
valid_name = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +80,10 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !valid_name {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let b = BroadcastMessage(
|
let b = BroadcastMessage(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
format!("* {} has entered the room", name),
|
format!("* {} has entered the room", name),
|
||||||
|
|
@ -123,7 +130,13 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if !valid_name {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compose_message(name: String, db: Users) -> String {
|
fn compose_message(name: String, db: Users) -> String {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue