Add support for canceling ProxyPingEvent (#1264)

* Added support for canceling ProxyPingEvent
This commit is contained in:
Adrian
2024-06-08 14:28:33 -05:00
committed by GitHub
parent 46cf9be297
commit 2d015cdf5c
2 changed files with 65 additions and 12 deletions

View File

@@ -68,9 +68,13 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
this.pingReceived = true;
server.getServerListPingHandler().getInitialPing(this.inbound)
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(event -> connection.closeWith(
LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())),
connection.eventLoop())
.thenAcceptAsync(event -> {
if (event.getResult().isAllowed()) {
connection.closeWith(LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion()));
} else {
connection.close();
}
}, connection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling legacy ping {}", packet, ex);
return null;
@@ -95,10 +99,14 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(
(event) -> {
final StringBuilder json = new StringBuilder();
VelocityServer.getPingGsonInstance(connection.getProtocolVersion())
.toJson(event.getPing(), json);
connection.write(new StatusResponsePacket(json));
if (event.getResult().isAllowed()) {
final StringBuilder json = new StringBuilder();
VelocityServer.getPingGsonInstance(connection.getProtocolVersion())
.toJson(event.getPing(), json);
connection.write(new StatusResponsePacket(json));
} else {
connection.close();
}
},
connection.eventLoop())
.exceptionally((ex) -> {