proto: TeamSpeak 6 fields and stream messages; tsctl shows streams

- Declarations: client_is_streaming (Client::is_streaming), initserver
  virtualserver_address/virtualserver_version_sign, stream
  notifications and commands (setupstream, stopstream, ...).
- tsctl: prints stream notifications and streaming state changes, marks
  streaming clients in the tree.
- CI: cargo-deny with default features (rug/GMP is benchmark-only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
Claude committed 2026-09-25 13:20:16 +00:00
1 parent cb5a541a3f
commit 369cbde85d
7 files changed
+132 -10

No files matched your search

+67 -6
View File
@@ -11,8 +11,8 @@ use tsclientlib::events::{Event, PropertyId, PropertyValue};
use tsclientlib::messages::c2s::{OutTokenUseMessage, OutTokenUsePart};
use tsclientlib::prelude::*;
use tsclientlib::{
ChannelId, ClientId, Connection, DisconnectOptions, MessageHandle, MessageTarget, StreamItem,
data,
ChannelId, ClientId, Connection, DisconnectOptions, InMessage, MessageHandle, MessageTarget,
StreamItem, data,
};
use tsproto_packets::packets::{Direction, Flags, OutCommand, PacketType};
@@ -238,10 +238,58 @@ fn describe(state: &data::Connection, event: &Event) -> Option<String> {
channel_name(state, client.channel)
))
}
Event::PropertyChanged { id: PropertyId::ClientIsStreaming(clid), .. } => {
let client = state.clients.get(clid)?;
let what = if client.is_streaming == Some(true) { "started" } else { "stopped" };
Some(format!("* {} (clid {}) {what} streaming", client.name, clid.0))
}
_ => None,
}
}
/// One line for TeamSpeak 6 stream notifications, `None` for other messages.
fn describe_message(msg: &InMessage) -> Option<String> {
let lines: Vec<String> = match msg {
InMessage::StreamStarted(m) => m
.iter()
.map(|p| {
format!(
"* stream {} started by clid {} (name {:?}, type {:?}, bitrate {:?}, audio {:?})",
p.stream_id,
p.client_id.0,
p.stream_name.as_deref().unwrap_or(""),
p.stream_type,
p.bitrate,
p.audio
)
})
.collect(),
InMessage::StreamStopped(m) => {
m.iter().map(|p| format!("* stream {} stopped", p.stream_id)).collect()
}
InMessage::JoinStreamRequest(m) => m
.iter()
.map(|p| format!("* clid {} asks to join stream {}", p.client_id.0, p.stream_id))
.collect(),
InMessage::StreamSignaling(m) => m
.iter()
.map(|p| {
format!("* signaling from clid {} on {}: {}", p.client_id.0, p.stream_id, p.json)
})
.collect(),
InMessage::StreamClientJoined(m) => m
.iter()
.map(|p| format!("* clid {} joined stream {}", p.client_id.0, p.stream_id))
.collect(),
InMessage::StreamClientLeft(m) => m
.iter()
.map(|p| format!("* clid {} left stream {}", p.client_id.0, p.stream_id))
.collect(),
_ => return None,
};
Some(lines.join("\n"))
}
/// Print book events; returns `true` if a text message contained `expect`.
fn print_events(
state: &data::Connection,
@@ -271,10 +319,18 @@ async fn listen(
) -> Result<()> {
let deadline = timeout.map(|t| Instant::now() + t);
let end = pump(con, deadline, |con, item| {
if let StreamItem::BookEvents(events) = item
&& print_events(con.get_state()?, &events, json, expect)?
{
return Ok(Flow::Stop);
match item {
StreamItem::BookEvents(events) => {
if print_events(con.get_state()?, &events, json, expect)? {
return Ok(Flow::Stop);
}
}
StreamItem::MessageEvent(msg) if !json => {
if let Some(line) = describe_message(&msg) {
println!("{line}");
}
}
_ => {}
}
Ok(Flow::Continue)
})
@@ -324,6 +380,11 @@ async fn repl(con: &mut Connection) -> Result<()> {
StreamItem::BookEvents(events) => {
print_events(con.get_state()?, &events, false, None)?;
}
StreamItem::MessageEvent(msg) => {
if let Some(line) = describe_message(&msg) {
println!("{line}");
}
}
StreamItem::MessageResult(handle, Err(error)) => {
println!("error (command {}): {error}", handle.0);
}
+8 -1
View File
@@ -25,6 +25,7 @@ pub struct ClientNode {
pub input_muted: bool,
pub output_muted: bool,
pub away: bool,
pub streaming: bool,
}
/// Sort siblings by following the `order` links (each channel names the
@@ -82,6 +83,9 @@ fn render_level(
if client.away {
flags.push("away");
}
if client.streaming {
flags.push("streaming");
}
let flags =
if flags.is_empty() { String::new() } else { format!(" [{}]", flags.join(", ")) };
let _ = writeln!(out, "{indent} - {}{flags}", client.name);
@@ -107,6 +111,7 @@ pub fn from_state(state: &data::Connection) -> String {
input_muted: c.input_muted,
output_muted: c.output_muted,
away: c.away_message.is_some(),
streaming: c.is_streaming == Some(true),
})
.collect();
render(&state.server.name, &channels, &clients)
@@ -134,6 +139,7 @@ mod tests {
input_muted: false,
output_muted: false,
away: false,
streaming: false,
}
}
@@ -161,6 +167,7 @@ mod tests {
query.is_query = true;
let mut muted = cl(3, "Bob", 0);
muted.input_muted = true;
muted.streaming = true;
let clients = [cl(1, "Alice", 10), cl(1, "Zed", 50), query, muted];
let text = render("Test Server", &channels, &clients);
assert_eq!(
@@ -171,7 +178,7 @@ mod tests {
- Alice\n\
# Games (cid 2)\n \
# Squad (cid 3)\n \
- Bob [mic off]\n"
- Bob [mic off, streaming]\n"
);
}
}