From b583f6dbe521e01e879e16605026997dfa10c3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 13 Oct 2020 02:31:09 +0200 Subject: join different channels Co-authored-by: Eskil Queseth --- mumd/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 5d6cca4..322bde8 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,4 +1,4 @@ -enum Command { +pub enum Command { ChannelJoin { channel_id: u32, }, -- cgit v1.2.1 From 503f6c90395682bf5d7fd3fb8a79bfcfc3c2f329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 13 Oct 2020 17:05:22 +0200 Subject: wait for complete state before sending commands --- mumd/src/command.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 322bde8..1f7a781 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,3 +1,9 @@ +use crate::state::State; + +use std::sync::{Arc, Mutex}; +use tokio::sync::mpsc; + +#[derive(Debug)] pub enum Command { ChannelJoin { channel_id: u32, @@ -12,3 +18,16 @@ pub enum Command { ServerDisconnect, Status, } + +pub async fn handle( + state: Arc>, + mut command_receiver: mpsc::UnboundedReceiver, +) { + // wait until we can send packages + let mut initialized_receiver = state.lock().unwrap().initialized_receiver(); + while matches!(initialized_receiver.recv().await, Some(false)) {} + + while let Some(command) = command_receiver.recv().await { + state.lock().unwrap().handle_command(command).await; + } +} -- cgit v1.2.1 From 3d8009a0201fba0bdc464fae0797d3bb3bcf69f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 14 Oct 2020 01:48:07 +0200 Subject: wip handle more commands (panics) --- mumd/src/command.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 1f7a781..c3b72bf 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,5 +1,6 @@ -use crate::state::State; +use crate::state::{Channel, Server, State}; +use std::collections::HashMap; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; @@ -19,14 +20,23 @@ pub enum Command { Status, } +#[derive(Debug)] +pub enum CommandResponse { + ChannelList { + channels: HashMap, + }, + Status { + username: String, + server_state: Server, + } +} + pub async fn handle( state: Arc>, mut command_receiver: mpsc::UnboundedReceiver, + command_response_sender: mpsc::UnboundedSender, ()>>, ) { - // wait until we can send packages - let mut initialized_receiver = state.lock().unwrap().initialized_receiver(); - while matches!(initialized_receiver.recv().await, Some(false)) {} - + //TODO err if not connected while let Some(command) = command_receiver.recv().await { state.lock().unwrap().handle_command(command).await; } -- cgit v1.2.1 From a3c393a711c71698ef833f1923374798cbb0d0b4 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 14 Oct 2020 02:04:16 +0200 Subject: fix code so that it doesn't deadlock --- mumd/src/command.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index c3b72bf..8a5c715 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,8 +1,9 @@ -use crate::state::{Channel, Server, State}; +use crate::state::{Channel, Server, State, StatePhase}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; +use log::*; #[derive(Debug)] pub enum Command { @@ -38,6 +39,13 @@ pub async fn handle( ) { //TODO err if not connected while let Some(command) = command_receiver.recv().await { - state.lock().unwrap().handle_command(command).await; + debug!("Parsing command {:?}", command); + let mut state = state.lock().unwrap(); + let (wait_for_connected, _) = state.handle_command(command).await; + if wait_for_connected { + let mut watcher = state.phase_receiver(); + drop(state); + while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {} + } } } -- cgit v1.2.1 From b5528c2198d54028ef03d35d5aa4d7fdde6af8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 14 Oct 2020 02:33:50 +0200 Subject: some changes --- mumd/src/command.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 8a5c715..0e5bdc7 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -27,7 +27,7 @@ pub enum CommandResponse { channels: HashMap, }, Status { - username: String, + username: Option, server_state: Server, } } @@ -41,11 +41,12 @@ pub async fn handle( while let Some(command) = command_receiver.recv().await { debug!("Parsing command {:?}", command); let mut state = state.lock().unwrap(); - let (wait_for_connected, _) = state.handle_command(command).await; + let (wait_for_connected, command_response) = state.handle_command(command).await; if wait_for_connected { let mut watcher = state.phase_receiver(); drop(state); while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {} } + command_response_sender.send(command_response).unwrap(); } } -- cgit v1.2.1 From 7fb14d648aacd398f720f60236020dab6bf9fd35 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 14 Oct 2020 16:54:27 +0200 Subject: add support for disconnect command --- mumd/src/command.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 0e5bdc7..bfdb7dd 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -49,4 +49,6 @@ pub async fn handle( } command_response_sender.send(command_response).unwrap(); } + + debug!("Finished handling commands"); } -- cgit v1.2.1 From ab0cdc240c65fdc6b764ed17f6611786d449acc3 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 14 Oct 2020 17:45:04 +0200 Subject: add support for reconnecting to server --- mumd/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index bfdb7dd..1104671 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; use log::*; -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum Command { ChannelJoin { channel_id: u32, -- cgit v1.2.1 From 8f32d34f1cf31cfd10d07e623842dd3f7fc86e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 14 Oct 2020 19:29:34 +0200 Subject: cargo fmt --- mumd/src/command.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 1104671..b4bd1b7 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,9 +1,9 @@ use crate::state::{Channel, Server, State, StatePhase}; +use log::*; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; -use log::*; #[derive(Clone, Debug)] pub enum Command { @@ -29,7 +29,7 @@ pub enum CommandResponse { Status { username: Option, server_state: Server, - } + }, } pub async fn handle( -- cgit v1.2.1