This commit is contained in:
TheMode 2021-08-08 23:03:01 +02:00
parent 3881102925
commit 1b79d2e2e8
2 changed files with 17 additions and 16 deletions

View File

@ -89,7 +89,8 @@ public class PlayerSocketConnection extends PlayerConnection {
try {
cipher.update(bytes, 0, remainingBytes, output, 0);
} catch (ShortBufferException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return;
}
readBuffer.clear();
readBuffer.writeBytes(output);
@ -134,14 +135,14 @@ public class PlayerSocketConnection extends PlayerConnection {
// Process packet
final int packetId = content.readVarInt();
try {
var finalBuffer = content.asByteBuffer(content.readerOffset(), packetEnd);
packetProcessor.process(this, packetId, finalBuffer);
final ByteBuffer payload = content.asByteBuffer(content.readerOffset(), packetEnd);
packetProcessor.process(this, packetId, payload);
} catch (Exception e) {
// Error while reading the packet
MinecraftServer.getExceptionManager().handleException(e);
break;
}
// Return to original state (before writing)
// Position buffer to read the next packet
readBuffer.reset(packetEnd, limit);
} catch (BufferUnderflowException e) {
readBuffer.reset(beginMark);

View File

@ -61,17 +61,6 @@ public final class Worker extends Thread {
}
}
public void receiveConnection(SocketChannel channel) throws IOException {
this.connectionMap.put(channel, new PlayerSocketConnection(this, channel, channel.getRemoteAddress()));
channel.configureBlocking(false);
channel.register(selector, SelectionKey.OP_READ);
var socket = channel.socket();
socket.setSendBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setTcpNoDelay(Server.NO_DELAY);
this.selector.wakeup();
}
public void disconnect(PlayerSocketConnection connection, SocketChannel channel) {
try {
channel.close();
@ -87,6 +76,17 @@ public final class Worker extends Thread {
}
}
void receiveConnection(SocketChannel channel) throws IOException {
this.connectionMap.put(channel, new PlayerSocketConnection(this, channel, channel.getRemoteAddress()));
channel.configureBlocking(false);
channel.register(selector, SelectionKey.OP_READ);
var socket = channel.socket();
socket.setSendBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(Server.SOCKET_BUFFER_SIZE);
socket.setTcpNoDelay(Server.NO_DELAY);
this.selector.wakeup();
}
/**
* Contains objects that we can be shared across all the connection of a {@link Worker worker}.
*/
@ -95,7 +95,7 @@ public final class Worker extends Thread {
public final BinaryBuffer contentBuffer = BinaryBuffer.ofSize(Server.MAX_PACKET_SIZE);
public final Inflater inflater = new Inflater();
public void clearBuffers() {
void clearBuffers() {
this.readBuffer.clear();
this.contentBuffer.clear();
}