Verifies client's name does not have whitespace

This commit is contained in:
Phuntsok Drak-pa 2018-03-23 02:19:09 +01:00
parent 1873df9ef0
commit 475724a306
1 changed files with 3 additions and 23 deletions

View File

@ -164,27 +164,7 @@ fn handle_client(stream: TcpStream, clients: Arc<Mutex<UserMap>>) {
})
}
// // Initialization: Ask user for his name
// let name = match (|| {
// send!("Welcome!");
// send!("Please enter your name:");
// let name = receive!();
// println!("{} Client {} identified as {}", get_time(), client, name);
// Ok(name)
// })()
// {
// Ok(name) => name,
// Err(e) => {
// println!(
// "{} Client {} disappeared during initialization: {}",
// get_time(),
// client,
// e
// );
// return ();
// }
// };
// Get user's name
let name: String = match (|| loop {
match receive!() {
input => {
@ -192,11 +172,9 @@ fn handle_client(stream: TcpStream, clients: Arc<Mutex<UserMap>>) {
if spliced_input.len() != 4 && spliced_input.len() != 5
|| spliced_input[0] != "PROT"
{
// send!("BAD REQ");
return Err(Error::new(ErrorKind::Other, "BAD REQ"));
}
if spliced_input[1] != ::PROTOCOL {
// send!("BAD PROT");
return Err(Error::new(ErrorKind::Other, "BAD PROT"));
}
if spliced_input.len() == 5 {
@ -218,6 +196,8 @@ fn handle_client(stream: TcpStream, clients: Arc<Mutex<UserMap>>) {
} else {
send!("NAME FAILURE");
}
} else {
return Err(Error::new(ErrorKind::Other, "BAD REQ"));
}
}