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());
|
||||
|
||||
Reference in New Issue
Block a user