Versions.csv gains the 121 verified rows of upstream tsdeclarations it was missing (TeamSpeak 5 betas, 3.6.x) and 6.0.0-beta4.1 [Build: 1779880475] for Linux, captured from the official Linux client's clientinit. Every row verifies against TeamSpeak's version-signing key. They are appended, so the generated Version variants and the indexes keep their names. native_version() now claims the newest 6.x build signed for the native platform (Linux 6.0.0-beta4.1, Windows 6.0.0-beta2), so the client shows as a TeamSpeak 6 client instead of 3.?.?; platforms without one (macOS, Android, iOS) keep the generic tuple. --client-version generic (and a bookmark's client_version) claims the old tuple. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VZBWxxMsxUzp4PSTKVzbZN
314 lines
9.9 KiB
Rust
314 lines
9.9 KiB
Rust
//! `voelinctl`: headless TeamSpeak 3/6 client for development and integration tests.
|
|
|
|
mod alloc;
|
|
mod bench;
|
|
mod client;
|
|
mod engine;
|
|
mod gateway;
|
|
mod identity;
|
|
mod observe;
|
|
mod probe;
|
|
mod query;
|
|
mod session;
|
|
mod stream;
|
|
mod studio;
|
|
mod tree;
|
|
mod versions;
|
|
mod voice;
|
|
|
|
use std::path::PathBuf;
|
|
use std::time::Duration;
|
|
|
|
use anyhow::Result;
|
|
use clap::{Args, Parser, Subcommand};
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
/// Counts heap allocations for `stream bench` and `studio bench`.
|
|
#[global_allocator]
|
|
static ALLOCATOR: alloc::Counting = alloc::Counting;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Command {
|
|
/// Manage the client identity (the key pair that gives the client its unique id).
|
|
Identity {
|
|
#[command(subcommand)]
|
|
command: IdentityCommand,
|
|
},
|
|
/// List the signed client versions that can be sent in `clientinit`.
|
|
Versions {
|
|
/// Only show versions whose platform or version contains this text.
|
|
filter: Option<String>,
|
|
},
|
|
/// Connect to a server and run an action.
|
|
Connect(ConnectArgs),
|
|
/// Run ServerQuery commands (raw TCP, SSH or HTTP WebQuery).
|
|
Query(query::QueryArgs),
|
|
/// Watch who is in which channel through ServerQuery, without appearing on the server.
|
|
Observe(observe::ObserveArgs),
|
|
/// Read and write a channel's chat through an invisible query relay.
|
|
Relay(observe::RelayArgs),
|
|
/// Use a tsgw gateway as a user: presence, chat, history; with
|
|
/// `--engine` through the client engine (chat history sync, pins,
|
|
/// reactions, topics, events, stream directory, administration).
|
|
Gateway(gateway::GatewayArgs),
|
|
/// A voice session through the client engine: files, avatars, pokes,
|
|
/// private and offline messages, contacts.
|
|
Engine(client::EngineArgs),
|
|
/// TeamSpeak 6: probe how a client that arrives after a stream started
|
|
/// can learn about it; prints every command both clients exchange.
|
|
ProbeStream(probe::ProbeStreamArgs),
|
|
/// Stream tools that need no server (`bench`).
|
|
Stream(bench::StreamToolArgs),
|
|
/// The Stream Studio headless: run a scene file (preview picture,
|
|
/// recording, replay clip, WHIP), bench the compositor, list cameras.
|
|
Studio(studio::StudioArgs),
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum IdentityCommand {
|
|
/// Create a new identity and store it.
|
|
New {
|
|
/// Minimum security level (hash cash). Servers commonly require 8.
|
|
#[arg(long, default_value_t = 8)]
|
|
level: u8,
|
|
/// Where to store the identity [default: <config dir>/voelinctl/identity.json].
|
|
#[arg(long)]
|
|
out: Option<PathBuf>,
|
|
/// Overwrite an existing file.
|
|
#[arg(long)]
|
|
force: bool,
|
|
},
|
|
/// Print uid and security level of a stored identity.
|
|
Show {
|
|
#[arg(long)]
|
|
identity: Option<PathBuf>,
|
|
},
|
|
/// List the identities in the client database, with the id `export` takes.
|
|
List {
|
|
/// Client database [default: <data dir>/voelin/client.db].
|
|
#[arg(long)]
|
|
store: Option<PathBuf>,
|
|
},
|
|
/// Import identities from the official TeamSpeak 3 and 6 clients. Their
|
|
/// files are only read, never changed.
|
|
Import {
|
|
/// A TeamSpeak 3 `.ini` export, or a client's `settings.db`.
|
|
#[arg(long, conflicts_with = "auto", required_unless_present = "auto")]
|
|
from: Option<PathBuf>,
|
|
/// Look in the usual locations of both clients instead (see
|
|
/// `docs/identity.md`).
|
|
#[arg(long)]
|
|
auto: bool,
|
|
/// List what was found and store nothing.
|
|
#[arg(long)]
|
|
dry_run: bool,
|
|
#[arg(long)]
|
|
store: Option<PathBuf>,
|
|
},
|
|
/// Write an identity from the client database to a TeamSpeak 3 `.ini`
|
|
/// export, which the official client imports.
|
|
Export {
|
|
/// Identity id, from `identity list`.
|
|
id: i64,
|
|
/// File to write; on Unix it is created readable only by you.
|
|
path: PathBuf,
|
|
#[arg(long)]
|
|
store: Option<PathBuf>,
|
|
},
|
|
}
|
|
|
|
#[derive(Args, Debug)]
|
|
pub struct ConnectArgs {
|
|
/// Server address: host, host:port, or a TeamSpeak server nickname.
|
|
address: String,
|
|
/// Nickname to use.
|
|
#[arg(long, default_value = "voelinctl")]
|
|
nick: String,
|
|
/// Identity file. Without it a temporary identity is generated.
|
|
#[arg(long, env = "VOELINCTL_IDENTITY")]
|
|
identity: Option<PathBuf>,
|
|
/// Signed client version: `default` (the newest signed 6.x build of this OS), `generic`
|
|
/// (3.?.?), an index or `<platform>@<version>` from `voelinctl versions`.
|
|
#[arg(long, default_value = "default")]
|
|
client_version: String,
|
|
/// Server password.
|
|
#[arg(long, env = "VOELINCTL_SERVER_PASSWORD")]
|
|
server_password: Option<String>,
|
|
/// Privilege key (token) to redeem after connecting, e.g. the ServerAdmin key a new server prints.
|
|
#[arg(long, env = "VOELINCTL_PRIVILEGE_KEY")]
|
|
privilege_key: Option<String>,
|
|
/// Channel to join, as a path like `Lobby/Sub`.
|
|
#[arg(long)]
|
|
channel: Option<String>,
|
|
/// Log every command sent and received.
|
|
#[arg(long)]
|
|
log_commands: bool,
|
|
/// Give up connecting after this many seconds.
|
|
#[arg(long, default_value_t = 30)]
|
|
connect_timeout: u64,
|
|
#[command(subcommand)]
|
|
action: Action,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
pub enum Action {
|
|
/// Subscribe to all channels and print the channel tree with its clients.
|
|
Tree {
|
|
/// How long to wait for subscription results before printing.
|
|
#[arg(long, default_value_t = 1500)]
|
|
settle_ms: u64,
|
|
},
|
|
/// Send a text message and exit.
|
|
Chat {
|
|
#[command(subcommand)]
|
|
target: ChatTarget,
|
|
},
|
|
/// Print text messages and client events until interrupted.
|
|
Listen {
|
|
/// Print events as JSON lines instead of text.
|
|
#[arg(long)]
|
|
json: bool,
|
|
/// Exit successfully once a text message containing this text arrives.
|
|
#[arg(long)]
|
|
expect: Option<String>,
|
|
/// Exit after this many seconds; fails if `--expect` was not satisfied.
|
|
#[arg(long)]
|
|
timeout: Option<u64>,
|
|
},
|
|
/// Send a raw, already escaped command (e.g. `serveredit virtualserver_name=Test\\sServer`)
|
|
/// and wait for the result. Combine with `--log-commands` to see the answer.
|
|
Raw { command: String },
|
|
/// Send or record voice in the current channel.
|
|
Voice {
|
|
#[command(subcommand)]
|
|
command: VoiceCommand,
|
|
},
|
|
/// TeamSpeak 6 streams (screen sharing): start, list or watch.
|
|
Stream(Box<stream::StreamArgs>),
|
|
/// Interactive session. Type `/help` for commands.
|
|
Repl,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug, Clone)]
|
|
pub enum VoiceCommand {
|
|
/// Talk: send a WAV file or a test tone, in real time.
|
|
Send {
|
|
/// WAV file to send (any sample rate; resampled to 48 kHz).
|
|
file: Option<PathBuf>,
|
|
/// Send a sine tone of this frequency instead of a file.
|
|
#[arg(long, conflicts_with = "file")]
|
|
tone: Option<f32>,
|
|
/// Tone length in seconds.
|
|
#[arg(long, default_value_t = 3.0)]
|
|
seconds: f32,
|
|
/// Use the stereo Opus Music codec instead of mono Opus Voice.
|
|
#[arg(long)]
|
|
music: bool,
|
|
},
|
|
/// Listen: mix everything said in the channel into a stereo 48 kHz WAV file.
|
|
Record {
|
|
out: PathBuf,
|
|
/// Recording length in seconds.
|
|
#[arg(long, default_value_t = 5.0)]
|
|
seconds: f32,
|
|
/// Fail unless the recording contains this tone frequency (for tests).
|
|
#[arg(long)]
|
|
expect_tone: Option<f32>,
|
|
},
|
|
}
|
|
|
|
#[derive(Subcommand, Debug, Clone)]
|
|
pub enum ChatTarget {
|
|
/// Send to the server chat (everyone on the server).
|
|
Server { message: String },
|
|
/// Send to the chat of the channel we are in.
|
|
Channel { message: String },
|
|
/// Send a private message to a client id.
|
|
Client { clid: u16, message: String },
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn")),
|
|
)
|
|
.with_writer(std::io::stderr)
|
|
.init();
|
|
|
|
let cli = Cli::parse();
|
|
match cli.command {
|
|
Command::Identity { command } => run_identity(command),
|
|
Command::Versions { filter } => {
|
|
for (i, v) in versions::known_versions().iter().enumerate() {
|
|
let matches = filter
|
|
.as_deref()
|
|
.is_none_or(|f| v.platform.contains(f) || v.version.contains(f));
|
|
if matches {
|
|
println!("{i:>3} {}@{}", v.platform, v.version);
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
Command::Connect(args) => {
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
rt.block_on(session::run(args))
|
|
}
|
|
Command::Query(args) => tokio::runtime::Runtime::new()?.block_on(query::run(args)),
|
|
Command::Observe(args) => tokio::runtime::Runtime::new()?.block_on(observe::observe(args)),
|
|
Command::Relay(args) => tokio::runtime::Runtime::new()?.block_on(observe::relay(args)),
|
|
Command::Gateway(args) => tokio::runtime::Runtime::new()?.block_on(gateway::run(args)),
|
|
Command::Engine(args) => tokio::runtime::Runtime::new()?.block_on(client::run(args)),
|
|
Command::ProbeStream(args) => tokio::runtime::Runtime::new()?.block_on(probe::run(args)),
|
|
Command::Stream(args) => bench::run(args),
|
|
Command::Studio(args) => studio::run(args),
|
|
}
|
|
}
|
|
|
|
fn run_identity(command: IdentityCommand) -> Result<()> {
|
|
match command {
|
|
IdentityCommand::New { level, out, force } => {
|
|
let path = out.unwrap_or_else(identity::default_path);
|
|
if path.exists() && !force {
|
|
anyhow::bail!("{} already exists, pass --force to overwrite", path.display());
|
|
}
|
|
let id = identity::create(level);
|
|
identity::save(&path, &id)?;
|
|
println!("uid: {}", identity::uid(&id));
|
|
println!("level: {}", id.level());
|
|
println!("saved: {}", path.display());
|
|
Ok(())
|
|
}
|
|
IdentityCommand::Show { identity: path } => {
|
|
let path = path.unwrap_or_else(identity::default_path);
|
|
let id = identity::load(&path)?;
|
|
println!("uid: {}", identity::uid(&id));
|
|
println!("level: {}", id.level());
|
|
let omega = id.key().to_pub().to_ts();
|
|
// TeamSpeak 6 servers know the identity by another unique id.
|
|
let ids = voelin_gateway_proto::UniqueIds::from_omega(&omega);
|
|
println!("uid6: {}", ids.ts6);
|
|
println!("omega: {omega}");
|
|
Ok(())
|
|
}
|
|
IdentityCommand::List { store } => identity::list(store),
|
|
// `--auto` only means "no --from"; clap has already required one.
|
|
IdentityCommand::Import { from, auto: _, dry_run, store } => {
|
|
identity::import(from, dry_run, store)
|
|
}
|
|
IdentityCommand::Export { id, path, store } => identity::export(id, &path, store),
|
|
}
|
|
}
|
|
|
|
impl ConnectArgs {
|
|
fn connect_timeout(&self) -> Duration {
|
|
Duration::from_secs(self.connect_timeout)
|
|
}
|
|
}
|