diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/AbstractTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/AbstractTeamspeakClientSocket.java index 62aedf2..116d7d0 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/AbstractTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/AbstractTeamspeakClientSocket.java @@ -1040,6 +1040,8 @@ public abstract class AbstractTeamspeakClientSocket */ int getCurrentGeneration(); + int getCurrentPacketId(); + /** * Counts the given packet by its packet ID and stores it in history. * @@ -1063,6 +1065,11 @@ public abstract class AbstractTeamspeakClientSocket return 0; } + @Override + public int getCurrentPacketId() { + return 0; + } + @Override public boolean put(int packetId) { return true; @@ -1084,6 +1091,8 @@ public abstract class AbstractTeamspeakClientSocket bufferStart = new Pair<>(0,0), // position of the start of the buffer in the window bufferEnd; // position of the end of the buffer in the window + private int latestPacketId = 0; + /** * Constructs a new full counter * @@ -1144,12 +1153,19 @@ public abstract class AbstractTeamspeakClientSocket return bufferEnd.getKey(); } + @Override + public int getCurrentPacketId() { + return latestPacketId; + } + @Override public boolean put(int packetId) { // find if right of the start and within the start's bounds if (packetId >= bufferStart.getValue() && packetId < bufferStart.getValue() + bufferSize && packetId < generationSize) { + latestPacketId = Math.max(latestPacketId, packetId); + return putRelative(packetId - bufferStart.getValue(), bufferStart.getKey()); } @@ -1158,6 +1174,8 @@ public abstract class AbstractTeamspeakClientSocket && packetId >= 0 && packetId > bufferEnd.getValue() - bufferSize && packetId < generationSize) { + latestPacketId = Math.max(latestPacketId, packetId); + return putRelative(bufferSize - (bufferEnd.getValue() - packetId) - 1, bufferEnd.getKey()); } @@ -1198,9 +1216,9 @@ public abstract class AbstractTeamspeakClientSocket int bufferEndGeneration; int bufferEndPosition = (bufferStartPosition + bufferSize - 1) % generationSize; - if (bufferEndPosition < bufferStartPosition) + if (bufferEndPosition < bufferStartPosition) { bufferEndGeneration = bufferStartGeneration + 1; - else + } else bufferEndGeneration = bufferStartGeneration; this.bufferStart = new Pair<>(bufferStartGeneration, bufferStartPosition); @@ -1209,6 +1227,8 @@ public abstract class AbstractTeamspeakClientSocket throw new IllegalStateException(); // if we had to adjust the buffer size, recursively retry put + this.latestPacketId = packetId; + return put(packetId); } diff --git a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java index d0f15dc..c332d85 100644 --- a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java +++ b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java @@ -6,12 +6,14 @@ import com.github.manevolent.ts3j.enums.CodecType; import com.github.manevolent.ts3j.event.*; import com.github.manevolent.ts3j.identity.LocalIdentity; import com.github.manevolent.ts3j.protocol.client.ClientConnectionState; +import com.github.manevolent.ts3j.protocol.packet.PacketBody0Voice; import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket; import com.github.manevolent.ts3j.util.Ts3Debugging; import java.math.BigInteger; import java.net.InetSocketAddress; import java.util.Base64; +import java.util.function.Consumer; import static org.junit.Assert.assertEquals; @@ -51,7 +53,7 @@ public class ServerConnectionTest { @Override public void onClientJoin(ClientJoinEvent e) { - + System.err.println(e.get("cid")); } @Override @@ -150,13 +152,12 @@ public class ServerConnectionTest { client.subscribeAll(); try { - - while (client.isConnected()) { - for (Client c : client.listClients()) { - client.getClientInfo(c.getId()); - } - } - + client.setVoiceHandler(packetBody0Voice -> { + System.err.println("clientId=" + packetBody0Voice.getClientId()); + System.err.println("packetId=" + packetBody0Voice.getPacketId()); + System.err.println("type=" + packetBody0Voice.getCodecType()); + System.err.println("len=" + packetBody0Voice.getCodecData().length); + }); } catch (Exception ex) { ex.printStackTrace(); }