diff --git a/client/src/main.rs b/client/src/main.rs index cd18503..60605d4 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -57,7 +57,7 @@ async fn run_client( .context("validating credentials")?; info!("Logging in to server."); - let mut worker = solstice_proto::server::Client::new(stream) + let (_info, mut worker) = solstice_proto::server::Client::new(stream) .login(credentials) .await .context("logging in")?; diff --git a/proto/src/server/client.rs b/proto/src/server/client.rs index a372392..e8aa174 100644 --- a/proto/src/server/client.rs +++ b/proto/src/server/client.rs @@ -1,6 +1,7 @@ //! A client interface for remote servers. use std::io; +use std::net::Ipv4Addr; use log::{debug, info}; use thiserror::Error; @@ -20,6 +21,15 @@ pub struct Client { version: Version, } +/// Contents of a successful login response. +pub struct LoginInfo { + /// The server's message of the day. + pub motd: String, + + /// Our public IP address, as observed by the server. + pub public_ip: Ipv4Addr, +} + /// An error that arose while logging in to a remote server. #[derive(Debug, Error)] pub enum ClientLoginError { @@ -63,7 +73,7 @@ impl Client { pub async fn login( mut self, credentials: Credentials, - ) -> Result { + ) -> Result<(LoginInfo, ClientWorker), ClientLoginError> { let login_request = credentials.into_login_request(self.version); debug!("Sending login request: {:?}", login_request); self @@ -94,7 +104,12 @@ impl Client { info!("Login: Public IP address: {}", ip); info!("Login: Password MD5: {:?}", password_md5_opt); - Ok(Worker::from_parts(self.reader, self.writer)) + let info = LoginInfo { + motd, + public_ip: ip, + }; + let worker = Worker::from_parts(self.reader, self.writer); + Ok((info, worker)) } ServerResponse::LoginResponse(LoginResponse::LoginFail { reason }) => { Err(ClientLoginError::LoginFailed(reason, self)) @@ -190,7 +205,7 @@ mod tests { .await .expect("connecting"); - let mut worker = Client::new(stream) + let (_, mut worker) = Client::new(stream) .login(credentials()) .await .expect("logging in"); diff --git a/proto/tests/connect.rs b/proto/tests/connect.rs index 06c6f03..7a51636 100644 --- a/proto/tests/connect.rs +++ b/proto/tests/connect.rs @@ -28,10 +28,13 @@ fn make_credentials(user_name: String) -> Credentials { async fn integration_connect() { init(); - let stream = connect().await.unwrap(); + let stream = connect().await.expect("connecting"); let credentials = make_credentials(make_user_name("connect")); - let mut worker = Client::new(stream).login(credentials).await.unwrap(); + let (_info, mut worker) = Client::new(stream) + .login(credentials) + .await + .expect("logging in"); let (request_tx, request_rx) = mpsc::channel(100); let (response_tx, _response_rx) = mpsc::channel(100); @@ -50,11 +53,14 @@ async fn integration_connect() { async fn integration_check_user_status() { init(); - let stream = connect().await.unwrap(); + let stream = connect().await.expect("connecting"); let user_name = make_user_name("check_user_status"); let credentials = make_credentials(user_name.clone()); - let mut worker = Client::new(stream).login(credentials).await.unwrap(); + let (_, mut worker) = Client::new(stream) + .login(credentials) + .await + .expect("logging in"); let (request_tx, request_rx) = mpsc::channel(100); let (response_tx, mut response_rx) = mpsc::channel(100);