latestPacketId exposure for the same reason as the last commit

This commit is contained in:
Manevolent
2018-08-16 13:44:43 -04:00
parent 3898f2658c
commit 0cd72622a2
2 changed files with 31 additions and 10 deletions
@@ -1040,6 +1040,8 @@ public abstract class AbstractTeamspeakClientSocket
*/ */
int getCurrentGeneration(); int getCurrentGeneration();
int getCurrentPacketId();
/** /**
* Counts the given packet by its packet ID and stores it in history. * Counts the given packet by its packet ID and stores it in history.
* *
@@ -1063,6 +1065,11 @@ public abstract class AbstractTeamspeakClientSocket
return 0; return 0;
} }
@Override
public int getCurrentPacketId() {
return 0;
}
@Override @Override
public boolean put(int packetId) { public boolean put(int packetId) {
return true; 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 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 bufferEnd; // position of the end of the buffer in the window
private int latestPacketId = 0;
/** /**
* Constructs a new full counter * Constructs a new full counter
* *
@@ -1144,12 +1153,19 @@ public abstract class AbstractTeamspeakClientSocket
return bufferEnd.getKey(); return bufferEnd.getKey();
} }
@Override
public int getCurrentPacketId() {
return latestPacketId;
}
@Override @Override
public boolean put(int packetId) { public boolean put(int packetId) {
// find if right of the start and within the start's bounds // find if right of the start and within the start's bounds
if (packetId >= bufferStart.getValue() if (packetId >= bufferStart.getValue()
&& packetId < bufferStart.getValue() + bufferSize && packetId < bufferStart.getValue() + bufferSize
&& packetId < generationSize) { && packetId < generationSize) {
latestPacketId = Math.max(latestPacketId, packetId);
return putRelative(packetId - bufferStart.getValue(), bufferStart.getKey()); return putRelative(packetId - bufferStart.getValue(), bufferStart.getKey());
} }
@@ -1158,6 +1174,8 @@ public abstract class AbstractTeamspeakClientSocket
&& packetId >= 0 && packetId >= 0
&& packetId > bufferEnd.getValue() - bufferSize && packetId > bufferEnd.getValue() - bufferSize
&& packetId < generationSize) { && packetId < generationSize) {
latestPacketId = Math.max(latestPacketId, packetId);
return putRelative(bufferSize - (bufferEnd.getValue() - packetId) - 1, bufferEnd.getKey()); return putRelative(bufferSize - (bufferEnd.getValue() - packetId) - 1, bufferEnd.getKey());
} }
@@ -1198,9 +1216,9 @@ public abstract class AbstractTeamspeakClientSocket
int bufferEndGeneration; int bufferEndGeneration;
int bufferEndPosition = (bufferStartPosition + bufferSize - 1) % generationSize; int bufferEndPosition = (bufferStartPosition + bufferSize - 1) % generationSize;
if (bufferEndPosition < bufferStartPosition) if (bufferEndPosition < bufferStartPosition) {
bufferEndGeneration = bufferStartGeneration + 1; bufferEndGeneration = bufferStartGeneration + 1;
else } else
bufferEndGeneration = bufferStartGeneration; bufferEndGeneration = bufferStartGeneration;
this.bufferStart = new Pair<>(bufferStartGeneration, bufferStartPosition); this.bufferStart = new Pair<>(bufferStartGeneration, bufferStartPosition);
@@ -1209,6 +1227,8 @@ public abstract class AbstractTeamspeakClientSocket
throw new IllegalStateException(); throw new IllegalStateException();
// if we had to adjust the buffer size, recursively retry put // if we had to adjust the buffer size, recursively retry put
this.latestPacketId = packetId;
return put(packetId); return put(packetId);
} }
@@ -6,12 +6,14 @@ import com.github.manevolent.ts3j.enums.CodecType;
import com.github.manevolent.ts3j.event.*; import com.github.manevolent.ts3j.event.*;
import com.github.manevolent.ts3j.identity.LocalIdentity; import com.github.manevolent.ts3j.identity.LocalIdentity;
import com.github.manevolent.ts3j.protocol.client.ClientConnectionState; 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.protocol.socket.client.LocalTeamspeakClientSocket;
import com.github.manevolent.ts3j.util.Ts3Debugging; import com.github.manevolent.ts3j.util.Ts3Debugging;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Base64; import java.util.Base64;
import java.util.function.Consumer;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -51,7 +53,7 @@ public class ServerConnectionTest {
@Override @Override
public void onClientJoin(ClientJoinEvent e) { public void onClientJoin(ClientJoinEvent e) {
System.err.println(e.get("cid"));
} }
@Override @Override
@@ -150,13 +152,12 @@ public class ServerConnectionTest {
client.subscribeAll(); client.subscribeAll();
try { try {
client.setVoiceHandler(packetBody0Voice -> {
while (client.isConnected()) { System.err.println("clientId=" + packetBody0Voice.getClientId());
for (Client c : client.listClients()) { System.err.println("packetId=" + packetBody0Voice.getPacketId());
client.getClientInfo(c.getId()); System.err.println("type=" + packetBody0Voice.getCodecType());
} System.err.println("len=" + packetBody0Voice.getCodecData().length);
} });
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }