fix: gracefully fail for unknown protocols

Fixes #3012
Fixes #3001
Fixes #2994
This commit is contained in:
Dan Mulloy 2024-06-14 14:00:59 -05:00
parent 46d40d752e
commit 2cad996252
No known key found for this signature in database
GPG Key ID: 3C5AD5D866D1539A
2 changed files with 13 additions and 11 deletions

View File

@ -741,11 +741,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
STATUS("Status", "status"), STATUS("Status", "status"),
LOGIN("Login", "login"), LOGIN("Login", "login"),
CONFIGURATION("Configuration", "configuration"), CONFIGURATION("Configuration", "configuration"),
UNKNOWN("", "");
/**
* Only for packets removed in Minecraft 1.7.2
*/
LEGACY("", "");
private final String packetName; private final String packetName;
private final String mojangName; private final String mojangName;
@ -761,14 +757,17 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
* @return The corresponding protocol. * @return The corresponding protocol.
*/ */
public static Protocol fromVanilla(Enum<?> vanilla) { public static Protocol fromVanilla(Enum<?> vanilla) {
if (vanilla == null) {
return UNKNOWN;
}
switch (vanilla.name()) { switch (vanilla.name()) {
case "HANDSHAKING": return HANDSHAKING; case "HANDSHAKING": return HANDSHAKING;
case "PLAY": return PLAY; case "PLAY": return PLAY;
case "STATUS": return STATUS; case "STATUS": return STATUS;
case "LOGIN": return LOGIN; case "LOGIN": return LOGIN;
case "CONFIGURATION": return CONFIGURATION; case "CONFIGURATION": return CONFIGURATION;
default: default: return UNKNOWN;
throw new IllegalArgumentException("Unrecognized vanilla enum " + vanilla);
} }
} }

View File

@ -11,9 +11,6 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.PacketType.Protocol;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
@ -46,6 +43,8 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import org.bukkit.Server;
import org.bukkit.entity.Player;
public class NettyChannelInjector implements Injector { public class NettyChannelInjector implements Injector {
@ -583,8 +582,12 @@ public class NettyChannelInjector implements Injector {
} }
PacketType.Protocol protocol = this.getCurrentProtocol(PacketType.Sender.SERVER); PacketType.Protocol protocol = this.getCurrentProtocol(PacketType.Sender.SERVER);
PacketType packetType = PacketRegistry.getPacketType(protocol, packet.getClass()); 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) { if (packetType == null) {
ProtocolLogger.debug("skipping unknown outbound packet type for {0}", packet.getClass()); ProtocolLogger.debug("skipping unknown outbound packet type for {0}", packet.getClass());
return action; return action;