3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 23:30:26 +01:00

Correctly implement status protocol specification according to vanilla.

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-08-20 15:03:33 -04:00
Ursprung b2000652ca
Commit 1d4da8c32d
2 geänderte Dateien mit 12 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.packet.Handshake;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
@ -156,11 +157,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
if (cause instanceof ReadTimeoutException) { if (cause instanceof ReadTimeoutException) {
logger.error("{}: read timed out", association); logger.error("{}: read timed out", association);
} else { } else {
boolean frontlineHandler = sessionHandler instanceof LoginSessionHandler
|| sessionHandler instanceof HandshakeSessionHandler
|| sessionHandler instanceof StatusSessionHandler;
boolean isQuietDecoderException = cause instanceof QuietDecoderException; boolean isQuietDecoderException = cause instanceof QuietDecoderException;
boolean willLogQuietDecoderException = !isQuietDecoderException boolean willLog = !isQuietDecoderException && !frontlineHandler;
|| (!(sessionHandler instanceof LoginSessionHandler) if (willLog) {
&& !(sessionHandler instanceof HandshakeSessionHandler));
if (willLogQuietDecoderException) {
logger.error("{}: exception encountered in {}", association, sessionHandler, cause); logger.error("{}: exception encountered in {}", association, sessionHandler, cause);
} else { } else {
knownDisconnect = true; knownDisconnect = true;

Datei anzeigen

@ -34,20 +34,17 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class); private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class);
private static final QuietRuntimeException EXPECTED_AWAITING_REQUEST = new QuietRuntimeException( private static final QuietRuntimeException EXPECTED_AWAITING_REQUEST = new QuietRuntimeException(
"Expected connection to be awaiting status request"); "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 VelocityServer server;
private final MinecraftConnection connection; private final MinecraftConnection connection;
private final InboundConnection inbound; private final InboundConnection inbound;
private State state; private boolean pingReceived = false;
StatusSessionHandler(VelocityServer server, MinecraftConnection connection, StatusSessionHandler(VelocityServer server, MinecraftConnection connection,
InboundConnection inbound) { InboundConnection inbound) {
this.server = server; this.server = server;
this.connection = connection; this.connection = connection;
this.inbound = inbound; this.inbound = inbound;
this.state = State.AWAITING_REQUEST;
} }
@Override @Override
@ -158,10 +155,10 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(LegacyPing packet) { public boolean handle(LegacyPing packet) {
if (this.state != State.AWAITING_REQUEST) { if (this.pingReceived) {
throw EXPECTED_AWAITING_REQUEST; throw EXPECTED_AWAITING_REQUEST;
} }
this.state = State.RECEIVED_REQUEST; this.pingReceived = true;
getInitialPing() getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {
@ -173,19 +170,17 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(StatusPing packet) { public boolean handle(StatusPing packet) {
if (this.state != State.RECEIVED_REQUEST) {
throw EXPECTED_RECEIVED_REQUEST;
}
connection.closeWith(packet); connection.closeWith(packet);
return true; return true;
} }
@Override @Override
public boolean handle(StatusRequest packet) { public boolean handle(StatusRequest packet) {
if (this.state != State.AWAITING_REQUEST) { if (this.pingReceived) {
throw EXPECTED_AWAITING_REQUEST; throw EXPECTED_AWAITING_REQUEST;
} }
this.state = State.RECEIVED_REQUEST; this.pingReceived = true;
getInitialPing() getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync( .thenAcceptAsync(