From e13ef720a93f9a03948efd7b605fdd2d4df20745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 13 Oct 2020 00:10:36 +0200 Subject: parse channel remove (#3) --- mumd/src/network.rs | 6 ++++-- mumd/src/state.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mumd/src/network.rs b/mumd/src/network.rs index a90a0fc..947612f 100644 --- a/mumd/src/network.rs +++ b/mumd/src/network.rs @@ -135,7 +135,7 @@ async fn listen_tcp( ControlPacket::ServerSync(msg) => { info!("Logged in"); if let Some(sender) = crypt_state_sender.take() { - sender.send( + let _ = sender.send( crypt_state .take() .expect("Server didn't send us any CryptSetup packet!"), @@ -173,7 +173,9 @@ async fn listen_tcp( debug!("Channel state received"); server.lock().unwrap().parse_channel_state(msg); } - ControlPacket::ChannelRemove(msg) => {} + ControlPacket::ChannelRemove(msg) => { + server.lock().unwrap().parse_channel_remove(msg); + } _ => {} } } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 6e0d908..1ef8467 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -35,6 +35,17 @@ impl Server { } } + pub fn parse_channel_remove(&mut self, msg: Box) { + if !msg.has_channel_id() { + warn!("Can't parse channel remove without channel id"); + return; + } + match self.channels.entry(msg.get_channel_id()) { + Entry::Vacant(_) => { warn!("Attempted to remove channel that doesn't exist"); } + Entry::Occupied(e) => { e.remove(); } + } + } + pub fn parse_user_state(&mut self, msg: Box) { if !msg.has_session() { warn!("Can't parse user state without session"); -- cgit v1.2.1