Archiviert
13
0

Ignore improperly registered custom packets

Fixes #123
Dieser Commit ist enthalten in:
Dan Mulloy 2015-10-23 20:28:49 -04:00
Ursprung 245433b29a
Commit cd7894f9f1
2 geänderte Dateien mit 19 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -53,6 +53,10 @@ public class Netty {
return compat; return compat;
} }
public static boolean isIndependent() {
return compat instanceof IndependentNetty;
}
public static WrappedByteBuf createPacketBuffer() { public static WrappedByteBuf createPacketBuffer() {
return getCompat().createPacketBuffer(); return getCompat().createPacketBuffer();
} }

Datei anzeigen

@ -9,10 +9,10 @@ import java.util.Set;
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.PacketType.Sender; import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.compat.netty.Netty;
import com.comphenix.protocol.injector.packet.MapContainer; import com.comphenix.protocol.injector.packet.MapContainer;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -109,14 +109,13 @@ public class NettyProtocolRegistry {
* Load the packet lookup tables in each protocol. * Load the packet lookup tables in each protocol.
*/ */
private synchronized void initialize() { private synchronized void initialize() {
Object[] protocols = enumProtocol.getEnumConstants(); if (!Netty.isIndependent()) { // Check for 1.7
// TODO: Find a better less than 1.7 check
if (MinecraftVersion.getCurrentVersion().compareTo(MinecraftVersion.BOUNTIFUL_UPDATE) < 0) {
initialize17(); initialize17();
return; return;
} }
Object[] protocols = enumProtocol.getEnumConstants();
// ID to Packet class maps // ID to Packet class maps
Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap(); Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap();
Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap(); Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap();
@ -218,12 +217,17 @@ public class NettyProtocolRegistry {
private void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) { private void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) {
for (Entry<Integer, Class<?>> entry : lookup.entrySet()) { for (Entry<Integer, Class<?>> entry : lookup.entrySet()) {
PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), PacketType.UNKNOWN_PACKET); PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), PacketType.UNKNOWN_PACKET);
register.typeToClass.put(type, entry.getValue());
if (sender == Sender.SERVER) try {
register.serverPackets.add(type); register.typeToClass.put(type, entry.getValue());
if (sender == Sender.CLIENT)
register.clientPackets.add(type); if (sender == Sender.SERVER)
register.serverPackets.add(type);
if (sender == Sender.CLIENT)
register.clientPackets.add(type);
} catch (IllegalArgumentException ex) {
// Sometimes this happens with fake packets, just ignore it
}
} }
} }