Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-08-03 13:09:03 +02:00
parent 1c3bb5b0ff
commit b35954c05d
4 changed files with 14 additions and 15 deletions

View File

@ -4,10 +4,8 @@ import net.minestom.server.network.packet.client.status.PingPacket;
import net.minestom.server.network.packet.client.status.StatusRequestPacket; import net.minestom.server.network.packet.client.status.StatusRequestPacket;
public class ClientStatusPacketsHandler extends ClientPacketsHandler { public class ClientStatusPacketsHandler extends ClientPacketsHandler {
public ClientStatusPacketsHandler() { public ClientStatusPacketsHandler() {
register(0x00, StatusRequestPacket::new); register(0x00, StatusRequestPacket::new);
register(0x01, PingPacket::new); register(0x01, PingPacket::new);
} }
} }

View File

@ -16,12 +16,8 @@ public class StatusRequestPacket implements ClientPreplayPacket {
public void process(@NotNull PlayerConnection connection) { public void process(@NotNull PlayerConnection connection) {
final ServerListPingType pingVersion = ServerListPingType.fromModernProtocolVersion(connection.getProtocolVersion()); final ServerListPingType pingVersion = ServerListPingType.fromModernProtocolVersion(connection.getProtocolVersion());
final ServerListPingEvent statusRequestEvent = new ServerListPingEvent(connection, pingVersion); final ServerListPingEvent statusRequestEvent = new ServerListPingEvent(connection, pingVersion);
EventDispatcher.callCancellable(statusRequestEvent, () -> { EventDispatcher.callCancellable(statusRequestEvent, () ->
final ResponsePacket responsePacket = new ResponsePacket(); connection.sendPacket(new ResponsePacket(pingVersion.getPingResponse(statusRequestEvent.getResponseData()))));
responsePacket.jsonResponse = pingVersion.getPingResponse(statusRequestEvent.getResponseData());
connection.sendPacket(responsePacket);
});
} }
@Override @Override

View File

@ -7,7 +7,11 @@ import org.jetbrains.annotations.NotNull;
public class ResponsePacket implements ServerPacket { public class ResponsePacket implements ServerPacket {
public String jsonResponse = ""; public String jsonResponse;
public ResponsePacket(String jsonResponse) {
this.jsonResponse = jsonResponse;
}
@Override @Override
public void write(@NotNull BinaryWriter writer) { public void write(@NotNull BinaryWriter writer) {

View File

@ -228,12 +228,13 @@ public class NettyPlayerConnection extends PlayerConnection {
} }
public void attemptWrite(ByteBuffer buffer) { public void attemptWrite(ByteBuffer buffer) {
buffer.flip();
synchronized (tickBufferLock) { synchronized (tickBufferLock) {
try { try {
this.tickBuffer.put(buffer); this.tickBuffer.put(buffer);
} catch (BufferOverflowException e) { } catch (BufferOverflowException e) {
try { try {
this.channel.write(tickBuffer); this.channel.write(tickBuffer.flip());
this.channel.write(buffer); this.channel.write(buffer);
} catch (IOException ex) { } catch (IOException ex) {
MinecraftServer.getExceptionManager().handleException(ex); MinecraftServer.getExceptionManager().handleException(ex);
@ -245,12 +246,12 @@ public class NettyPlayerConnection extends PlayerConnection {
} }
public void flush() { public void flush() {
if (tickBuffer.remaining() == 0) {
// Nothing to write
return;
}
// Retrieve safe copy
synchronized (tickBufferLock) { synchronized (tickBufferLock) {
this.tickBuffer.flip();
if (tickBuffer.remaining() == 0) {
// Nothing to write
return;
}
try { try {
channel.write(tickBuffer); channel.write(tickBuffer);
} catch (IOException e) { } catch (IOException e) {