diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-29 18:34:28 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-29 18:34:28 +0200 |
| commit | 65016caa8d565942086540edbee95b8af1e75c8c (patch) | |
| tree | d86dc518f19af8e4200c19280d9e0df388cf2515 | |
| parent | c5af1b237027031be310951c36f23f0a0bc760b6 (diff) | |
| download | mum-65016caa8d565942086540edbee95b8af1e75c8c.tar.gz | |
tcp event connected contains result
| -rw-r--r-- | mumd/src/network/tcp.rs | 4 | ||||
| -rw-r--r-- | mumd/src/state.rs | 20 | ||||
| -rw-r--r-- | mumlib/src/error.rs | 4 |
3 files changed, 15 insertions, 13 deletions
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index cd178f8..1738b15 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -38,7 +38,7 @@ pub enum TcpEvent { #[derive(Clone)] pub enum TcpEventData<'a> { - Connected(&'a msgs::ServerSync), + Connected(Result<&'a msgs::ServerSync, mumlib::error::Error>), _Disconnected, } @@ -286,7 +286,7 @@ async fn listen( ) .await; } - event_queue.send(TcpEventData::Connected(&msg)).await; + event_queue.send(TcpEventData::Connected(Ok(&msg))).await; let mut state = state.lock().await; let server = state.server_mut().unwrap(); server.parse_server_sync(*msg); diff --git a/mumd/src/state.rs b/mumd/src/state.rs index b279dfd..f725276 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -342,16 +342,18 @@ impl State { accept_invalid_cert, ))) .unwrap(); - at!(TcpEvent::Connected, |e| { + at!(TcpEvent::Connected, |res| { //runs the closure when the client is connected - if let TcpEventData::Connected(msg) = e { - Ok(Some(CommandResponse::ServerConnect { - welcome_message: if msg.has_welcome_text() { - Some(msg.get_welcome_text().to_string()) - } else { - None - }, - })) + if let TcpEventData::Connected(res) = res { + res.map(|msg| { + Some(CommandResponse::ServerConnect { + welcome_message: if msg.has_welcome_text() { + Some(msg.get_welcome_text().to_string()) + } else { + None + }, + }) + }) } else { unreachable!("callback should be provided with a TcpEventData::Connected"); } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 8c66068..820d5f3 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; pub type Result<T> = std::result::Result<T, Error>; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum Error { DisconnectedError, AlreadyConnectedError, @@ -26,7 +26,7 @@ impl fmt::Display for Error { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum ChannelIdentifierError { Invalid, Ambiguous, |
