Show the myTeamSpeak ID, UUID and creation date in the account tab

The ID is the account's base32 myTeamSpeak ID: the localpart of its chat
ID and the user the myTeamSpeak file API addresses. All three come from
the sign-in reply already fetched, on desktop and Android.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 08:03:59 +00:00
co-authored by Claude Opus 5.5
parent 023b449fba
commit 1bb788b501
6 changed files with 160 additions and 4 deletions
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Button import androidx.compose.material3.Button
@@ -41,11 +42,15 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.ts3client.android.SessionController import com.ts3client.android.SessionController
import com.ts3client.myts.AccountInfo
import com.ts3client.myts.MyTeamSpeak import com.ts3client.myts.MyTeamSpeak
import com.ts3client.myts.MyTsException import com.ts3client.myts.MyTsException
import com.ts3client.teamspeak.SyncItem import com.ts3client.teamspeak.SyncItem
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.IOException import java.io.IOException
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
private data class ItemRow(val item: SyncItem, val imported: Boolean, val selected: Boolean) private data class ItemRow(val item: SyncItem, val imported: Boolean, val selected: Boolean)
@@ -64,11 +69,13 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
var error by remember { mutableStateOf(false) } var error by remember { mutableStateOf(false) }
var email by remember { mutableStateOf("") } var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var info by remember { mutableStateOf<AccountInfo?>(null) }
var all by remember { mutableStateOf(emptyList<SyncItem>()) } var all by remember { mutableStateOf(emptyList<SyncItem>()) }
var rows by remember { mutableStateOf(emptyList<ItemRow>()) } var rows by remember { mutableStateOf(emptyList<ItemRow>()) }
BackHandler(onBack = onBack) BackHandler(onBack = onBack)
fun show(account: MyTeamSpeak.Account) { fun show(account: MyTeamSpeak.Account) {
info = account.info()
all = account.items() all = account.items()
rows = all.filter { it !is SyncItem.Folder }.map { rows = all.filter { it !is SyncItem.Folder }.map {
val imported = vm.isImported(it) val imported = vm.isImported(it)
@@ -157,10 +164,20 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
signedIn = false signedIn = false
rows = emptyList() rows = emptyList()
all = emptyList() all = emptyList()
info = null
message = null message = null
}) { Text("Sign out") } }) { Text("Sign out") }
} }
} }
info?.let { details ->
item {
Column(Modifier.padding(horizontal = 16.dp)) {
if (details.userId().isNotEmpty()) Detail("ID", details.userId())
if (details.uuid().isNotEmpty()) Detail("UUID", details.uuid())
details.created()?.let { Detail("Created", dateFormat.format(it)) }
}
}
}
if (rows.isNotEmpty()) { if (rows.isNotEmpty()) {
item { item {
Text("Synchronised by the account", Modifier.padding(start = 16.dp, top = 16.dp), Text("Synchronised by the account", Modifier.padding(start = 16.dp, top = 16.dp),
@@ -204,6 +221,17 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
} }
} }
private val dateFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withZone(ZoneId.systemDefault())
/** A labelled value that can be selected and copied. */
@Composable
private fun Detail(label: String, value: String) {
Column(Modifier.padding(top = 8.dp)) {
Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
SelectionContainer { Text(value, style = MaterialTheme.typography.bodyMedium) }
}
}
private fun name(item: SyncItem) = when (item) { private fun name(item: SyncItem) = when (item) {
is SyncItem.Bookmark -> item.name().ifBlank { item.address() } is SyncItem.Bookmark -> item.name().ifBlank { item.address() }
is SyncItem.Identity -> "Identity: ${item.name()}" is SyncItem.Identity -> "Identity: ${item.name()}"
@@ -0,0 +1,38 @@
package com.ts3client.myts;
import java.time.Instant;
/**
* Who a myTeamSpeak account is, as its sign-in reply says. The {@code userId} is the
* account's myTeamSpeak ID: also the localpart of its TeamSpeak chat ID and the user the
* file API addresses.
*
* @param userId empty when the reply carried none
* @param created null when the reply carried none
*/
public record AccountInfo(String username, String userId, String uuid, Instant created) {
private static final String BASE32 = "abcdefghijklmnopqrstuvwxyz234567";
static AccountInfo of(String username, String uuid, byte[] userId, long createdSeconds) {
return new AccountInfo(username, userId == null ? "" : base32(userId), uuid,
createdSeconds > 0 ? Instant.ofEpochSecond(createdSeconds) : null);
}
/** RFC 4648 base32, lowercase and unpadded. */
static String base32(byte[] data) {
StringBuilder out = new StringBuilder((data.length * 8 + 4) / 5);
int buffer = 0, bits = 0;
for (byte b : data) {
buffer = (buffer << 8) | (b & 0xff);
bits += 8;
while (bits >= 5) {
out.append(BASE32.charAt((buffer >> (bits - 5)) & 31));
bits -= 5;
}
buffer &= (1 << bits) - 1;
}
if (bits > 0) out.append(BASE32.charAt((buffer << (5 - bits)) & 31));
return out.toString();
}
}
@@ -24,11 +24,15 @@ public final class MyTeamSpeak {
public static final URI API = URI.create("https://clientapi.myteamspeak.com/"); public static final URI API = URI.create("https://clientapi.myteamspeak.com/");
/** What the account holds, in the same form as a local TeamSpeak 3 client's store. */ /** What the account holds, in the same form as a local TeamSpeak 3 client's store. */
public record Account(String username, List<SyncItem> items) { public record Account(AccountInfo info, List<SyncItem> items) {
public Account { public Account {
items = List.copyOf(items); items = List.copyOf(items);
} }
public String username() {
return info.username();
}
public long identities() { public long identities() {
return items.stream().filter(SyncItem.Identity.class::isInstance).count(); return items.stream().filter(SyncItem.Identity.class::isInstance).count();
} }
@@ -94,14 +98,27 @@ public final class MyTeamSpeak {
new ProtobufWriter().string(1, email).string(2, loginToken).toByteArray())); new ProtobufWriter().string(1, email).string(2, loginToken).toByteArray()));
byte[] keyPackage = null; byte[] keyPackage = null;
String session = "", username = ""; String session = "", username = "", uuid = "";
byte[] userId = null;
long createdAt = 0;
int error = 0; int error = 0;
while (reply.next()) { while (reply.next()) {
switch (reply.fieldNumber()) { switch (reply.fieldNumber()) {
case 1 -> keyPackage = reply.readBytes(); case 1 -> keyPackage = reply.readBytes();
case 2 -> session = reply.readString(); case 2 -> session = reply.readString();
case 5 -> error = (int) reply.readVarint(); case 5 -> error = (int) reply.readVarint();
case 4 -> uuid = reply.readString();
case 8 -> username = reply.readString(); case 8 -> username = reply.readString();
case 9 -> {
ProtobufReader identity = reply.readMessage();
while (identity.next()) {
switch (identity.fieldNumber()) {
case 3 -> createdAt = identity.readVarint();
case 4 -> userId = identity.readBytes();
default -> identity.skip();
}
}
}
default -> reply.skip(); default -> reply.skip();
} }
} }
@@ -114,7 +131,7 @@ public final class MyTeamSpeak {
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new MyTsException("Could not unlock the account's encrypted data", e); throw new MyTsException("Could not unlock the account's encrypted data", e);
} }
return new Account(username, pull(session, itemKey)); return new Account(AccountInfo.of(username, uuid, userId, createdAt), pull(session, itemKey));
} finally { } finally {
signOut(session); signOut(session);
} }
@@ -0,0 +1,33 @@
package com.ts3client.myts;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class AccountInfoTest {
private static String base32(String text) {
return AccountInfo.base32(text.getBytes(StandardCharsets.US_ASCII));
}
@Test
void encodesRfc4648VectorsLowercaseAndUnpadded() {
assertEquals("", base32(""));
assertEquals("my", base32("f"));
assertEquals("mzxq", base32("fo"));
assertEquals("mzxw6", base32("foo"));
assertEquals("mzxw6yq", base32("foob"));
assertEquals("mzxw6ytb", base32("fooba"));
assertEquals("mzxw6ytboi", base32("foobar"));
}
@Test
void toleratesAReplyWithoutIdentityData() {
AccountInfo info = AccountInfo.of("tester", "u", null, 0);
assertEquals("", info.userId());
assertNull(info.created());
}
}
@@ -48,7 +48,11 @@ class MyTeamSpeakTest {
.bytes(1, MyTsCryptoTest.KEY_PACKAGE) .bytes(1, MyTsCryptoTest.KEY_PACKAGE)
.string(2, SESSION) .string(2, SESSION)
.varint(5, 200) .varint(5, 200)
.string(4, "828613f7-3cde-45e6-993e-c57ee979a39f")
.string(8, "tester") .string(8, "tester")
.message(9, new ProtobufWriter().varint(3, 1_770_000_000L)
.bytes(4, java.util.HexFormat.of().parseHex(
"0120b05c4b1a2d3e4f5061728394a5b6c7d8e9f00112233445566778899aabbccd")))
.toByteArray(); .toByteArray();
} }
@@ -82,6 +86,9 @@ class MyTeamSpeakTest {
MyTeamSpeak.Account account = new MyTeamSpeak(server).download(credentials(MyTsCryptoTest.PASSWORD)); MyTeamSpeak.Account account = new MyTeamSpeak(server).download(credentials(MyTsCryptoTest.PASSWORD));
assertEquals("tester", account.username()); assertEquals("tester", account.username());
assertEquals("828613f7-3cde-45e6-993e-c57ee979a39f", account.info().uuid());
assertEquals(java.time.Instant.ofEpochSecond(1_770_000_000L), account.info().created());
assertEquals("aeqlaxcldiwt4t2qmfzihfffw3d5r2pqaejcgncfkztxrcm2vo6m2", account.info().userId());
assertEquals(1, account.items().size()); assertEquals(1, account.items().size());
SyncItem.Bookmark bookmark = assertInstanceOf(SyncItem.Bookmark.class, account.items().get(0)); SyncItem.Bookmark bookmark = assertInstanceOf(SyncItem.Bookmark.class, account.items().get(0));
assertEquals("server.lixko.eu", bookmark.address()); assertEquals("server.lixko.eu", bookmark.address());
@@ -2,6 +2,7 @@ package com.ts3client.ui;
import com.formdev.flatlaf.util.ScaledEmptyBorder; import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
import com.ts3client.myts.AccountInfo;
import com.ts3client.myts.MyTeamSpeak; import com.ts3client.myts.MyTeamSpeak;
import com.ts3client.myts.MyTeamSpeakLogin; import com.ts3client.myts.MyTeamSpeakLogin;
import com.ts3client.myts.MyTsException; import com.ts3client.myts.MyTsException;
@@ -25,6 +26,9 @@ import java.awt.CardLayout;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.io.IOException; import java.io.IOException;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -50,6 +54,7 @@ final class MyTeamSpeakPanel extends JPanel {
private final JLabel signInStatus = new JLabel(" "); private final JLabel signInStatus = new JLabel(" ");
private final JLabel account = new JLabel(); private final JLabel account = new JLabel();
private final JPanel details = new JPanel(new GridBagLayout());
private final ItemTable items = new ItemTable(); private final ItemTable items = new ItemTable();
private final JButton refresh = new JButton("Refresh"); private final JButton refresh = new JButton("Refresh");
private final JButton importButton = new JButton("Import selected"); private final JButton importButton = new JButton("Import selected");
@@ -108,6 +113,9 @@ final class MyTeamSpeakPanel extends JPanel {
signOut.addActionListener(e -> signOut()); signOut.addActionListener(e -> signOut());
header.add(account, BorderLayout.CENTER); header.add(account, BorderLayout.CENTER);
header.add(signOut, BorderLayout.EAST); header.add(signOut, BorderLayout.EAST);
JPanel top = new JPanel(new BorderLayout(0, UIScale.scale(8)));
top.add(header, BorderLayout.NORTH);
top.add(details, BorderLayout.CENTER);
JPanel buttons = new JPanel(); JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
@@ -126,7 +134,7 @@ final class MyTeamSpeakPanel extends JPanel {
JPanel panel = new JPanel(new BorderLayout(0, UIScale.scale(12))); JPanel panel = new JPanel(new BorderLayout(0, UIScale.scale(12)));
panel.setBorder(new ScaledEmptyBorder(12, 12, 12, 12)); panel.setBorder(new ScaledEmptyBorder(12, 12, 12, 12));
panel.add(header, BorderLayout.NORTH); panel.add(top, BorderLayout.NORTH);
panel.add(data, BorderLayout.CENTER); panel.add(data, BorderLayout.CENTER);
return panel; return panel;
} }
@@ -167,6 +175,7 @@ final class MyTeamSpeakPanel extends JPanel {
private void signOut() { private void signOut() {
login.signOut(); login.signOut();
accountItems = List.of(); accountItems = List.of();
details.removeAll();
items.set(List.of()); items.set(List.of());
fetched = false; fetched = false;
email.setText(""); email.setText("");
@@ -193,8 +202,32 @@ final class MyTeamSpeakPanel extends JPanel {
}); });
} }
private void showDetails(AccountInfo info) {
details.removeAll();
GridBagConstraints c = FormPanel.gbc();
int row = 0;
if (!info.userId().isEmpty()) FormPanel.addRow(details, c, row++, new JLabel("ID:"), selectable(info.userId()));
if (!info.uuid().isEmpty()) FormPanel.addRow(details, c, row++, new JLabel("UUID:"), selectable(info.uuid()));
if (info.created() != null) {
String date = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
.format(info.created().atZone(ZoneId.systemDefault()));
FormPanel.addRow(details, c, row, new JLabel("Created:"), selectable(date));
}
details.revalidate();
details.repaint();
}
/** A value that can be selected and copied but not edited. */
private static JTextField selectable(String value) {
JTextField field = new JTextField(value);
field.setEditable(false);
field.setCaretPosition(0);
return field;
}
private void showItems(MyTeamSpeak.Account result) { private void showItems(MyTeamSpeak.Account result) {
fetched = true; fetched = true;
showDetails(result.info());
accountItems = result.items(); accountItems = result.items();
List<Row> rows = new ArrayList<>(); List<Row> rows = new ArrayList<>();
for (SyncItem item : accountItems) { for (SyncItem item : accountItems) {