Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Move handshake exceptions filter to exceptionCaught handling
Dieser Commit ist enthalten in:
Ursprung
96485c444e
Commit
f16ff65933
@ -3,11 +3,13 @@ package us.myles.ViaVersion.bukkit.handlers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||
import us.myles.ViaVersion.exception.CancelCodecException;
|
||||
import us.myles.ViaVersion.exception.CancelDecoderException;
|
||||
import us.myles.ViaVersion.exception.InformativeException;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -57,7 +59,8 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder {
|
||||
if (PipelineUtil.containsCause(cause, CancelCodecException.class)) return; // ProtocolLib compat
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.bukkit.handlers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||
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.handlers.ChannelHandlerContextWrapper;
|
||||
import us.myles.ViaVersion.handlers.ViaHandler;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -418,7 +418,8 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
|
||||
try {
|
||||
protocolPacket.getRemapper().remap(packetWrapper);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof CancelException) {
|
||||
// Don't print cancelled packets or the handshake
|
||||
if (e instanceof CancelException || state == State.HANDSHAKE) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
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.type.Type;
|
||||
import us.myles.ViaVersion.packets.Direction;
|
||||
@ -27,23 +26,7 @@ public class BaseProtocol extends SimpleProtocol {
|
||||
registerIncoming(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@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 {
|
||||
handler(wrapper -> {
|
||||
int protVer = wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.STRING); // Server Address
|
||||
wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port
|
||||
@ -86,7 +69,6 @@ public class BaseProtocol extends SimpleProtocol {
|
||||
if (state == 2) {
|
||||
info.setState(State.LOGIN);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren