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:
@@ -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/");
|
||||
|
||||
/** 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 {
|
||||
items = List.copyOf(items);
|
||||
}
|
||||
|
||||
public String username() {
|
||||
return info.username();
|
||||
}
|
||||
|
||||
public long identities() {
|
||||
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()));
|
||||
|
||||
byte[] keyPackage = null;
|
||||
String session = "", username = "";
|
||||
String session = "", username = "", uuid = "";
|
||||
byte[] userId = null;
|
||||
long createdAt = 0;
|
||||
int error = 0;
|
||||
while (reply.next()) {
|
||||
switch (reply.fieldNumber()) {
|
||||
case 1 -> keyPackage = reply.readBytes();
|
||||
case 2 -> session = reply.readString();
|
||||
case 5 -> error = (int) reply.readVarint();
|
||||
case 4 -> uuid = 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();
|
||||
}
|
||||
}
|
||||
@@ -114,7 +131,7 @@ public final class MyTeamSpeak {
|
||||
} catch (GeneralSecurityException 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 {
|
||||
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)
|
||||
.string(2, SESSION)
|
||||
.varint(5, 200)
|
||||
.string(4, "828613f7-3cde-45e6-993e-c57ee979a39f")
|
||||
.string(8, "tester")
|
||||
.message(9, new ProtobufWriter().varint(3, 1_770_000_000L)
|
||||
.bytes(4, java.util.HexFormat.of().parseHex(
|
||||
"0120b05c4b1a2d3e4f5061728394a5b6c7d8e9f00112233445566778899aabbccd")))
|
||||
.toByteArray();
|
||||
}
|
||||
|
||||
@@ -82,6 +86,9 @@ class MyTeamSpeakTest {
|
||||
MyTeamSpeak.Account account = new MyTeamSpeak(server).download(credentials(MyTsCryptoTest.PASSWORD));
|
||||
|
||||
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());
|
||||
SyncItem.Bookmark bookmark = assertInstanceOf(SyncItem.Bookmark.class, account.items().get(0));
|
||||
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.UIScale;
|
||||
import com.ts3client.myts.AccountInfo;
|
||||
import com.ts3client.myts.MyTeamSpeak;
|
||||
import com.ts3client.myts.MyTeamSpeakLogin;
|
||||
import com.ts3client.myts.MyTsException;
|
||||
@@ -25,6 +26,9 @@ import java.awt.CardLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
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.List;
|
||||
|
||||
@@ -50,6 +54,7 @@ final class MyTeamSpeakPanel extends JPanel {
|
||||
private final JLabel signInStatus = new JLabel(" ");
|
||||
|
||||
private final JLabel account = new JLabel();
|
||||
private final JPanel details = new JPanel(new GridBagLayout());
|
||||
private final ItemTable items = new ItemTable();
|
||||
private final JButton refresh = new JButton("Refresh");
|
||||
private final JButton importButton = new JButton("Import selected");
|
||||
@@ -108,6 +113,9 @@ final class MyTeamSpeakPanel extends JPanel {
|
||||
signOut.addActionListener(e -> signOut());
|
||||
header.add(account, BorderLayout.CENTER);
|
||||
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();
|
||||
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)));
|
||||
panel.setBorder(new ScaledEmptyBorder(12, 12, 12, 12));
|
||||
panel.add(header, BorderLayout.NORTH);
|
||||
panel.add(top, BorderLayout.NORTH);
|
||||
panel.add(data, BorderLayout.CENTER);
|
||||
return panel;
|
||||
}
|
||||
@@ -167,6 +175,7 @@ final class MyTeamSpeakPanel extends JPanel {
|
||||
private void signOut() {
|
||||
login.signOut();
|
||||
accountItems = List.of();
|
||||
details.removeAll();
|
||||
items.set(List.of());
|
||||
fetched = false;
|
||||
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) {
|
||||
fetched = true;
|
||||
showDetails(result.info());
|
||||
accountItems = result.items();
|
||||
List<Row> rows = new ArrayList<>();
|
||||
for (SyncItem item : accountItems) {
|
||||
|
||||
Reference in New Issue
Block a user