3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Move handshake exceptions filter to exceptionCaught handling

Dieser Commit ist enthalten in:
KennyTV 2020-07-01 13:22:00 +02:00
Ursprung 96485c444e
Commit f16ff65933
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 47 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -3,11 +3,13 @@ package us.myles.ViaVersion.bukkit.handlers;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.bukkit.util.NMSUtil;
import us.myles.ViaVersion.exception.CancelCodecException; import us.myles.ViaVersion.exception.CancelCodecException;
import us.myles.ViaVersion.exception.CancelDecoderException; import us.myles.ViaVersion.exception.CancelDecoderException;
import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.exception.InformativeException;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -57,7 +59,8 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder {
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; // ProtocolLib compat if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; // ProtocolLib compat
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
if (!NMSUtil.isDebugPropertySet() && PipelineUtil.containsCause(cause, InformativeException.class)) { if (!NMSUtil.isDebugPropertySet() && PipelineUtil.containsCause(cause, InformativeException.class)
&& (info.getProtocolInfo().getState() != State.HANDSHAKE || Via.getManager().isDebug())) {
cause.printStackTrace(); // Print if CB doesn't already do it cause.printStackTrace(); // Print if CB doesn't already do it
} }
} }

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.bukkit.handlers;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.bukkit.util.NMSUtil;
import us.myles.ViaVersion.exception.CancelCodecException; import us.myles.ViaVersion.exception.CancelCodecException;
@ -10,6 +11,7 @@ import us.myles.ViaVersion.exception.CancelEncoderException;
import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.exception.InformativeException;
import us.myles.ViaVersion.handlers.ChannelHandlerContextWrapper; import us.myles.ViaVersion.handlers.ChannelHandlerContextWrapper;
import us.myles.ViaVersion.handlers.ViaHandler; import us.myles.ViaVersion.handlers.ViaHandler;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -69,7 +71,8 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaHand
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; // ProtocolLib compat if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; // ProtocolLib compat
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
if (!NMSUtil.isDebugPropertySet() && PipelineUtil.containsCause(cause, InformativeException.class)) { if (!NMSUtil.isDebugPropertySet() && PipelineUtil.containsCause(cause, InformativeException.class)
&& (info.getProtocolInfo().getState() != State.HANDSHAKE || Via.getManager().isDebug())) {
cause.printStackTrace(); // Print if CB doesn't already do it cause.printStackTrace(); // Print if CB doesn't already do it
} }
} }

Datei anzeigen

@ -418,7 +418,8 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
try { try {
protocolPacket.getRemapper().remap(packetWrapper); protocolPacket.getRemapper().remap(packetWrapper);
} catch (Exception e) { } catch (Exception e) {
if (e instanceof CancelException) { // Don't print cancelled packets or the handshake
if (e instanceof CancelException || state == State.HANDSHAKE) {
throw e; throw e;
} }

Datei anzeigen

@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.protocol.SimpleProtocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.Direction;
@ -27,23 +26,7 @@ public class BaseProtocol extends SimpleProtocol {
registerIncoming(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() { registerIncoming(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
try {
handleWithException(wrapper);
} catch (Exception e) {
// Only throw exceptions here when debug is enabled
// The handling has proven to be correct, but often receives invalid packets as the first packet of a connection
if (Via.getManager().isDebug()) {
throw e;
} else {
wrapper.cancel();
}
}
}
private void handleWithException(PacketWrapper wrapper) throws Exception {
int protVer = wrapper.passthrough(Type.VAR_INT); int protVer = wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Server Address wrapper.passthrough(Type.STRING); // Server Address
wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port
@ -86,7 +69,6 @@ public class BaseProtocol extends SimpleProtocol {
if (state == 2) { if (state == 2) {
info.setState(State.LOGIN); info.setState(State.LOGIN);
} }
}
}); });
} }
}); });