Bug fixed
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>dev.unlegitdqrk</groupId>
|
<groupId>dev.unlegitdqrk</groupId>
|
||||||
<artifactId>unlegitlibrary</artifactId>
|
<artifactId>unlegitlibrary</artifactId>
|
||||||
<version>1.8.0</version>
|
<version>1.8.1</version>
|
||||||
<url>https://unlegitdqrk.dev/</url>
|
<url>https://unlegitdqrk.dev/</url>
|
||||||
<description>Just a big library</description>
|
<description>Just a big library</description>
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ public class ConnectedClient {
|
|||||||
try { if (tcpSocket != null) tcpSocket.close(); } catch (IOException ignored) {}
|
try { if (tcpSocket != null) tcpSocket.close(); } catch (IOException ignored) {}
|
||||||
try { if (inputStream != null) inputStream.close(); } catch (IOException ignored) {}
|
try { if (inputStream != null) inputStream.close(); } catch (IOException ignored) {}
|
||||||
try { if (outputStream != null) outputStream.close(); } catch (IOException ignored) {}
|
try { if (outputStream != null) outputStream.close(); } catch (IOException ignored) {}
|
||||||
try { if (udpChannel != null) udpChannel.close(); } catch (IOException ignored) {}
|
|
||||||
|
|
||||||
tcpSocket = null;
|
tcpSocket = null;
|
||||||
udpChannel = null;
|
udpChannel = null;
|
||||||
|
|||||||
@@ -209,39 +209,45 @@ public class NetworkServer {
|
|||||||
|
|
||||||
private void udpReceiveLoop() {
|
private void udpReceiveLoop() {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(65536);
|
ByteBuffer buffer = ByteBuffer.allocate(65536);
|
||||||
|
|
||||||
while (!Thread.currentThread().isInterrupted()) {
|
while (!Thread.currentThread().isInterrupted()) {
|
||||||
try {
|
try {
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
SocketAddress sender = udpChannel.receive(buffer);
|
SocketAddress sender = udpChannel.receive(buffer);
|
||||||
if (sender == null) continue;
|
if (sender == null) continue;
|
||||||
|
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
if (buffer.remaining() < 13) continue; // 12-byte IV + at least 1 byte payload
|
if (buffer.remaining() < 13) continue;
|
||||||
|
|
||||||
UUID mappedUuid = clientUdpAddresses.get(sender);
|
UUID mappedUuid = clientUdpAddresses.get(sender);
|
||||||
if (mappedUuid != null) {
|
if (mappedUuid != null) {
|
||||||
ConnectedClient mappedClient = getClientByUuid(mappedUuid);
|
ConnectedClient mappedClient = getClientByUuid(mappedUuid);
|
||||||
if (mappedClient != null) {
|
if (mappedClient != null && tryHandleUdpPacket(mappedClient, sender, buffer.asReadOnlyBuffer())) {
|
||||||
if (tryHandleUdpPacket(mappedClient, sender, buffer.asReadOnlyBuffer())) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: try all clients if mapping missing or decrypt failed (e.g., NAT rebinding)
|
|
||||||
List<ConnectedClient> snapshot;
|
List<ConnectedClient> snapshot;
|
||||||
synchronized (connectedClients) {
|
synchronized (connectedClients) {
|
||||||
snapshot = new ArrayList<>(connectedClients);
|
snapshot = new ArrayList<>(connectedClients);
|
||||||
}
|
}
|
||||||
for (ConnectedClient client : snapshot) {
|
for (ConnectedClient client : snapshot) {
|
||||||
if (tryHandleUdpPacket(client, sender, buffer.asReadOnlyBuffer())) {
|
if (tryHandleUdpPacket(client, sender, buffer.asReadOnlyBuffer())) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (java.nio.channels.ClosedChannelException e) {
|
||||||
|
// Expected on shutdown / close from another thread.
|
||||||
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (tcpSocket != null) {
|
// Not fatal for TCP. Keep UDP loop alive unless channel is actually closed.
|
||||||
try { tcpSocket.close(); } catch (IOException ignored) {}
|
if (udpChannel == null || !udpChannel.isOpen() || Thread.currentThread().isInterrupted()) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
e.printStackTrace();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(50);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user