TS2: registered login and Auto fallback

- Connector: --login-name/--login-password (TS_LOGIN_NAME/TS_LOGIN_PASSWORD)
  send a registered login (flag 2 + account name + password).
- Server type "auto" retries as TeamSpeak 2 when the TS3 handshake gets no
  answer, only with ENABLE_TS2=1. Default port 9987 is swapped for 8767.
- Gateway and connect dialog pass account name/password for TS2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-11-12 18:38:37 +00:00
1 parent 83877aaa76
commit bfe05a8b02
12 files changed
+107 -10

No files matched your search

+28 -2
View File
@@ -72,7 +72,7 @@ const MAX_ICON_BYTES: u64 = 512 << 10;
const MAX_AVATAR_BYTES: u64 = 512 << 10;
const OUT_CHANNELS: usize = 2;
#[derive(Parser, Debug)]
#[derive(Parser, Debug, Clone)]
#[command(author, about = "One-shot bridge: connects to a real TeamSpeak server and reports events as JSON lines on stdout")]
struct Args {
/// Server address, e.g. "192.168.178.108" or "192.168.178.108:9987"
@@ -107,6 +107,12 @@ struct Args {
/// Privilege key / token (`client_default_token` in clientinit).
#[arg(long, alias = "token", env = "TS_PRIVILEGE_KEY", hide_env_values = true)]
privilege_key: Option<String>,
/// TeamSpeak 2 only: account name for a registered login (anonymous when omitted).
#[arg(long, env = "TS_LOGIN_NAME", hide_env_values = true)]
login_name: Option<String>,
/// TeamSpeak 2 only: password of the registered account.
#[arg(long, env = "TS_LOGIN_PASSWORD", hide_env_values = true)]
login_password: Option<String>,
}
#[derive(Serialize)]
@@ -870,7 +876,27 @@ fn send_server_get_variables(con: &mut tsclientlib::Connection) {
#[tokio::main]
async fn main() {
let args = Args::parse();
let result = if args.server_type == "ts2" { ts2::run(args).await } else { run(args).await };
// "auto" falls back to TeamSpeak 2 when the TS3 handshake gets no answer at
// all; only if the gateway enables TS2 (ENABLE_TS2=1, inherited env).
let ts2_fallback = args.server_type == "auto" && std::env::var("ENABLE_TS2").as_deref() == Ok("1");
let result = if args.server_type == "ts2" {
ts2::run(args).await
} else if ts2_fallback {
match run(args.clone()).await {
Err(e) if e.to_string().contains("connection timed out") => {
eprintln!("no TS3 answer, trying TeamSpeak 2");
// Only the TS3 default port is swapped; an explicit other port is kept.
let mut args = args;
if let Some(host) = args.address.strip_suffix(":9987") {
args.address = host.to_string();
}
ts2::run(args).await.map_err(|_| e)
}
r => r,
}
} else {
run(args).await
};
if let Err(e) = result {
emit(&Event::Error { message: e.to_string() });
}
+16 -6
View File
@@ -732,11 +732,21 @@ async fn login(sock: &UdpSocket, args: &Args) -> Result<Vec<u8>> {
p.extend_from_slice(&[0; 4]); // CRC
p.extend_from_slice(&pstr("TeamSpeak"));
p.extend_from_slice(&pstr("Linux"));
p.extend_from_slice(&[2, 0, 0, 0, 0x20, 0, 0x3c, 0, 1, 1]);
// Anonymous login: no account name, the server password goes in the
// password field.
p.extend_from_slice(&pstr(""));
p.extend_from_slice(&pstr(args.server_password.as_deref().unwrap_or("")));
p.extend_from_slice(&[2, 0, 0, 0, 0x20, 0, 0x3c, 0, 1]);
// Registered login (2): account name + its password. Anonymous (1): no
// account name, the server password goes in the password field.
match &args.login_name {
Some(name) if !name.is_empty() => {
p.push(2);
p.extend_from_slice(&pstr(name));
p.extend_from_slice(&pstr(args.login_password.as_deref().unwrap_or("")));
}
_ => {
p.push(1);
p.extend_from_slice(&pstr(""));
p.extend_from_slice(&pstr(args.server_password.as_deref().unwrap_or("")));
}
}
p.extend_from_slice(&pstr(&args.nickname));
crc(&mut p, 16);
let mut buf = [0u8; 2048];
@@ -778,7 +788,7 @@ which this gateway does not connect to. (Self-hosting admin? Set ALLOW_PRIVATE_T
let reply = login(&sock, &args).await?;
if reply[89..92] != [0, 0, 0] {
bail!("The TeamSpeak 2 server rejected the login (wrong server password, or nickname not allowed).");
bail!("The TeamSpeak 2 server rejected the login (wrong server password, wrong account name or password, or nickname not allowed).");
}
// Unlike the 30-byte fields, the welcome message's length byte can go up to 255.
let welcome_len = reply[180] as usize;