aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-06-07 00:50:15 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-06-07 00:50:15 +0200
commit2b63fa8ac1b7e7d995955758f8cd9ab2ec7d4e0e (patch)
tree9c7bb675eb590aac535746ca1058ea873d4fea5a
parent0cc89730e82464e8f6c4ee69a4791fdd0135178c (diff)
downloadmum-2b63fa8ac1b7e7d995955758f8cd9ab2ec7d4e0e.tar.gz
events command
-rw-r--r--mumctl/src/main.rs15
-rw-r--r--mumd/src/state.rs24
-rw-r--r--mumlib/src/command.rs46
3 files changed, 67 insertions, 18 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs
index bde24a1..0af322d 100644
--- a/mumctl/src/main.rs
+++ b/mumctl/src/main.rs
@@ -87,6 +87,10 @@ enum Command {
},
/// Send a message to a channel or a user
Message(Target),
+ Events {
+ #[structopt(short = "f", long = "follow")]
+ follow: bool,
+ },
}
#[derive(Debug, StructOpt)]
@@ -399,6 +403,17 @@ fn match_opt() -> Result<(), Error> {
send_command(msg)??;
}
},
+ Command::Events { follow } => {
+ for response in send_command_multi(MumCommand::Events { block: follow })? {
+ match response {
+ Ok(Some(CommandResponse::Event { event })) => {
+ println!("{}", event)
+ }
+ Ok(_) => unreachable!("Response should only be a Some(Event)"),
+ Err(e) => error!("{}", e),
+ }
+ }
+ }
}
let config_path = config::default_cfg_path();
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index f831258..c51c139 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -15,7 +15,7 @@ use mumble_protocol::control::msgs;
use mumble_protocol::control::ControlPacket;
use mumble_protocol::ping::PongPacket;
use mumble_protocol::voice::Serverbound;
-use mumlib::command::{Command, CommandResponse, MessageTarget};
+use mumlib::command::{Command, CommandResponse, Event, MessageTarget};
use mumlib::config::Config;
use mumlib::Error;
use std::{
@@ -60,11 +60,6 @@ pub enum ExecutionContext {
),
}
-pub enum Event {
- UserConnected(String, Option<String>),
- UserDisconnected(String, Option<String>),
-}
-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StatePhase {
Disconnected,
@@ -435,6 +430,19 @@ pub fn handle_command(
new_deaf.map(|b| CommandResponse::DeafenStatus { is_deafened: b })
))
}
+ Command::Events { block } => {
+ if block {
+ warn!("Blocking event list is unimplemented");
+ now!(Ok(None))
+ } else {
+ let events: Vec<_> = state
+ .events
+ .iter()
+ .map(|event| Ok(Some(CommandResponse::Event { event: event.clone() })))
+ .collect();
+ ExecutionContext::Now(Box::new(move || Box::new(events.into_iter())))
+ }
+ }
Command::InputVolumeSet(volume) => {
state.audio_input.set_volume(volume);
now!(Ok(None))
@@ -618,12 +626,12 @@ pub fn handle_command(
}),
Box::new(move |pong| {
Ok(pong.map(|pong| {
- (CommandResponse::ServerStatus {
+ CommandResponse::ServerStatus {
version: pong.version,
users: pong.users,
max_users: pong.max_users,
bandwidth: pong.bandwidth,
- })
+ }
}))
}),
),
diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs
index 351d7f6..7551bb3 100644
--- a/mumlib/src/command.rs
+++ b/mumlib/src/command.rs
@@ -1,6 +1,26 @@
use crate::state::{Channel, Server};
use serde::{Deserialize, Serialize};
+use std::fmt;
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum Event {
+ UserConnected(String, Option<String>),
+ UserDisconnected(String, Option<String>),
+}
+
+impl fmt::Display for Event {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Event::UserConnected(user, channel) => {
+ write!(f, "{} connected to {}", user, channel.as_deref().unwrap_or("unknown channel"))
+ }
+ Event::UserDisconnected(user, channel) => {
+ write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown channel"))
+ }
+ }
+ }
+}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Command {
@@ -10,11 +30,21 @@ pub enum Command {
ChannelList,
ConfigReload,
DeafenSelf(Option<bool>),
+ Events {
+ block: bool
+ },
InputVolumeSet(f32),
MuteOther(String, Option<bool>),
MuteSelf(Option<bool>),
OutputVolumeSet(f32),
+ PastMessages {
+ block: bool,
+ },
Ping,
+ SendMessage {
+ message: String,
+ targets: Vec<MessageTarget>,
+ },
ServerConnect {
host: String,
port: u16,
@@ -29,13 +59,6 @@ pub enum Command {
},
Status,
UserVolumeSet(String, f32),
- PastMessages {
- block: bool,
- },
- SendMessage {
- message: String,
- targets: Vec<MessageTarget>,
- },
}
#[derive(Debug, Deserialize, Serialize)]
@@ -46,9 +69,15 @@ pub enum CommandResponse {
DeafenStatus {
is_deafened: bool,
},
+ Event {
+ event: Event,
+ },
MuteStatus {
is_muted: bool,
},
+ PastMessage {
+ message: (String, String),
+ },
Pong,
ServerConnect {
welcome_message: Option<String>,
@@ -62,9 +91,6 @@ pub enum CommandResponse {
Status {
server_state: Server,
},
- PastMessage {
- message: (String, String),
- },
}
#[derive(Clone, Debug, Deserialize, Serialize)]