diff --git a/connector/src/main.rs b/connector/src/main.rs index 69eb01c..042f45c 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -588,10 +588,14 @@ async fn run(args: Args) -> Result<()> { tracing_subscriber::fmt().with_env_filter("warn").with_writer(std::io::stderr).init(); let address = args.address.clone(); + // Accepts either our own persisted JSON blob (serialized below) or a raw + // TS3 identity string ("V", the format used by the + // native client's exported .ini files and teamspeak:// URLs) - the web + // client's "Identitäten importieren" can hand in either. let identity = args .identity .as_deref() - .and_then(|s| serde_json::from_str::(s).ok()) + .and_then(|s| serde_json::from_str::(s).ok().or_else(|| Identity::new_from_str(s).ok())) .unwrap_or_else(Identity::create); let identity_str = serde_json::to_string(&identity).unwrap(); let mut con_config = Connection::build(args.address).name(args.nickname).identity(identity); diff --git a/web/src/App.tsx b/web/src/App.tsx index 0fcfb19..e1f5dce 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -2864,7 +2864,7 @@ function IdentitiesDialog({ { const file = e.target.files?.[0]; @@ -5345,10 +5345,45 @@ function AppInner() { URL.revokeObjectURL(url); }; + /** Parses the native client's identity .ini format: + * [Identity] + * id= + * identity="V" + * nickname=<...> + * phonetic_nickname=<...> + * Returns null if it doesn't look like one. */ + const parseIniIdentity = (text: string): { name: string; nickname: string; phonetic: string; blob: string } | null => { + if (!/^\s*\[Identity\]/im.test(text)) return null; + const fields: Record = {}; + for (const line of text.split(/\r?\n/)) { + const m = line.match(/^(\w+)\s*=\s*(.*)$/); + if (!m) continue; + let value = m[2].trim(); + if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1); + // The native client escapes non-ASCII bytes in this file as \xHH. + value = value.replace(/\\x([0-9a-fA-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))); + fields[m[1]] = value; + } + if (!fields.identity) return null; + return { name: fields.id ?? "", nickname: fields.nickname ?? "", phonetic: fields.phonetic_nickname ?? "", blob: fields.identity }; + }; + const handleImportIdentity = (file: File) => { const reader = new FileReader(); reader.onload = () => { const text = (reader.result as string).trim(); + const ini = parseIniIdentity(text); + if (ini) { + const identity: Identity = { + id: crypto.randomUUID(), + name: ini.name || file.name.replace(/\.ini$/i, "") || t("identities.newName"), + nickname: ini.nickname, + phoneticName: ini.phonetic, + blob: ini.blob, + }; + setIdentities((prev) => [...prev, identity]); + return; + } try { JSON.parse(text); } catch {