From 2cad9962527d689097634c6d90e18a03aa306ca6 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 14 Jun 2024 14:00:59 -0500 Subject: [PATCH] fix: gracefully fail for unknown protocols Fixes #3012 Fixes #3001 Fixes #2994 --- .../java/com/comphenix/protocol/PacketType.java | 13 ++++++------- .../netty/channel/NettyChannelInjector.java | 11 +++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java index 72810699..9471674a 100644 --- a/src/main/java/com/comphenix/protocol/PacketType.java +++ b/src/main/java/com/comphenix/protocol/PacketType.java @@ -741,11 +741,7 @@ public class PacketType implements Serializable, Cloneable, Comparable vanilla) { + if (vanilla == null) { + return UNKNOWN; + } + switch (vanilla.name()) { case "HANDSHAKING": return HANDSHAKING; case "PLAY": return PLAY; case "STATUS": return STATUS; case "LOGIN": return LOGIN; case "CONFIGURATION": return CONFIGURATION; - default: - throw new IllegalArgumentException("Unrecognized vanilla enum " + vanilla); + default: return UNKNOWN; } } diff --git a/src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java b/src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java index 8a946f5d..b9e1da77 100644 --- a/src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java +++ b/src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java @@ -11,9 +11,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; -import org.bukkit.Server; -import org.bukkit.entity.Player; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.ProtocolLibrary; @@ -46,6 +43,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoop; import io.netty.util.AttributeKey; +import org.bukkit.Server; +import org.bukkit.entity.Player; public class NettyChannelInjector implements Injector { @@ -583,8 +582,12 @@ public class NettyChannelInjector implements Injector { } PacketType.Protocol protocol = this.getCurrentProtocol(PacketType.Sender.SERVER); + if (protocol == Protocol.UNKNOWN) { + ProtocolLogger.debug("skipping unknown protocol for {0}", packet.getClass()); + return action; + } + PacketType packetType = PacketRegistry.getPacketType(protocol, packet.getClass()); - if (packetType == null) { ProtocolLogger.debug("skipping unknown outbound packet type for {0}", packet.getClass()); return action;