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