diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-05-21 21:48:14 +0200 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-05-21 21:48:14 +0200 |
| commit | f72440096cefecbe62a37813ea3ee6f3cd3c7299 (patch) | |
| tree | 36e0941b33ab4f79aa45b5416ca6c8b1aedce63b /mumd/src | |
| parent | aac27b02754e2d8b8152a062c112842d9f22478a (diff) | |
| download | mum-f72440096cefecbe62a37813ea3ee6f3cd3c7299.tar.gz | |
add connectivity check
Diffstat (limited to 'mumd/src')
| -rw-r--r-- | mumd/src/state.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs index ce915ac..8072b8e 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -621,6 +621,10 @@ pub fn handle_command( now!(Ok(None)) } Command::PastMessages { block } => { + //does it make sense to wait for messages while not connected? + if !matches!(*state.phase_receiver().borrow(), StatePhase::Connected(_)) { + return now!(Err(Error::Disconnected)); + } if block { let ref_state = Arc::clone(&og_state); ExecutionContext::TcpEventSubscriber( @@ -629,7 +633,7 @@ pub fn handle_command( if let TcpEventData::TextMessage(a) = data { let message = ( a.get_message().to_owned(), - ref_state.read().unwrap().get_user_name(a.get_actor()) + ref_state.read().unwrap().get_user_name(a.get_actor()).unwrap() ); sender.send(Ok(Some(CommandResponse::PastMessage { message }))).is_ok() } else { @@ -640,7 +644,7 @@ pub fn handle_command( } else { let messages = std::mem::take(&mut state.message_buffer); let messages = messages.into_iter() - .map(|(msg, user)| (msg, state.get_user_name(user))) + .map(|(msg, user)| (msg, state.get_user_name(user).unwrap())) .collect(); now!(Ok(Some(CommandResponse::PastMessages { messages }))) |
