From 65016caa8d565942086540edbee95b8af1e75c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 29 Mar 2021 18:34:28 +0200 Subject: tcp event connected contains result --- mumd/src/network/tcp.rs | 4 ++-- mumd/src/state.rs | 20 +++++++++++--------- 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 = std::result::Result; -#[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, -- cgit v1.2.1