mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 13:15:52 +01:00
fix: gracefully fail for unknown protocols
Fixes #3012 Fixes #3001 Fixes #2994
This commit is contained in:
parent
46d40d752e
commit
2cad996252
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user