diff --git a/ts3-client/core/src/main/java/com/ts3client/net/TeamspeakConnection.java b/ts3-client/core/src/main/java/com/ts3client/net/TeamspeakConnection.java index a809e0d..67f01f1 100644 --- a/ts3-client/core/src/main/java/com/ts3client/net/TeamspeakConnection.java +++ b/ts3-client/core/src/main/java/com/ts3client/net/TeamspeakConnection.java @@ -4,10 +4,10 @@ import com.github.manevolent.ts3j.api.Client; import com.github.manevolent.ts3j.command.CommandException; import com.github.manevolent.ts3j.command.MultiCommand; import com.github.manevolent.ts3j.command.SingleCommand; -import com.github.manevolent.ts3j.command.parameter.CommandParameter; import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter; import com.github.manevolent.ts3j.event.*; import com.github.manevolent.ts3j.identity.LocalIdentity; +import com.github.manevolent.ts3j.identity.Uid; import com.github.manevolent.ts3j.protocol.ProtocolRole; import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket; import com.github.manevolent.ts3j.util.Ts3Crypt; @@ -35,7 +35,6 @@ import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.util.ArrayList; -import java.util.Base64; import java.util.Collection; import java.util.List; import java.util.Map; @@ -1394,7 +1393,7 @@ public final class TeamspeakConnection implements TS3Listener { String uniqueId = serverUniqueId(); if (uniqueId == null) { chatLogs = null; - ui.onStatus("Chat logs unavailable: server unique id was not reported"); + ui.onStatus("Chat logs unavailable: the server's unique id is not known"); return; } ChatLogStore logs = new ChatLogStore(uniqueId); @@ -1413,72 +1412,8 @@ public final class TeamspeakConnection implements TS3Listener { } private String serverUniqueId() { - String uniqueId = validServerUniqueId(firstPresent( - client.getServerProperties().get("virtualserver_unique_identifier"), - client.getServerProperties().get("virtualserver_unique_id"))); - if (uniqueId != null) return uniqueId; - - uniqueId = serverUniqueIdFrom(new SingleCommand("serverinfo", ProtocolRole.CLIENT)); - if (uniqueId != null) return uniqueId; - - try { - SingleCommand command = new SingleCommand("servergetvariables", ProtocolRole.CLIENT); - String serverId = client.getServerProperties().get("virtualserver_id"); - if (serverId != null && !serverId.isBlank()) { - command.add(new CommandSingleParameter("virtualserver_id", serverId)); - } - return serverUniqueIdFrom(command); - } catch (Exception ignored) { - return null; - } - } - - private String serverUniqueIdFrom(SingleCommand command) { - try { - for (SingleCommand response : client.executeCommand(command).get()) { - String uniqueId = validServerUniqueId(firstPresent( - parameterValue(response, "virtualserver_unique_identifier"), - parameterValue(response, "virtualserver_unique_id"))); - if (uniqueId != null) return uniqueId; - } - return null; - } catch (Exception e) { - return null; - } - } - - private static String validServerUniqueId(String value) { - if (value == null || value.isBlank()) return null; - try { - byte[] decoded = Base64.getDecoder().decode(value); - if (decoded.length != 20) return null; - - // TS3 server UIDs are SHA-1-sized binary identifiers represented as base64. - // Plain host strings are rejected before they can become log folder names. - boolean printable = true; - for (byte b : decoded) { - int c = b & 0xff; - if (c < 0x20 || c > 0x7e) { - printable = false; - break; - } - } - return printable ? null : value; - } catch (IllegalArgumentException e) { - return null; - } - } - - private static String firstPresent(String... values) { - for (String value : values) { - if (value != null && !value.isBlank()) return value; - } - return null; - } - - private static String parameterValue(SingleCommand command, String key) { - CommandParameter parameter = command.get(key); - return parameter == null ? null : parameter.getValue(); + Uid uid = client.getServerUid(); + return uid == null ? null : uid.toBase64(); } public void loadPrivateChatHistory(int clientId, String uniqueId) { diff --git a/ts3j b/ts3j index 8273a27..c47bbdf 160000 --- a/ts3j +++ b/ts3j @@ -1 +1 @@ -Subproject commit 8273a27160de9ece6fb3cde933411f623885b134 +Subproject commit c47bbdf96c15e8241b927893c5196b078a1947ba