3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +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.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;

Datei anzeigen

@ -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(