mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 17:37:42 +01:00
Fix ping
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
1c3bb5b0ff
commit
b35954c05d
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user