diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 01:30:40 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 01:30:40 +0200 |
| commit | 17f077d48b361a4cf8f5743750ca7408a8800797 (patch) | |
| tree | aaa217c08cb879aea69c3421fa4fa3bf3173c285 | |
| parent | 2b63fa8ac1b7e7d995955758f8cd9ab2ec7d4e0e (diff) | |
| download | mum-17f077d48b361a4cf8f5743750ca7408a8800797.tar.gz | |
timestamps on mumble events
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | mumd/Cargo.toml | 1 | ||||
| -rw-r--r-- | mumd/src/state.rs | 12 | ||||
| -rw-r--r-- | mumlib/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumlib/src/command.rs | 23 |
5 files changed, 28 insertions, 12 deletions
@@ -139,6 +139,7 @@ dependencies = [ "libc", "num-integer", "num-traits", + "serde", "time", "winapi", ] @@ -814,6 +815,7 @@ version = "0.4.0" dependencies = [ "bincode", "bytes", + "chrono", "cpal", "dasp_frame", "dasp_interpolate", diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index d8e2635..1e8e63f 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -42,6 +42,7 @@ tokio-stream = "0.1.0" tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } bincode = "1.3.2" +chrono = "0.4" libnotify = { version = "1.0", optional = true } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index c51c139..ec25204 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, Event, MessageTarget}; +use mumlib::command::{Command, CommandResponse, MessageTarget, MumbleEvent, MumbleEventKind}; use mumlib::config::Config; use mumlib::Error; use std::{ @@ -76,7 +76,7 @@ pub struct State { phase_watcher: (watch::Sender<StatePhase>, watch::Receiver<StatePhase>), - events: Vec<Event>, + events: Vec<MumbleEvent>, } impl State { @@ -146,7 +146,7 @@ impl State { )); } let this_channel_name = this_channel_name.map(|s| s.to_string()); - self.push_event(Event::UserConnected(msg.get_name().to_string(), this_channel_name)); + self.push_event(MumbleEventKind::UserConnected(msg.get_name().to_string(), this_channel_name)); self.audio_output .play_effect(NotificationEvents::UserConnected); } @@ -244,7 +244,7 @@ impl State { if let Some(user) = self.server().unwrap().users().get(&msg.get_session()) { notifications::send(format!("{} disconnected", &user.name())); let user_name = user.name().to_string(); - self.push_event(Event::UserDisconnected(user_name, channel_name)); + self.push_event(MumbleEventKind::UserDisconnected(user_name, channel_name)); } } @@ -287,8 +287,8 @@ impl State { .play_effect(NotificationEvents::ServerConnect); } - pub fn push_event(&mut self, event: Event) { - self.events.push(event); + pub fn push_event(&mut self, kind: MumbleEventKind) { + self.events.push(MumbleEvent { timestamp: chrono::Local::now().naive_local(), kind }); } pub fn audio_input(&self) -> &AudioInput { diff --git a/mumlib/Cargo.toml b/mumlib/Cargo.toml index 5c9d4e1..5ec9365 100644 --- a/mumlib/Cargo.toml +++ b/mumlib/Cargo.toml @@ -13,7 +13,7 @@ readme = "../README.md" [dependencies] colored = "2" -chrono = "0.4" +chrono = { version = "0.4", features = [ "serde" ] } dirs = "3" fern = "0.6" log = "0.4" diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 7551bb3..402d6b0 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -1,21 +1,34 @@ use crate::state::{Channel, Server}; +use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Event { +pub struct MumbleEvent { + pub timestamp: NaiveDateTime, + pub kind: MumbleEventKind +} + +impl fmt::Display for MumbleEvent { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "[{}] {}", self.timestamp.format("%d %b %H:%M"), self.kind) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum MumbleEventKind { UserConnected(String, Option<String>), UserDisconnected(String, Option<String>), } -impl fmt::Display for Event { +impl fmt::Display for MumbleEventKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Event::UserConnected(user, channel) => { + MumbleEventKind::UserConnected(user, channel) => { write!(f, "{} connected to {}", user, channel.as_deref().unwrap_or("unknown channel")) } - Event::UserDisconnected(user, channel) => { + MumbleEventKind::UserDisconnected(user, channel) => { write!(f, "{} disconnected from {}", user, channel.as_deref().unwrap_or("unknown channel")) } } @@ -70,7 +83,7 @@ pub enum CommandResponse { is_deafened: bool, }, Event { - event: Event, + event: MumbleEvent, }, MuteStatus { is_muted: bool, |
