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

View File

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