Desktop: block incoming whispers, Server Connection Info, ServerQuery toggle
- Block Incoming Whispers: toolbar toggle and the three TS3 hotkey actions; mutes all whispers per server, kept across reconnects. - Server Connection Info window (server menu or toolbar), as in TS3: version with build date, uptime, ping, loss and live In/Out traffic. The shared figures panel moves out of ConnectionInfoDialog. - ServerQuery clients are hidden in the tree unless toggled on (toolbar or the bookmark's "Show ServerQuery clients"), remembered per bookmark. - "Show Server Tabs" in the toolbar menu hides the server tab strip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,8 @@ public final class Bookmark {
|
||||
public boolean myTeamSpeakFeatures = true;
|
||||
/** Offer whispering in this server's menus. */
|
||||
public boolean showWhisperControls = false;
|
||||
/** List the server's ServerQuery clients in the tree. */
|
||||
public boolean showQueryClients = false;
|
||||
/** The server's icon as last seen there, 0 for none or not yet known. */
|
||||
public long iconId = 0;
|
||||
|
||||
@@ -52,6 +54,7 @@ public final class Bookmark {
|
||||
b.connectOnStartup = connectOnStartup;
|
||||
b.myTeamSpeakFeatures = myTeamSpeakFeatures;
|
||||
b.showWhisperControls = showWhisperControls;
|
||||
b.showQueryClients = showQueryClients;
|
||||
b.iconId = iconId;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,31 @@ public final class Bookmarks {
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** Whether a bookmark leading to the server lists its ServerQuery clients. */
|
||||
public boolean showsQueryClients(String address, int port) {
|
||||
for (Bookmark b : entries) {
|
||||
if (b.pointsAt(address, port) && b.showQueryClients) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has every bookmark leading to the server list its ServerQuery clients, or not.
|
||||
*
|
||||
* @return whether any bookmark changed, and so needs saving
|
||||
*/
|
||||
public boolean rememberQueryClients(String address, int port, boolean show) {
|
||||
if (address == null || address.isBlank()) return false;
|
||||
boolean changed = false;
|
||||
for (Bookmark b : entries) {
|
||||
if (b.pointsAt(address, port) && b.showQueryClients != show) {
|
||||
b.showQueryClients = show;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** The bookmark with this {@link Bookmark#id}, or null. */
|
||||
public Bookmark find(String id) {
|
||||
for (Bookmark b : entries) {
|
||||
@@ -90,6 +115,7 @@ public final class Bookmarks {
|
||||
bm.connectOnStartup = Boolean.parseBoolean(p.getProperty(prefix + "connectOnStartup", "false"));
|
||||
bm.myTeamSpeakFeatures = Boolean.parseBoolean(p.getProperty(prefix + "myTeamSpeakFeatures", "true"));
|
||||
bm.showWhisperControls = Boolean.parseBoolean(p.getProperty(prefix + "showWhisperControls", "false"));
|
||||
bm.showQueryClients = Boolean.parseBoolean(p.getProperty(prefix + "showQueryClients", "false"));
|
||||
bm.iconId = parseLong(p.getProperty(prefix + "iconId"));
|
||||
if (bm.address != null && !bm.address.isBlank()) b.entries.add(bm);
|
||||
}
|
||||
@@ -114,6 +140,7 @@ public final class Bookmarks {
|
||||
p.setProperty(prefix + "connectOnStartup", Boolean.toString(bm.connectOnStartup));
|
||||
p.setProperty(prefix + "myTeamSpeakFeatures", Boolean.toString(bm.myTeamSpeakFeatures));
|
||||
p.setProperty(prefix + "showWhisperControls", Boolean.toString(bm.showWhisperControls));
|
||||
p.setProperty(prefix + "showQueryClients", Boolean.toString(bm.showQueryClients));
|
||||
p.setProperty(prefix + "iconId", Long.toString(bm.iconId));
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -218,6 +218,8 @@ public final class Settings {
|
||||
// ---- window chrome ----
|
||||
/** Whether the status bar at the bottom of the window is shown. */
|
||||
public final Setting<Boolean> showStatusBar = flag("showStatusBar", true);
|
||||
/** The strip of server tabs while more than one server is open; hidden, only the one on screen shows. */
|
||||
public final Setting<Boolean> showServerTabs = flag("showServerTabs", true);
|
||||
/** The main toolbar's buttons in order, comma-separated action ids with "-" for a separator; empty for the default set. */
|
||||
public final Setting<String> toolbarLayout = text("toolbarLayout", "");
|
||||
/** Whether the Master Volume slider is shown on the toolbar. */
|
||||
|
||||
@@ -145,11 +145,11 @@ public enum HotkeyAction {
|
||||
WHISPER_REPLY_DEACTIVATE(Category.SELF, 0x0180, "DeactivateReply",
|
||||
"Deactivate Reply to a Whisper", true, Argument.NONE, false),
|
||||
WHISPER_BLOCK_ACTIVATE(Category.SELF, 0x0180, "ActivateBlock",
|
||||
"Activate Block Incoming Whispers", true, Argument.NONE, false),
|
||||
"Activate Block Incoming Whispers", true, Argument.NONE, true),
|
||||
WHISPER_BLOCK_DEACTIVATE(Category.SELF, 0x0180, "DeactivateBlock",
|
||||
"Deactivate Block Incoming Whispers", true, Argument.NONE, false),
|
||||
"Deactivate Block Incoming Whispers", true, Argument.NONE, true),
|
||||
WHISPER_BLOCK_TOGGLE(Category.SELF, 0x0180, "ToggleBlock",
|
||||
"Toggle Block Incoming Whispers", true, Argument.NONE, false),
|
||||
"Toggle Block Incoming Whispers", true, Argument.NONE, true),
|
||||
|
||||
RECORDING_START(Category.SELF, 0x01c0, "Activate",
|
||||
"Start Recording", true, Argument.NONE, false),
|
||||
|
||||
@@ -691,6 +691,7 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
else if ("notifytokenadd".equals(e.getCommand())) conn.privilegeKeys.onAdded(e);
|
||||
else if ("notifycomplainlist".equals(e.getCommand())) conn.complaints.onListEntry(e);
|
||||
else if ("notifyserverlog".equals(e.getCommand())) conn.serverLog.onLine(e);
|
||||
else if ("notifyserverconnectioninfo".equals(e.getCommand())) conn.serverStats.onReport(e);
|
||||
else conn.offlineMessages.onReply(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@ import eu.lixko.ts3j.client.audio.VoiceReceiveStats;
|
||||
import eu.lixko.ts3j.client.text.ByteSize;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Renders {@link ConnectionStats} the way the official Connection Info window does: a
|
||||
@@ -43,6 +48,12 @@ public final class ConnectionStatsFormat {
|
||||
new Tab("Keep Alive", ConnectionStats.Kind.KEEPALIVE),
|
||||
new Tab("Control", ConnectionStats.Kind.CONTROL));
|
||||
|
||||
/** The server window's traffic table headings. */
|
||||
public static final List<String> SERVER_COLUMNS = List.of("In", "Out");
|
||||
|
||||
private static final Pattern BUILD = Pattern.compile("^(.*?)\\s*\\[Build: (\\d+)]\\s*$");
|
||||
private static final DateTimeFormatter BUILD_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static final String QUOTA_TAB = "Quota";
|
||||
public static final String VOICE_TAB = "Voice received";
|
||||
|
||||
@@ -112,6 +123,50 @@ public final class ConnectionStatsFormat {
|
||||
new Row("Remaining " + direction + " this month:", remaining));
|
||||
}
|
||||
|
||||
/** The server window's facts; {@code s} is {@link ServerStats#UNKNOWN} while loading. */
|
||||
public static List<Row> serverSummaryRows(ServerModel model, String address, ServerStats s) {
|
||||
return List.of(
|
||||
new Row("Name", model.getServerName()),
|
||||
new Row("Version", versionWithBuildDate(model.serverProperty("virtualserver_version"))),
|
||||
new Row("Platform", orUnknown(model.serverProperty("virtualserver_platform"))),
|
||||
new Row("Uptime", uptime(s.uptimeSeconds())),
|
||||
new Row("Address", address),
|
||||
new Row("Average ping", s.pingMs() < 0 ? UNKNOWN : Math.round(s.pingMs()) + " ms"),
|
||||
new Row("Average packetloss", loss(s.packetLoss())));
|
||||
}
|
||||
|
||||
/** The server window's table, under {@link #SERVER_COLUMNS}; {@code total} is left empty. */
|
||||
public static List<TrafficRow> serverTrafficRows(ServerStats s) {
|
||||
return List.of(
|
||||
new TrafficRow("Packets transferred", "", count(s.packetsIn()), count(s.packetsOut())),
|
||||
new TrafficRow("Bytes transferred", "", ByteSize.format(s.bytesIn()), ByteSize.format(s.bytesOut())),
|
||||
new TrafficRow("Bandwidth last second", "",
|
||||
ByteSize.rate(s.bandwidthInLastSecond()), ByteSize.rate(s.bandwidthOutLastSecond())),
|
||||
new TrafficRow("Bandwidth last minute", "",
|
||||
ByteSize.rate(s.bandwidthInLastMinute()), ByteSize.rate(s.bandwidthOutLastMinute())),
|
||||
new TrafficRow("File transfer bandwidth", "",
|
||||
ByteSize.rate(s.fileTransferBandwidthIn()), ByteSize.rate(s.fileTransferBandwidthOut())),
|
||||
new TrafficRow("File transfer bytes transferred", "",
|
||||
ByteSize.format(s.fileTransferBytesIn()), ByteSize.format(s.fileTransferBytesOut())));
|
||||
}
|
||||
|
||||
/** {@code 3.13.7 [Build: 1655727713]} as {@code 3.13.7 (2022-06-20 12:21:53)}, the build being its time. */
|
||||
public static String versionWithBuildDate(String version) {
|
||||
if (version == null || version.isBlank()) return UNKNOWN;
|
||||
Matcher m = BUILD.matcher(version);
|
||||
if (!m.matches()) return version;
|
||||
try {
|
||||
Instant built = Instant.ofEpochSecond(Long.parseLong(m.group(2)));
|
||||
return m.group(1) + " (" + BUILD_DATE.format(built.atZone(ZoneId.systemDefault())) + ")";
|
||||
} catch (RuntimeException e) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
private static String orUnknown(String value) {
|
||||
return value == null || value.isBlank() ? UNKNOWN : value;
|
||||
}
|
||||
|
||||
/** The voice our playback received; every value is a dash when nothing was heard. */
|
||||
public static List<Row> voiceRows(VoiceReceiveStats v) {
|
||||
VoiceReceiveStats s = v == null ? VoiceReceiveStats.NONE : v;
|
||||
@@ -158,6 +213,15 @@ public final class ConnectionStatsFormat {
|
||||
return count(n) + " (" + new DecimalFormat("0.0").format(100.0 * n / of) + " %)";
|
||||
}
|
||||
|
||||
/** {@code 0 hours 3 minutes 55 seconds}, with days in front from a day on. */
|
||||
public static String uptime(long seconds) {
|
||||
if (seconds < 0) return UNKNOWN;
|
||||
long days = seconds / 86400;
|
||||
String rest = (seconds % 86400) / 3600 + " hours " + (seconds % 3600) / 60 + " minutes "
|
||||
+ seconds % 60 + " seconds";
|
||||
return days > 0 ? days + " days " + rest : rest;
|
||||
}
|
||||
|
||||
/** {@code 04:34}, or {@code 15:35:17} from an hour on. */
|
||||
public static String duration(long ms) {
|
||||
if (ms < 0) return UNKNOWN;
|
||||
|
||||
@@ -157,6 +157,10 @@ public final class Permissions {
|
||||
return permits("b_virtualserver_log_view");
|
||||
}
|
||||
|
||||
public boolean canViewServerConnectionInfo() {
|
||||
return permits("b_virtualserver_connectioninfo_view");
|
||||
}
|
||||
|
||||
public boolean canListPrivilegeKeys() {
|
||||
return permits("b_virtualserver_token_list");
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public final class ServerModel {
|
||||
private int defaultChannelGroupId;
|
||||
/** The channel new clients land in, and kicked ones go back to; 0 until the server names it. */
|
||||
private int defaultChannelId;
|
||||
/** Whether {@link #buildTree} lists ServerQuery clients; a view setting, so kept by {@link #clear}. */
|
||||
private boolean showQueryClients;
|
||||
|
||||
public synchronized void clear() {
|
||||
channels.clear();
|
||||
@@ -458,7 +460,7 @@ public final class ServerModel {
|
||||
}
|
||||
}
|
||||
for (ClientEntry cl : clients.values()) {
|
||||
if (cl.isQuery()) continue; // hide server-query clients from the tree
|
||||
if (cl.isQuery() && !showQueryClients) continue;
|
||||
if (channels.containsKey(cl.channelId)) {
|
||||
inside.computeIfAbsent(cl.channelId, id -> new ArrayList<>()).add(cl);
|
||||
}
|
||||
@@ -507,6 +509,14 @@ public final class ServerModel {
|
||||
siblings.addAll(ordered);
|
||||
}
|
||||
|
||||
public synchronized boolean showsQueryClients() {
|
||||
return showQueryClients;
|
||||
}
|
||||
|
||||
public synchronized void setShowQueryClients(boolean show) {
|
||||
showQueryClients = show;
|
||||
}
|
||||
|
||||
public synchronized int channelCount() {
|
||||
return channels.size();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package eu.lixko.ts3j.client.net;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The virtual server's connection figures, from {@code notifyserverconnectioninfo}: everything
|
||||
* it exchanged with all its clients. Seen from the server, as the official window shows them:
|
||||
* <em>in</em> is what it received, <em>out</em> what it sent. Unreported values are {@code -1}.
|
||||
*
|
||||
* @param packetLoss a fraction 0..1
|
||||
*/
|
||||
public record ServerStats(long uptimeSeconds, double pingMs, double packetLoss,
|
||||
long packetsIn, long packetsOut, long bytesIn, long bytesOut,
|
||||
long bandwidthInLastSecond, long bandwidthOutLastSecond,
|
||||
long bandwidthInLastMinute, long bandwidthOutLastMinute,
|
||||
long fileTransferBandwidthIn, long fileTransferBandwidthOut,
|
||||
long fileTransferBytesIn, long fileTransferBytesOut) {
|
||||
|
||||
/** Nothing known yet. */
|
||||
public static final ServerStats UNKNOWN = parse(Map.of());
|
||||
|
||||
static ServerStats parse(Map<String, String> m) {
|
||||
return new ServerStats(
|
||||
number(m, "connection_connected_time"),
|
||||
decimal(m, "connection_ping"),
|
||||
decimal(m, "connection_packetloss_total"),
|
||||
number(m, "connection_packets_received_total"),
|
||||
number(m, "connection_packets_sent_total"),
|
||||
number(m, "connection_bytes_received_total"),
|
||||
number(m, "connection_bytes_sent_total"),
|
||||
number(m, "connection_bandwidth_received_last_second_total"),
|
||||
number(m, "connection_bandwidth_sent_last_second_total"),
|
||||
number(m, "connection_bandwidth_received_last_minute_total"),
|
||||
number(m, "connection_bandwidth_sent_last_minute_total"),
|
||||
number(m, "connection_filetransfer_bandwidth_received"),
|
||||
number(m, "connection_filetransfer_bandwidth_sent"),
|
||||
number(m, "connection_filetransfer_bytes_received_total"),
|
||||
number(m, "connection_filetransfer_bytes_sent_total"));
|
||||
}
|
||||
|
||||
private static long number(Map<String, String> m, String key) {
|
||||
String v = m.get(key);
|
||||
if (v == null) return -1;
|
||||
try {
|
||||
return Long.parseLong(v.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static double decimal(Map<String, String> m, String key) {
|
||||
String v = m.get(key);
|
||||
if (v == null) return -1;
|
||||
try {
|
||||
return Double.parseDouble(v.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package eu.lixko.ts3j.client.net;
|
||||
|
||||
import com.github.manevolent.ts3j.command.SingleCommand;
|
||||
import com.github.manevolent.ts3j.event.UnknownTeamspeakEvent;
|
||||
import com.github.manevolent.ts3j.protocol.ProtocolRole;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Asks for the virtual server's connection figures with {@code serverrequestconnectioninfo},
|
||||
* which the server answers with a {@code notifyserverconnectioninfo} ahead of the command's
|
||||
* result. Needs {@code b_virtualserver_connectioninfo_view}.
|
||||
*
|
||||
* <p>Requests run in the background and fail with a {@link RequestException}.
|
||||
*/
|
||||
public final class ServerStatsAdmin {
|
||||
|
||||
private final Uplink uplink;
|
||||
private volatile ServerStats latest;
|
||||
|
||||
ServerStatsAdmin(Uplink uplink) {
|
||||
this.uplink = uplink;
|
||||
}
|
||||
|
||||
public CompletableFuture<ServerStats> read() {
|
||||
return uplink.request(() -> {
|
||||
synchronized (this) {
|
||||
latest = null;
|
||||
uplink.socket().executeCommand(new SingleCommand("serverrequestconnectioninfo", ProtocolRole.CLIENT))
|
||||
.complete();
|
||||
uplink.awaitEventsProcessed();
|
||||
ServerStats stats = latest;
|
||||
return stats == null ? ServerStats.UNKNOWN : stats;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onReport(UnknownTeamspeakEvent e) {
|
||||
latest = ServerStats.parse(e.getMap());
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ public final class TeamspeakConnection {
|
||||
final PrivilegeKeyAdmin privilegeKeys = new PrivilegeKeyAdmin(uplink);
|
||||
final ComplaintAdmin complaints;
|
||||
final ServerLogAdmin serverLog = new ServerLogAdmin(uplink);
|
||||
final ServerStatsAdmin serverStats = new ServerStatsAdmin(uplink);
|
||||
final OfflineMessageAdmin offlineMessages;
|
||||
private final AvatarAdmin avatarAdmin;
|
||||
/** Ourselves: devices and status flags; package-private for {@link ConnectionEventHandler}. */
|
||||
@@ -94,6 +95,8 @@ public final class TeamspeakConnection {
|
||||
*/
|
||||
/** The client whose whisper we heard last, to reply to; 0 for none yet. */
|
||||
private volatile int lastWhisperer;
|
||||
/** Whether incoming whispers go unheard, whoever sends them; kept across reconnects. */
|
||||
private volatile boolean whispersBlocked;
|
||||
private volatile LocalIdentity identity;
|
||||
/**
|
||||
* The connect in progress. A disconnect clears it and a newer connect replaces it, which
|
||||
@@ -282,7 +285,7 @@ public final class TeamspeakConnection {
|
||||
client.addListener(events);
|
||||
client.setVoiceHandler(playback::handleVoice);
|
||||
client.setWhisperHandler(whisper -> {
|
||||
if (!contacts.isWhisperAllowed(whisper.getClientId())) return;
|
||||
if (whispersBlocked || !contacts.isWhisperAllowed(whisper.getClientId())) return;
|
||||
lastWhisperer = whisper.getClientId();
|
||||
playback.handleWhisper(whisper);
|
||||
});
|
||||
@@ -643,6 +646,10 @@ public final class TeamspeakConnection {
|
||||
return serverLog;
|
||||
}
|
||||
|
||||
public ServerStatsAdmin serverStats() {
|
||||
return serverStats;
|
||||
}
|
||||
|
||||
/** Our offline message inbox, sending offline messages and finding their recipients. */
|
||||
public OfflineMessageAdmin offlineMessages() {
|
||||
return offlineMessages;
|
||||
@@ -745,6 +752,14 @@ public final class TeamspeakConnection {
|
||||
sock.setWhisperTarget(target);
|
||||
}
|
||||
|
||||
public boolean areWhispersBlocked() {
|
||||
return whispersBlocked;
|
||||
}
|
||||
|
||||
public void setWhispersBlocked(boolean blocked) {
|
||||
whispersBlocked = blocked;
|
||||
}
|
||||
|
||||
/** The client who whispered to us last, if still on the server. */
|
||||
public ClientEntry lastWhisperer() {
|
||||
int id = lastWhisperer;
|
||||
|
||||
@@ -38,6 +38,7 @@ import eu.lixko.ts3j.client.net.PrivilegeKeyAdmin;
|
||||
import eu.lixko.ts3j.client.net.Recording;
|
||||
import eu.lixko.ts3j.client.net.Replies;
|
||||
import eu.lixko.ts3j.client.net.ServerLogAdmin;
|
||||
import eu.lixko.ts3j.client.net.ServerStatsAdmin;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.net.Whisper;
|
||||
import eu.lixko.ts3j.client.recording.VoiceRecorder;
|
||||
@@ -198,6 +199,16 @@ public final class ServerSession {
|
||||
return conn.getModel();
|
||||
}
|
||||
|
||||
public boolean showsQueryClients() {
|
||||
return conn.getModel().showsQueryClients();
|
||||
}
|
||||
|
||||
/** Lists the server's ServerQuery clients in the tree too, or hides them again. */
|
||||
public void setShowQueryClients(boolean show) {
|
||||
conn.getModel().setShowQueryClients(show);
|
||||
listener.onModelChanged();
|
||||
}
|
||||
|
||||
/** Our client id on the server, or -1 while not connected. */
|
||||
public int selfClientId() {
|
||||
return conn.getSelfClientId();
|
||||
@@ -590,6 +601,16 @@ public final class ServerSession {
|
||||
return whisper != null && targets != null && targets.isEmpty();
|
||||
}
|
||||
|
||||
/** Whether incoming whispers are blocked here, whatever the contacts allow. */
|
||||
public boolean areWhispersBlocked() {
|
||||
return conn.areWhispersBlocked();
|
||||
}
|
||||
|
||||
public void setWhispersBlocked(boolean blocked) {
|
||||
conn.setWhispersBlocked(blocked);
|
||||
listener.onSessionChanged();
|
||||
}
|
||||
|
||||
/** The client who whispered to us last, to whisper back to; null when none is on. */
|
||||
public ClientEntry lastWhisperer() {
|
||||
return conn.isConnected() ? conn.lastWhisperer() : null;
|
||||
@@ -850,6 +871,10 @@ public final class ServerSession {
|
||||
return conn.serverLog();
|
||||
}
|
||||
|
||||
public ServerStatsAdmin serverStats() {
|
||||
return conn.serverStats();
|
||||
}
|
||||
|
||||
public OfflineMessageAdmin offlineMessages() {
|
||||
return conn.offlineMessages();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user