From 1d4da8c32df5b22221639e245000a188dfdcaec7 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 20 Aug 2020 15:03:33 -0400 Subject: [PATCH] Correctly implement status protocol specification according to vanilla. --- .../proxy/connection/MinecraftConnection.java | 10 ++++++---- .../connection/client/StatusSessionHandler.java | 17 ++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 70de89673..d9210e636 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -27,6 +27,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; +import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; @@ -156,11 +157,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { if (cause instanceof ReadTimeoutException) { logger.error("{}: read timed out", association); } else { + boolean frontlineHandler = sessionHandler instanceof LoginSessionHandler + || sessionHandler instanceof HandshakeSessionHandler + || sessionHandler instanceof StatusSessionHandler; boolean isQuietDecoderException = cause instanceof QuietDecoderException; - boolean willLogQuietDecoderException = !isQuietDecoderException - || (!(sessionHandler instanceof LoginSessionHandler) - && !(sessionHandler instanceof HandshakeSessionHandler)); - if (willLogQuietDecoderException) { + boolean willLog = !isQuietDecoderException && !frontlineHandler; + if (willLog) { logger.error("{}: exception encountered in {}", association, sessionHandler, cause); } else { knownDisconnect = true; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index a1d14ad28..ba9baaa2b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -34,20 +34,17 @@ public class StatusSessionHandler implements MinecraftSessionHandler { private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class); private static final QuietRuntimeException EXPECTED_AWAITING_REQUEST = new QuietRuntimeException( "Expected connection to be awaiting status request"); - private static final QuietRuntimeException EXPECTED_RECEIVED_REQUEST = new QuietRuntimeException( - "Expected connection to be awaiting ping"); private final VelocityServer server; private final MinecraftConnection connection; private final InboundConnection inbound; - private State state; + private boolean pingReceived = false; StatusSessionHandler(VelocityServer server, MinecraftConnection connection, InboundConnection inbound) { this.server = server; this.connection = connection; this.inbound = inbound; - this.state = State.AWAITING_REQUEST; } @Override @@ -158,10 +155,10 @@ public class StatusSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(LegacyPing packet) { - if (this.state != State.AWAITING_REQUEST) { + if (this.pingReceived) { throw EXPECTED_AWAITING_REQUEST; } - this.state = State.RECEIVED_REQUEST; + this.pingReceived = true; getInitialPing() .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenAcceptAsync(event -> { @@ -173,19 +170,17 @@ public class StatusSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(StatusPing packet) { - if (this.state != State.RECEIVED_REQUEST) { - throw EXPECTED_RECEIVED_REQUEST; - } connection.closeWith(packet); return true; } @Override public boolean handle(StatusRequest packet) { - if (this.state != State.AWAITING_REQUEST) { + if (this.pingReceived) { throw EXPECTED_AWAITING_REQUEST; } - this.state = State.RECEIVED_REQUEST; + this.pingReceived = true; + getInitialPing() .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenAcceptAsync(