From a4ce0feb6120e1e78fd4917243ffb84d2ee6d531 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Tue, 6 Oct 2026 20:26:59 +0000 Subject: [PATCH] Report a minute's bandwidth as bytes per second setconnectioninfo sent the bytes of the whole last minute where the server expects the minute's average rate, so others saw our bandwidth 60 times too high. PacketStatistics gains the per-second averages, and the packets-last-minute count looked at the last second only. Co-Authored-By: Claude Opus 5.5 --- .../protocol/packet/statistics/PacketStatistics.java | 12 +++++++++++- .../socket/client/LocalTeamspeakClientSocket.java | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/packet/statistics/PacketStatistics.java b/src/main/java/com/github/manevolent/ts3j/protocol/packet/statistics/PacketStatistics.java index 7ef5291..8c71e1c 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/packet/statistics/PacketStatistics.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/packet/statistics/PacketStatistics.java @@ -61,7 +61,7 @@ public class PacketStatistics { } public int getSentPacketsLastMinute() { - long now = System.nanoTime() - 1_000_000_000L; + long now = System.nanoTime() - 60_000_000_000L; synchronized (sentPacketList) { return (int) sentPacketList.stream() @@ -124,6 +124,16 @@ public class PacketStatistics { } } + /** Average bytes per second sent over the last minute, as TeamSpeak reports a minute's bandwidth. */ + public int getSentBandwidthLastMinute() { + return getSentBytesLastMinute() / 60; + } + + /** Average bytes per second received over the last minute. */ + public int getReceivedBandwidthLastMinute() { + return getReceivedBytesLastMinute() / 60; + } + public int getReceivedBytesLastMinute() { long now = System.nanoTime() - 60_000_000_000L; diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index b8e0fca..7911e9e 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -150,11 +150,11 @@ public class LocalTeamspeakClientSocket response.add(new CommandSingleParameter("connection_bandwidth_sent_last_second_" + name, Integer.toString(stats.getSentBytesLastSecond()))); response.add(new CommandSingleParameter("connection_bandwidth_sent_last_minute_" + name, - Integer.toString(stats.getSentBytesLastMinute()))); + Integer.toString(stats.getSentBandwidthLastMinute()))); response.add(new CommandSingleParameter("connection_bandwidth_received_last_second_" + name, Integer.toString(stats.getReceivedBytesLastSecond()))); response.add(new CommandSingleParameter("connection_bandwidth_received_last_minute_" + name, - Integer.toString(stats.getReceivedBytesLastMinute()))); + Integer.toString(stats.getReceivedBandwidthLastMinute()))); } response.add(new CommandSingleParameter("connection_server2client_packetloss_total", Integer.toString(0)));