From 2d4813d047fe859e9bdb29a00429c010c6a1d4fd Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Fri, 5 Jul 2019 23:37:36 +0000 Subject: [PATCH] Add Todo state to LoginStatus enum. --- src/client.rs | 11 ++++++++--- src/login.rs | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/client.rs b/src/client.rs index f5ff448..d5b1bdc 100644 --- a/src/client.rs +++ b/src/client.rs @@ -72,7 +72,7 @@ impl Client { control_tx: None, control_rx: control_rx, - login_status: LoginStatus::Pending, + login_status: LoginStatus::Todo, rooms: room::RoomMap::new(), users: user::UserMap::new(), @@ -94,6 +94,8 @@ impl Client { .unwrap(), )); + self.login_status = LoginStatus::AwaitingResponse; + self.send_to_server(server::ServerRequest::SetListenPortRequest( server::SetListenPortRequest { port: config::LISTEN_PORT, @@ -210,7 +212,10 @@ impl Client { let username = config::USERNAME.to_string(); let response = match self.login_status { - LoginStatus::Pending => control::LoginStatusResponse::Pending { username: username }, + LoginStatus::Todo => control::LoginStatusResponse::Pending { username: username }, + LoginStatus::AwaitingResponse => { + control::LoginStatusResponse::Pending { username: username } + } LoginStatus::Success(ref motd) => control::LoginStatusResponse::Success { username: username, @@ -528,7 +533,7 @@ impl Client { } fn handle_login_response(&mut self, login: server::LoginResponse) { - if let LoginStatus::Pending = self.login_status { + if let LoginStatus::AwaitingResponse = self.login_status { match login { server::LoginResponse::LoginOk { motd, diff --git a/src/login.rs b/src/login.rs index 14fba48..65fe6b4 100644 --- a/src/login.rs +++ b/src/login.rs @@ -6,10 +6,11 @@ /// successfully logged in, the client can interact with the server. #[derive(Clone, Debug)] pub enum LoginStatus { - // TODO: add a state representing the fact that no request has been sent. + /// Request not sent yet. + Todo, /// Sent request, awaiting response. - Pending, + AwaitingResponse, /// Logged in. /// Stores the MOTD as received from the server. @@ -19,4 +20,3 @@ pub enum LoginStatus { /// Stores the error message as received from the server. Failure(String), } -