From ded5b573004f867bc9fe9644d4d4fe3a81c48b99 Mon Sep 17 00:00:00 2001 From: Eskil Q Date: Wed, 23 Dec 2020 19:53:36 +0100 Subject: remove mumlibs dependency on rust-mumble-protocol --- Cargo.lock | 1 - mumd/src/state.rs | 2 +- mumd/src/state/user.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++- mumlib/Cargo.toml | 1 - mumlib/src/state.rs | 66 +------------------------------------------------- 5 files changed, 66 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d268301..66f9276 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -842,7 +842,6 @@ dependencies = [ "colored", "fern", "log", - "mumble-protocol", "serde", "toml", ] diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 7a4704a..aba0931 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -16,7 +16,7 @@ use mumble_protocol::voice::Serverbound; use mumlib::command::{Command, CommandResponse}; use mumlib::config::Config; use mumlib::error::{ChannelIdentifierError, Error}; -use mumlib::state::UserDiff; +use crate::state::user::UserDiff; use std::net::{SocketAddr, ToSocketAddrs}; use tokio::sync::{mpsc, watch}; diff --git a/mumd/src/state/user.rs b/mumd/src/state/user.rs index 913f91b..5770bca 100644 --- a/mumd/src/state/user.rs +++ b/mumd/src/state/user.rs @@ -78,7 +78,7 @@ impl User { } } - pub fn apply_user_diff(&mut self, diff: &mumlib::state::UserDiff) { + pub fn apply_user_diff(&mut self, diff: &crate::state::user::UserDiff) { if let Some(comment) = diff.comment.clone() { self.comment = Some(comment); } @@ -155,3 +155,66 @@ impl From<&User> for mumlib::state::User { } } } + +#[derive(Debug, Default)] +pub struct UserDiff { + pub comment: Option, + pub hash: Option, + pub name: Option, + pub priority_speaker: Option, + pub recording: Option, + + pub suppress: Option, // by me + pub self_mute: Option, // by self + pub self_deaf: Option, // by self + pub mute: Option, // by admin + pub deaf: Option, // by admin + + pub channel_id: Option, +} + +impl UserDiff { + pub fn new() -> Self { + UserDiff::default() + } +} + +impl From for UserDiff { + fn from(mut msg: msgs::UserState) -> Self { + let mut ud = UserDiff::new(); + if msg.has_comment() { + ud.comment = Some(msg.take_comment()); + } + if msg.has_hash() { + ud.hash = Some(msg.take_hash()); + } + if msg.has_name() { + ud.name = Some(msg.take_name()); + } + if msg.has_priority_speaker() { + ud.priority_speaker = Some(msg.get_priority_speaker()); + } + if msg.has_recording() { + ud.recording = Some(msg.get_recording()); + } + if msg.has_suppress() { + ud.suppress = Some(msg.get_suppress()); + } + if msg.has_self_mute() { + ud.self_mute = Some(msg.get_self_mute()); + } + if msg.has_self_deaf() { + ud.self_deaf = Some(msg.get_self_deaf()); + } + if msg.has_mute() { + ud.mute = Some(msg.get_mute()); + } + if msg.has_deaf() { + ud.deaf = Some(msg.get_deaf()); + } + if msg.has_channel_id() { + ud.channel_id = Some(msg.get_channel_id()); + } + ud + } +} diff --git a/mumlib/Cargo.toml b/mumlib/Cargo.toml index 59feb75..74bdb32 100644 --- a/mumlib/Cargo.toml +++ b/mumlib/Cargo.toml @@ -11,6 +11,5 @@ edition = "2018" colored = "2.0" fern = "0.5" log = "0.4" -mumble-protocol = "0.3" serde = { version = "1.0", features = ["derive"] } toml = "0.5" diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 3b1da56..0f1cef2 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -1,4 +1,3 @@ -use mumble_protocol::control::msgs; use serde::export::Formatter; use serde::{Deserialize, Serialize}; use std::fmt::Display; @@ -153,67 +152,4 @@ impl Display for User { true_to_str!(self.deaf, "d") ) } -} - -#[derive(Debug, Default)] -pub struct UserDiff { - pub comment: Option, - pub hash: Option, - pub name: Option, - pub priority_speaker: Option, - pub recording: Option, - - pub suppress: Option, // by me - pub self_mute: Option, // by self - pub self_deaf: Option, // by self - pub mute: Option, // by admin - pub deaf: Option, // by admin - - pub channel_id: Option, -} - -impl UserDiff { - pub fn new() -> Self { - UserDiff::default() - } -} - -impl From for UserDiff { - fn from(mut msg: msgs::UserState) -> Self { - let mut ud = UserDiff::new(); - if msg.has_comment() { - ud.comment = Some(msg.take_comment()); - } - if msg.has_hash() { - ud.hash = Some(msg.take_hash()); - } - if msg.has_name() { - ud.name = Some(msg.take_name()); - } - if msg.has_priority_speaker() { - ud.priority_speaker = Some(msg.get_priority_speaker()); - } - if msg.has_recording() { - ud.recording = Some(msg.get_recording()); - } - if msg.has_suppress() { - ud.suppress = Some(msg.get_suppress()); - } - if msg.has_self_mute() { - ud.self_mute = Some(msg.get_self_mute()); - } - if msg.has_self_deaf() { - ud.self_deaf = Some(msg.get_self_deaf()); - } - if msg.has_mute() { - ud.mute = Some(msg.get_mute()); - } - if msg.has_deaf() { - ud.deaf = Some(msg.get_deaf()); - } - if msg.has_channel_id() { - ud.channel_id = Some(msg.get_channel_id()); - } - ud - } -} +} \ No newline at end of file -- cgit v1.2.1