aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/network/tcp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mumd/src/network/tcp.rs')
-rw-r--r--mumd/src/network/tcp.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs
index cac1533..f620a32 100644
--- a/mumd/src/network/tcp.rs
+++ b/mumd/src/network/tcp.rs
@@ -11,6 +11,7 @@ use mumble_protocol::control::{msgs, ClientControlCodec, ControlCodec, ControlPa
use mumble_protocol::crypt::ClientCryptState;
use mumble_protocol::voice::VoicePacket;
use mumble_protocol::{Clientbound, Serverbound};
+use mumlib::command::MumbleEventKind;
use std::collections::HashMap;
use std::convert::{Into, TryInto};
use std::net::SocketAddr;
@@ -339,6 +340,10 @@ async fn listen(
let mut crypt_state = None;
let mut crypt_state_sender = Some(crypt_state_sender);
+ let mut last_late = 0;
+ let mut last_lost = 0;
+ let mut last_resync = 0;
+
loop {
let packet = match stream.next().await {
Some(Ok(packet)) => packet,
@@ -367,6 +372,8 @@ async fn listen(
if let Some(user) = user {
notifications::send(format!("{}: {}", user, msg.get_message()));
//TODO: probably want a config flag for this
+ let user = user.to_string();
+ state.push_event(MumbleEventKind::TextMessageReceived(user)) //TODO also include message target
}
state.register_message((msg.get_message().to_owned(), msg.get_actor()));
drop(state);
@@ -465,6 +472,40 @@ async fn listen(
}
}
}
+ ControlPacket::Ping(msg) => {
+ trace!("Received Ping {:?}", *msg);
+
+ let late = msg.get_late();
+ let lost = msg.get_lost();
+ let resync = msg.get_resync();
+
+ let late = late - last_late;
+ let lost = lost - last_lost;
+ let resync = resync - last_resync;
+
+ last_late += late;
+ last_lost += lost;
+ last_resync += resync;
+
+ macro_rules! format_if_nonzero {
+ ($value:expr) => {
+ if $value != 0 {
+ format!("\n {}: {}", stringify!($value), $value)
+ } else {
+ String::new()
+ }
+ }
+ }
+
+ if late != 0 || lost != 0 || resync != 0 {
+ debug!(
+ "Ping:{}{}{}",
+ format_if_nonzero!(late),
+ format_if_nonzero!(lost),
+ format_if_nonzero!(resync),
+ );
+ }
+ }
packet => {
debug!("Received unhandled ControlPacket {:#?}", packet);
}