diff --git a/README.md b/README.md index b474eff..9bed3ba 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ not need to be installed on the same machine, modified, or operated by you. | 🔁 **Seamless reconnect** | Switch or add connections mid-session without tearing down unrelated tabs; dropped connections come back on their own, with the channel tree intact | | ⌨️ **Keyboard & screen readers** | Arrow keys through the channel tree (exposed as an ARIA tree) and through menus, Enter joins, context-menu key opens the menu; focus-trapped dialogs, labelled toolbar buttons | | 🍵 **VoySpeak support** | Connects to real VoySpeak servers (formerly GreenTeaSpeak), not just TS3/TS6/TeaSpeak | -| 📟 **TeamSpeak 2** | **EXPERIMENTAL** Voice, channels, private messages and server messages on old TS2 servers. Off by default, the gateway enables it with `ENABLE_TS2=1` | +| 📟 **TeamSpeak 2** | **EXPERIMENTAL** Voice, channels, private messages and server messages on old TS2 servers. Registered accounts work too, and the server type "Auto" detects TS2 on its own. Off by default, the gateway enables it with `ENABLE_TS2=1` | | 🖥️ **Screen streaming to/from TS6** | **ALPHA · UNSTABLE** Share your screen to native TeamSpeak 6 clients and watch theirs. Built on TS6's undocumented Stream/Call protocol — expect it to break; see [Roadmap](ROADMAP.md) | ## 🧱 Tech Stack @@ -249,7 +249,7 @@ All optional; add them under `environment:` in your compose override next to `PO | `NEWS_TICKER` | on | Set to `0` to hide the news ticker at the bottom of the client. | | `NEWS_TICKER_CENTRAL` | on | Set to `0` to drop the official WebSpeak3 news (releases, new store designs, announcements) and only show your own messages. | | `NEWS_TICKER_MESSAGES` | – | Your own ticker messages, separated by `\|`, e.g. `Maintenance tonight at 10pm \| Welcome!` | -| `ENABLE_TS2` | off | Set to `1` to offer **TeamSpeak 2** as a server type in the connect dialog. Experimental: voice (Speex), channel list, private messages and server messages work; channel chat depends on the server's permissions; file transfer, avatars, screen streams and admin functions aren't available on TS2. The code ships in every image, it just stays unused while this is off. | +| `ENABLE_TS2` | off | Set to `1` to offer **TeamSpeak 2** as a server type in the connect dialog. Experimental: voice (Speex), channel list, private messages and server messages work; channel chat depends on the server's permissions; file transfer, avatars, screen streams and admin functions aren't available on TS2. Also lets the server type "Auto" fall back to TS2 when a server gives no TS3 answer, and adds account name and password fields for registered TS2 logins. The code ships in every image, it just stays unused while this is off. | | `SYNC_URL` | official sync server | Account sync server your visitors use (Options → Account), e.g. `https://sync.example.com/api/sync`. Only needed if you run your own (see below). | > **Anonymous usage ping:** when the gateway starts and then once a day, it sends a random instance ID (made up on first start, stored in `instance-id` in the working directory, used for nothing else) and its version number to `gateway.webspeak3.de`. That's the only way to tell whether anyone self-hosts WebSpeak3 at all, and how many instances still run an old version, e.g. after a security fix. Nothing else is sent: no hostnames, no TeamSpeak servers, no users, no settings. The receiving side doesn't store IP addresses. The startup log says when it's on. Turn it off with `TELEMETRY=0`. diff --git a/connector/src/main.rs b/connector/src/main.rs index 09eab61..71f31a4 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -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, + /// 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, + /// TeamSpeak 2 only: password of the registered account. + #[arg(long, env = "TS_LOGIN_PASSWORD", hide_env_values = true)] + login_password: Option, } #[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() }); } diff --git a/connector/src/ts2.rs b/connector/src/ts2.rs index 829a069..fda96a5 100644 --- a/connector/src/ts2.rs +++ b/connector/src/ts2.rs @@ -732,11 +732,21 @@ async fn login(sock: &UdpSocket, args: &Args) -> Result> { 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; diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 7c1ccda..d67036d 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -774,6 +774,8 @@ wss.on("connection", (socket: WebSocket, req: IncomingMessage) => { identity: msg.identity, serverType: parseServerType(msg.serverType), privilegeKey: parsePrivilegeKey(msg), + loginName: typeof msg.loginName === "string" ? msg.loginName.trim() || undefined : undefined, + loginPassword: typeof msg.loginPassword === "string" ? msg.loginPassword || undefined : undefined, }; connection = new Ts3Connection(options); liveConnections.add(connection); diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index bb03b80..bd85427 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -228,6 +228,9 @@ export interface Ts3ConnectOptions { serverType?: ServerType; /** One-time privilege key / token to redeem on connect. */ privilegeKey?: string; + /** TeamSpeak 2 registered account (anonymous when omitted). */ + loginName?: string; + loginPassword?: string; } const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -280,6 +283,8 @@ export class Ts3Connection { if (this.options.channelPassword) env.TS_CHANNEL_PASSWORD = this.options.channelPassword; if (this.options.identity) env.TS_IDENTITY = this.options.identity; if (this.options.privilegeKey) env.TS_PRIVILEGE_KEY = this.options.privilegeKey; + if (this.options.loginName) env.TS_LOGIN_NAME = this.options.loginName; + if (this.options.loginPassword) env.TS_LOGIN_PASSWORD = this.options.loginPassword; this.child = spawn(CONNECTOR_BIN, args, { env }); // The connector can exit on its own (e.g. the TS3 server drops it) and close diff --git a/web/src/App.tsx b/web/src/App.tsx index 0b76a9d..90cdf1c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -421,6 +421,9 @@ type ConnectParams = { channelPassword: string; defaultChannel: string; privilegeKey: string; + /** TeamSpeak 2 registered account (anonymous when empty). */ + loginName?: string; + loginPassword?: string; serverType: ServerType; identityId: string | null; favoriteId: string | null; @@ -2106,6 +2109,8 @@ function ConnectDialog({ defaultChannel, privilegeKey, serverType, + loginName, + loginPassword, expanded, connecting, identities, @@ -2117,6 +2122,8 @@ function ConnectDialog({ onDefaultChannelChange, onPrivilegeKeyChange, onServerTypeChange, + onLoginNameChange, + onLoginPasswordChange, onActiveIdentityChange, onToggleExpanded, onConnect, @@ -2133,6 +2140,8 @@ function ConnectDialog({ defaultChannel: string; privilegeKey: string; serverType: ServerType; + loginName: string; + loginPassword: string; expanded: boolean; connecting: boolean; identities: Identity[]; @@ -2143,6 +2152,8 @@ function ConnectDialog({ onChannelPasswordChange: (v: string) => void; onDefaultChannelChange: (v: string) => void; onPrivilegeKeyChange: (v: string) => void; + onLoginNameChange: (v: string) => void; + onLoginPasswordChange: (v: string) => void; onServerTypeChange: (v: ServerType) => void; onActiveIdentityChange: (id: string) => void; onToggleExpanded: () => void; @@ -2300,6 +2311,27 @@ function ConnectDialog({ )} + {serverType === "ts2" && ( + <> + + + + )}