Show server, channel and client details on Android, and the server's on the desktop
Core's Details says what the info box tells, as TeamSpeak's info frame does: labelled facts, then a BBCode description. The desktop info panel now lays it out instead of building its own, and selecting the server row shows the server: address, version, clients, channels, creation date and its welcome and host messages, from the virtualserver_* properties kept since initserver. On Android the channel and client sheets show the same details, asking the server for a missing channel description or a client's variables; tapping the server row opens a server sheet. Descriptions render as TeamSpeak's do: BBCode now knows [hr], [left]/[right]/[justify], numbered and lettered lists and tables, which Android's HTML parser approximates — rules as dividers, table rows as lines, list items numbered, font sizes as big/small. Links are blue whatever the wallpaper. Push-to-talk in the bottom bar follows whichever server holds the microphone, and a server without it keeps its button to take it in a fixed slot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -493,6 +493,7 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
@Override
|
||||
public void onServerEdit(ServerEditedEvent e) {
|
||||
if (has(e, "virtualserver_name")) conn.getModel().setServerName(e.get("virtualserver_name"));
|
||||
conn.getModel().putServerProperties(e.getMap());
|
||||
if (conn.isConnected()) {
|
||||
conn.sound(byInvoker(e, SoundEvent.SERVER_EDITED_BY_YOU, SoundEvent.SERVER_EDITED_BY_OTHER,
|
||||
SoundEvent.SERVER_EDITED_BY_OTHER), conn.serverVars());
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
import com.ts3client.contacts.Contact;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* What the info box tells about the server, a channel or a client, as the TeamSpeak 3 client's
|
||||
* info frame does: labelled facts, then a description in BBCode. The same on every frontend,
|
||||
* which only lays it out.
|
||||
*
|
||||
* @param description BBCode; empty when there is none
|
||||
* @param pending the description is still being asked for
|
||||
*/
|
||||
public record Details(String title, List<Field> fields, String description, boolean pending) {
|
||||
|
||||
/**
|
||||
* One labelled fact.
|
||||
*
|
||||
* @param groups the groups {@code value} names, in order, for frontends that show their icons;
|
||||
* empty when it names none
|
||||
*/
|
||||
public record Field(String label, String value, List<Group> groups) {
|
||||
Field(String label, String value) {
|
||||
this(label, value, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
public static Details server(ServerModel model, String address) {
|
||||
List<Field> fields = new ArrayList<>();
|
||||
fields.add(new Field("Address", address));
|
||||
String version = model.serverProperty("virtualserver_version");
|
||||
String platform = model.serverProperty("virtualserver_platform");
|
||||
if (!version.isEmpty()) fields.add(new Field("Version", version + (platform.isEmpty() ? "" : " on " + platform)));
|
||||
String max = model.serverProperty("virtualserver_maxclients");
|
||||
fields.add(new Field("Clients", model.clientCount() + (max.isEmpty() ? "" : " / " + max)));
|
||||
fields.add(new Field("Channels", Integer.toString(model.channelCount())));
|
||||
long created = parseLong(model.serverProperty("virtualserver_created"));
|
||||
if (created > 0) {
|
||||
fields.add(new Field("Created", DATE.format(Instant.ofEpochSecond(created).atZone(ZoneId.systemDefault()))));
|
||||
}
|
||||
String welcome = model.serverProperty("virtualserver_welcomemessage").trim();
|
||||
String host = model.serverProperty("virtualserver_hostmessage").trim();
|
||||
String description = welcome.isEmpty() || host.isEmpty() ? welcome + host : welcome + "\n\n" + host;
|
||||
return new Details(model.getServerName(), fields, description, false);
|
||||
}
|
||||
|
||||
public static Details channel(ChannelNode ch) {
|
||||
List<Field> fields = new ArrayList<>();
|
||||
if (ch.maxClients >= 0) fields.add(new Field("Max clients", Integer.toString(ch.maxClients)));
|
||||
if (ch.hasPassword) fields.add(new Field("Password", "protected"));
|
||||
if (!ch.topic.isEmpty()) fields.add(new Field("Topic", ch.topic));
|
||||
String description = ch.description == null ? "" : ch.description;
|
||||
return new Details(ch.name, fields, description, description.isEmpty() && !ch.descriptionLoaded);
|
||||
}
|
||||
|
||||
/** @param contact the client's contact entry, or null */
|
||||
public static Details client(ClientEntry cl, ServerModel model, Contact contact) {
|
||||
List<Field> fields = new ArrayList<>();
|
||||
if (contact != null) {
|
||||
String type = contact.type.label();
|
||||
if (!contact.phoneticNickname.isEmpty()) type += " (" + contact.phoneticNickname + ")";
|
||||
fields.add(new Field("Contact", type));
|
||||
}
|
||||
|
||||
List<Group> serverGroups = model.serverGroupsOf(cl.serverGroupIds);
|
||||
if (serverGroups.isEmpty()) {
|
||||
List<String> names = model.serverGroupNames(cl.serverGroupIds);
|
||||
fields.add(new Field("Server groups", names.isEmpty() ? "—" : String.join(", ", names)));
|
||||
} else {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Group g : serverGroups) names.add(g.name);
|
||||
fields.add(new Field("Server groups", String.join(", ", names), serverGroups));
|
||||
}
|
||||
Group channelGroup = model.channelGroup(cl.channelGroupId);
|
||||
fields.add(channelGroup != null
|
||||
? new Field("Channel group", channelGroup.name, List.of(channelGroup))
|
||||
: new Field("Channel group", "#" + cl.channelGroupId));
|
||||
|
||||
if (cl.talkPower != 0) fields.add(new Field("Talk power", Integer.toString(cl.talkPower)));
|
||||
if (!cl.version.isEmpty()) {
|
||||
fields.add(new Field("Version", cl.version + (cl.platform.isEmpty() ? "" : " on " + cl.platform)));
|
||||
} else if (!cl.platform.isEmpty()) {
|
||||
fields.add(new Field("Platform", cl.platform));
|
||||
}
|
||||
if (cl.away) fields.add(new Field("Status", "Away"));
|
||||
if (!cl.inputHardware) fields.add(new Field("Microphone", "disabled"));
|
||||
else if (cl.inputMuted) fields.add(new Field("Microphone", "muted"));
|
||||
if (!cl.outputHardware) fields.add(new Field("Speakers", "disabled"));
|
||||
else if (cl.outputMuted) fields.add(new Field("Speakers", "muted"));
|
||||
if (!cl.uniqueId.isEmpty()) fields.add(new Field("Unique ID", cl.uniqueId));
|
||||
|
||||
String name = contact == null ? cl.nickname : contact.displayName(cl.nickname);
|
||||
return new Details(name, fields, cl.description == null ? "" : cl.description, false);
|
||||
}
|
||||
|
||||
private static long parseLong(String s) {
|
||||
try {
|
||||
return s.isEmpty() ? 0 : Long.parseLong(s.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ public final class ServerModel {
|
||||
/** Permission id -> the local client's resolved value, from {@code notifyclientneededpermissions}. */
|
||||
private final Map<Integer, Integer> selfPermissionValues = new LinkedHashMap<>();
|
||||
private String serverName = "TeamSpeak Server";
|
||||
/** The {@code virtualserver_*} properties from {@code initserver}, kept up to date by server edits. */
|
||||
private final Map<String, String> serverProperties = new HashMap<>();
|
||||
/** The channel group everyone starts in, e.g. "Guest" — not worth offering to (re)assign. */
|
||||
private int defaultChannelGroupId;
|
||||
|
||||
@@ -45,6 +47,7 @@ public final class ServerModel {
|
||||
permissionIds.clear();
|
||||
nextPermissionId = FIRST_PERMISSION_ID;
|
||||
selfPermissionValues.clear();
|
||||
serverProperties.clear();
|
||||
defaultChannelGroupId = 0;
|
||||
}
|
||||
|
||||
@@ -207,6 +210,19 @@ public final class ServerModel {
|
||||
if (name != null && !name.isEmpty()) this.serverName = name;
|
||||
}
|
||||
|
||||
/** Takes on the server properties among {@code properties}, keeping the others. */
|
||||
public synchronized void putServerProperties(Map<String, String> properties) {
|
||||
properties.forEach((key, value) -> {
|
||||
// An empty property comes as a bare key, without a value.
|
||||
if (key.startsWith("virtualserver_")) serverProperties.put(key, value == null ? "" : value);
|
||||
});
|
||||
}
|
||||
|
||||
/** @return the server property, empty when unknown */
|
||||
public synchronized String serverProperty(String key) {
|
||||
return serverProperties.getOrDefault(key, "");
|
||||
}
|
||||
|
||||
public synchronized int defaultChannelGroupId() {
|
||||
return defaultChannelGroupId;
|
||||
}
|
||||
@@ -450,6 +466,10 @@ public final class ServerModel {
|
||||
siblings.addAll(ordered);
|
||||
}
|
||||
|
||||
public synchronized int channelCount() {
|
||||
return channels.size();
|
||||
}
|
||||
|
||||
public synchronized int clientCount() {
|
||||
int n = 0;
|
||||
for (ClientEntry c : clients.values()) if (!c.isQuery()) n++;
|
||||
|
||||
@@ -500,6 +500,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
}
|
||||
// The name comes with initserver; servergetvariables never reports it.
|
||||
model.setServerName(client.getServerName());
|
||||
model.putServerProperties(client.getServerProperties());
|
||||
model.setDefaultChannelGroupId(
|
||||
(int) safeLong(client.getServerProperties().get("virtualserver_default_channel_group")));
|
||||
}
|
||||
|
||||
@@ -136,10 +136,28 @@ public final class BBCode {
|
||||
return push(out, open, name, "<u>", "</u>");
|
||||
case "s":
|
||||
return push(out, open, name, "<strike>", "</strike>");
|
||||
case "hr":
|
||||
// Stands alone; a closing tag some write after it is dropped, see closeTag.
|
||||
out.append("<hr>");
|
||||
return true;
|
||||
case "left":
|
||||
case "center":
|
||||
return push(out, open, name, "<div align=\"center\">", "</div>");
|
||||
case "right":
|
||||
case "justify":
|
||||
return push(out, open, name, "<div align=\"" + name + "\">", "</div>");
|
||||
case "list":
|
||||
if (value.equals("1")) return push(out, open, name, "<ol>", "</ol>");
|
||||
if (value.equalsIgnoreCase("a")) return push(out, open, name, "<ol type=\"a\">", "</ol>");
|
||||
return push(out, open, name, "<ul>", "</ul>");
|
||||
case "table":
|
||||
return push(out, open, name, "<table>", "</table>");
|
||||
case "tr":
|
||||
if (!contains(open, "table")) return false;
|
||||
return push(out, open, name, "<tr>", "</tr>");
|
||||
case "td":
|
||||
case "th":
|
||||
if (!contains(open, "tr")) return false;
|
||||
return push(out, open, name, "<" + name + ">", "</" + name + ">");
|
||||
case "color": {
|
||||
if (!COLOR.matcher(value).matches()) return false;
|
||||
return push(out, open, name, "<font color=\"" + value + "\">", "</font>");
|
||||
@@ -159,6 +177,7 @@ public final class BBCode {
|
||||
}
|
||||
|
||||
private static boolean closeTag(StringBuilder out, String name, Deque<Open> open) {
|
||||
if (name.equals("hr")) return true;
|
||||
if (!contains(open, name)) return false;
|
||||
// Close anything left dangling inside, then the tag itself.
|
||||
while (!open.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user