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());
|
||||
|
||||
110
ts3-client/core/src/main/java/com/ts3client/net/Details.java
Normal file
110
ts3-client/core/src/main/java/com/ts3client/net/Details.java
Normal file
@@ -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()) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DetailsTest {
|
||||
|
||||
@Test
|
||||
void serverTakesInitserverAndEditsAndBareKeys() {
|
||||
ServerModel model = new ServerModel();
|
||||
model.setServerName("Test");
|
||||
Map<String, String> init = new HashMap<>();
|
||||
init.put("virtualserver_version", "3.13.7");
|
||||
init.put("virtualserver_platform", "Linux");
|
||||
init.put("virtualserver_maxclients", "32");
|
||||
init.put("virtualserver_welcomemessage", "Hello");
|
||||
// An empty property comes as a bare key.
|
||||
init.put("virtualserver_hostmessage", null);
|
||||
model.putServerProperties(init);
|
||||
model.putServerProperties(Map.of("virtualserver_hostmessage", "Be nice", "invokerid", "5"));
|
||||
|
||||
Details d = Details.server(model, "host:9987");
|
||||
assertEquals("Test", d.title());
|
||||
assertEquals(new Details.Field("Version", "3.13.7 on Linux"), d.fields().get(1));
|
||||
assertEquals(new Details.Field("Clients", "0 / 32"), d.fields().get(2));
|
||||
assertEquals("Hello\n\nBe nice", d.description());
|
||||
assertEquals("", model.serverProperty("invokerid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void channelDescriptionIsPendingUntilAnswered() {
|
||||
ChannelNode ch = new ChannelNode(1, "Lobby");
|
||||
ch.topic = "Entry";
|
||||
assertTrue(Details.channel(ch).pending());
|
||||
ch.descriptionLoaded = true;
|
||||
Details d = Details.channel(ch);
|
||||
assertFalse(d.pending());
|
||||
assertEquals(List.of(new Details.Field("Topic", "Entry")), d.fields());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ts3client.text;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** The block tags TeamSpeak's own client renders in descriptions. */
|
||||
class BBCodeTagsTest {
|
||||
|
||||
@Test
|
||||
void rulesStandAlone() {
|
||||
assertEquals("a<hr>b", BBCode.toHtml("a[hr]b"));
|
||||
assertEquals("a<hr>b", BBCode.toHtml("a[hr][/hr]b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void alignsBlocks() {
|
||||
assertEquals("<div align=\"right\">x</div><div align=\"justify\">y</div>",
|
||||
BBCode.toHtml("[right]x[/right][justify]y[/justify]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void numbersLists() {
|
||||
assertEquals("<ol><li>one</li><li>two</li></ol>", BBCode.toHtml("[list=1][*]one[*]two[/list]"));
|
||||
assertEquals("<ol type=\"a\"><li>x</li></ol>", BBCode.toHtml("[list=a][*]x[/list]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildsTablesOnlyWhereTheyNest() {
|
||||
assertEquals("<table><tr><th>h</th><td>d</td></tr></table>",
|
||||
BBCode.toHtml("[table][tr][th]h[/th][td]d[/td][/tr][/table]"));
|
||||
assertEquals("[td]loose[/td]", BBCode.toHtml("[td]loose[/td]"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user