3
0
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:
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,65 +26,48 @@ 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 int protVer = wrapper.passthrough(Type.VAR_INT);
public void handle(PacketWrapper wrapper) throws Exception { wrapper.passthrough(Type.STRING); // Server Address
try { wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port
handleWithException(wrapper); int state = wrapper.passthrough(Type.VAR_INT);
} catch (Exception e) {
// Only throw exceptions here when debug is enabled ProtocolInfo info = wrapper.user().getProtocolInfo();
// The handling has proven to be correct, but often receives invalid packets as the first packet of a connection info.setProtocolVersion(protVer);
if (Via.getManager().isDebug()) { // Ensure the server has a version provider
throw e; if (Via.getManager().getProviders().get(VersionProvider.class) == null) {
} else { wrapper.user().setActive(false);
wrapper.cancel(); return;
} }
} // Choose the pipe
int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user());
info.setServerProtocolVersion(protocol);
List<Pair<Integer, Protocol>> protocols = null;
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol);
} }
private void handleWithException(PacketWrapper wrapper) throws Exception { ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
int protVer = wrapper.passthrough(Type.VAR_INT); if (protocols != null) {
wrapper.passthrough(Type.STRING); // Server Address for (Pair<Integer, Protocol> prot : protocols) {
wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port pipeline.add(prot.getValue());
int state = wrapper.passthrough(Type.VAR_INT); // Ensure mapping data has already been loaded
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass());
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setProtocolVersion(protVer);
// Ensure the server has a version provider
if (Via.getManager().getProviders().get(VersionProvider.class) == null) {
wrapper.user().setActive(false);
return;
} }
// Choose the pipe wrapper.set(Type.VAR_INT, 0, protocol);
int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); }
info.setServerProtocolVersion(protocol);
List<Pair<Integer, Protocol>> protocols = null;
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) // Add Base Protocol
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) { pipeline.add(ProtocolRegistry.getBaseProtocol(protocol));
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol);
}
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline(); // Change state
if (protocols != null) { if (state == 1) {
for (Pair<Integer, Protocol> prot : protocols) { info.setState(State.STATUS);
pipeline.add(prot.getValue()); }
// Ensure mapping data has already been loaded if (state == 2) {
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass()); info.setState(State.LOGIN);
}
wrapper.set(Type.VAR_INT, 0, protocol);
}
// Add Base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(protocol));
// Change state
if (state == 1) {
info.setState(State.STATUS);
}
if (state == 2) {
info.setState(State.LOGIN);
}
} }
}); });
} }