diff --git a/connector/src/main.rs b/connector/src/main.rs index 82bd98f..30baeaa 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -38,6 +38,9 @@ const FRAME_SAMPLES: usize = 960; /// Upper bound for a file download relayed to the browser (see its use). const MAX_DOWNLOAD_BYTES: u64 = 25 << 20; const MAX_ICON_BYTES: u64 = 512 << 10; +/// Avatars are fetched for everyone in the user's channel without asking; +/// TS3 servers default to a 300 KiB avatar size limit. +const MAX_AVATAR_BYTES: u64 = 512 << 10; const OUT_CHANNELS: usize = 2; #[derive(Parser, Debug)] @@ -118,6 +121,9 @@ struct ClientInfo { /// sends no stream command in that case, so the id has to be fetched with /// `requeststreaminfo`. Always `false` on servers that don't report it. is_streaming: bool, + /// `client_flag_avatar`: MD5 of the client's avatar, empty without one. The + /// file itself is `/avatar_` in channel 0, fetched by the browser. + avatar_hash: String, } /// Payload for the "streamsetup " stdin command - the `setupstream` args, which @@ -669,6 +675,7 @@ fn snapshot(con: &data::Connection) -> Event { has_talk_power, is_query: matches!(c.client_type, ClientType::Query { .. }), is_streaming: c.is_streaming.unwrap_or(false), + avatar_hash: c.avatar_hash.clone(), } }) .collect::>(); @@ -2955,7 +2962,11 @@ async fn run(args: Args) -> Result<()> { let announced_size = result.size; // Group/server icons are fetched automatically, without the user // asking, so they get a far smaller budget than explicit downloads. - let limit = if cid == 0 && path.starts_with("/icon_") { MAX_ICON_BYTES } else { MAX_DOWNLOAD_BYTES }; + let limit = match path.as_str() { + p if cid == 0 && p.starts_with("/icon_") => MAX_ICON_BYTES, + p if cid == 0 && p.starts_with("/avatar_") => MAX_AVATAR_BYTES, + _ => MAX_DOWNLOAD_BYTES, + }; tokio::spawn(async move { if announced_size > limit { emit(&Event::Error { diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index f5d3c20..6a7cbfa 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -59,6 +59,8 @@ export interface ClientInfo { isQuery: boolean; /** Broadcasting a TS6 Stream/Call. The stream id is fetched separately. */ isStreaming: boolean; + /** MD5 of the avatar (`client_flag_avatar`), empty without one. */ + avatarHash: string; } export interface GroupEntry { @@ -318,6 +320,7 @@ export class Ts3Connection { has_talk_power: boolean; is_query?: boolean; is_streaming?: boolean; + avatar_hash?: string; } interface RawChannelInfo { @@ -493,6 +496,7 @@ export class Ts3Connection { hasTalkPower: c.has_talk_power, isQuery: Boolean(c.is_query), isStreaming: Boolean(c.is_streaming), + avatarHash: c.avatar_hash ?? "", })), ownClientId: event.own_client_id ?? 0, serverMaxClients: event.server_max_clients ?? 0, diff --git a/web/src/App.css b/web/src/App.css index 782a9e0..cdbbcc7 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1417,6 +1417,22 @@ flex: 1; } +.ts-avatar-img { + width: 100%; + height: 100%; + object-fit: cover; + border-radius: inherit; +} + +.ts-info-avatar { + display: block; + width: 64px; + height: 64px; + object-fit: cover; + border-radius: 6px; + margin: 0.2rem 0 0.4rem; +} + .ts-menu-volume input { flex: 1; min-width: 6rem; diff --git a/web/src/App.tsx b/web/src/App.tsx index b680094..6fec76b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -647,6 +647,8 @@ interface ClientInfo { isStreaming?: boolean; /** ServerQuery client; filtered from the tree unless a favorite enables them. */ isQuery?: boolean; + /** MD5 of the avatar, empty without one; missing from gateways before v0.15. */ + avatarHash?: string; } interface GroupEntry { @@ -1099,14 +1101,12 @@ function ChannelTree({ - - {c.name.trim().charAt(0).toUpperCase() || "?"} - + isSelf={c.id === ownClientId} + /> {countryFlag(c.country) && {countryFlag(c.country)}} {c.name} {c.away && c.awayMessage && ( @@ -1180,10 +1180,12 @@ function SpeakingNowBar({ clients, talkers, ownClientId, + images, }: { clients: ClientInfo[]; talkers: Set; ownClientId: number | null; + images: Record; }) { const own = clients.find((c) => c.id === ownClientId); if (!own) return null; @@ -1198,12 +1200,7 @@ function SpeakingNowBar({ className={`ts-speaking-now-tile${talkers.has(c.id) ? " ts-speaking-now-tile-active" : ""}`} title={c.name} > - - {c.name.trim().charAt(0).toUpperCase() || "?"} - + {c.name} ))} @@ -1224,6 +1221,7 @@ function InfoPanel({ channels, clients, serverGroups, + images, onShowServerConnectionInfo, onEditServer, }: { @@ -1239,6 +1237,7 @@ function InfoPanel({ channels: ChannelInfo[]; clients: ClientInfo[]; serverGroups: GroupEntry[] | null; + images: Record; onShowServerConnectionInfo: () => void; onEditServer: () => void; }) { @@ -1301,6 +1300,9 @@ function InfoPanel({ /> {client.name} + {clientAvatarUrl(client, images) && ( + + )} {client.country && (
{t("info.country")}{" "} @@ -3581,6 +3583,50 @@ function iconDataUrl(base64: string): string { return `data:${sniffImageMime(atob(base64))};base64,${base64}`; } +// TeamSpeak keeps a client's avatar as /avatar_ in channel 0's files, +// with the UID's decoded bytes spelled as one letter a-p per nibble. +function avatarPath(uid: string): string | null { + try { + const letters = [...atob(uid)].map((ch) => { + const b = ch.charCodeAt(0); + return String.fromCharCode(97 + (b >> 4), 97 + (b & 15)); + }); + return letters.length ? `/avatar_${letters.join("")}` : null; + } catch { + return null; + } +} + +/** Data URL of a client's downloaded avatar, or null to fall back to initials. */ +function clientAvatarUrl(client: ClientInfo, images: Record): string | null { + const path = client.avatarHash ? avatarPath(client.uid) : null; + const base64 = path ? images[path] : undefined; + return base64 ? iconDataUrl(base64) : null; +} + +/** The initials tile, or the real avatar once it has been downloaded. */ +function AvatarTile({ + client, + images, + className, + isSelf, +}: { + client: ClientInfo; + images: Record; + className: string; + isSelf: boolean; +}) { + const url = clientAvatarUrl(client, images); + return ( + + {url ? : client.name.trim().charAt(0).toUpperCase() || "?"} + + ); +} + // IDs below this are TeamSpeak's built-in default group icons - they ship // inside the official client and were never uploaded to the server's icon // filebase, so downloadFile() for them just hangs forever (nothing to send @@ -7282,6 +7328,7 @@ function AppInner() { case "connected": logClient("info", "Connection", `Connected to ${data.serverName}`); reconnectAttemptsRef.current.delete(sessionId); + autoConnectPendingRef.current = false; hasConnectedRef.current = true; everConnectedRef.current.add(sessionId); setConnecting(false); @@ -8162,6 +8209,26 @@ function AppInner() { } }, [clients, serverGroups, serverIconImages]); + // Avatars share that cid-0 cache, keyed by path; the hash makes a changed + // avatar download again. ponytail: only the own channel and the selected + // client - a big server's every avatar would be megabytes through the + // gateway; widen this if the tree designs ever need all of them. + const requestedAvatarHashesRef = useRef(new Map()); + useEffect(() => { + if (!connected) requestedAvatarHashesRef.current.clear(); + }, [connected]); + + useEffect(() => { + const ownChannel = clients.find((c) => c.id === ownClientId)?.channel; + for (const c of clients) { + const wanted = c.channel === ownChannel || (selected?.type === "client" && selected.id === c.id); + const path = wanted && c.avatarHash ? avatarPath(c.uid) : null; + if (!path || requestedAvatarHashesRef.current.get(path) === c.avatarHash) continue; + requestedAvatarHashesRef.current.set(path, c.avatarHash!); + socketRef.current?.send(JSON.stringify({ type: "downloadFile", channelId: 0, path })); + } + }, [clients, ownClientId, selected]); + useEffect(() => { if (!connected) { setWhisperChannelIds(new Set()); @@ -8322,9 +8389,10 @@ function AppInner() { // Nova-theme-only: the connect dialog IS the app until a connection exists - // it's forced open on load and after every disconnect, and closes itself the - // moment a connection succeeds. + // moment a connection succeeds (an auto-connect never went through the + // dialog's own close, so this has to do it). useEffect(() => { - if (designTheme === "nova" && !connected) setConnectDialogOpen(true); + if (designTheme === "nova") setConnectDialogOpen(!connected); }, [designTheme, connected]); // Overrides let a device/DSP-setting change take effect immediately, without @@ -9319,11 +9387,13 @@ function AppInner() { setServerIconsOpen(true); setServerIconEntries(null); setServerIconImages({}); + requestedAvatarHashesRef.current.clear(); socketRef.current?.send(JSON.stringify({ type: "getFileList", channelId: 0, path: "/" })); }; const handleServerIconsRefresh = () => { setServerIconImages({}); + requestedAvatarHashesRef.current.clear(); socketRef.current?.send(JSON.stringify({ type: "getFileList", channelId: 0, path: "/" })); }; @@ -11184,6 +11254,7 @@ function AppInner() { channels={channels} clients={treeClients} serverGroups={serverGroups} + images={serverIconImages} onShowServerConnectionInfo={handleShowServerConnectionInfo} onEditServer={() => setServerEditOpen(true)} /> @@ -11195,7 +11266,12 @@ function AppInner() {
{connected && designTheme === "pulse" && ( - + )}
{activeTab === "channel"