Ensure that ProtocolLib discoveres mod-specific packets.

This commit is contained in:
Kristian S. Stangeland 2013-02-06 22:40:17 +01:00
parent 224b5d7f3e
commit 351dc7f3df
2 changed files with 26 additions and 14 deletions

View File

@ -133,8 +133,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
private AsyncFilterManager asyncFilterManager;
// Valid server and client packets
private Set<Integer> serverPackets;
private Set<Integer> clientPackets;
private boolean knowsServerPackets;
private boolean knowsClientPackets;
// Ensure that we're not performing too may injections
private AtomicInteger phaseLoginCount = new AtomicInteger(0);
@ -214,8 +214,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// Attempt to load the list of server and client packets
try {
this.serverPackets = PacketRegistry.getServerPackets();
this.clientPackets = PacketRegistry.getClientPackets();
knowsServerPackets = PacketRegistry.getServerPackets() != null;
knowsClientPackets = PacketRegistry.getClientPackets() != null;
} catch (FieldAccessException e) {
reporter.reportWarning(this, "Cannot load server and client packet list.", e);
}
@ -466,7 +466,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
for (int packetID : packets) {
// Only register server packets that are actually supported by Minecraft
if (side.isForServer()) {
if (serverPackets != null && serverPackets.contains(packetID))
// Note that we may update the packet list here
if (!knowsServerPackets || PacketRegistry.getServerPackets().contains(packetID))
playerInjection.addPacketHandler(packetID);
else
reporter.reportWarning(this, String.format(
@ -477,7 +478,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// As above, only for client packets
if (side.isForClient() && packetInjector != null) {
if (clientPackets != null && clientPackets.contains(packetID))
if (!knowsClientPackets || PacketRegistry.getClientPackets().contains(packetID))
packetInjector.addPacketHandler(packetID);
else
reporter.reportWarning(this, String.format(

View File

@ -47,8 +47,12 @@ public class PacketRegistry {
private static Map<Class, Integer> packetToID;
// Whether or not certain packets are sent by the client or the server
private static Set<Integer> serverPackets;
private static Set<Integer> clientPackets;
private static ImmutableSet<Integer> serverPackets;
private static ImmutableSet<Integer> clientPackets;
// The underlying sets
private static Set<Integer> serverPacketsRef;
private static Set<Integer> clientPacketsRef;
// New proxy values
private static Map<Integer, Class> overwrittenPackets = new HashMap<Integer, Class>();
@ -120,21 +124,21 @@ public class PacketRegistry {
@SuppressWarnings("unchecked")
private static void initializeSets() throws FieldAccessException {
if (serverPackets == null || clientPackets == null) {
if (serverPacketsRef == null || clientPacketsRef == null) {
List<Field> sets = getPacketRegistry().getFieldListByType(Set.class);
try {
if (sets.size() > 1) {
serverPackets = (Set<Integer>) FieldUtils.readStaticField(sets.get(0), true);
clientPackets = (Set<Integer>) FieldUtils.readStaticField(sets.get(1), true);
serverPacketsRef = (Set<Integer>) FieldUtils.readStaticField(sets.get(0), true);
clientPacketsRef = (Set<Integer>) FieldUtils.readStaticField(sets.get(1), true);
// Impossible
if (serverPackets == null || clientPackets == null)
if (serverPacketsRef == null || clientPacketsRef == null)
throw new FieldAccessException("Packet sets are in an illegal state.");
// NEVER allow callers to modify the underlying sets
serverPackets = ImmutableSet.copyOf(serverPackets);
clientPackets = ImmutableSet.copyOf(clientPackets);
serverPackets = ImmutableSet.copyOf(serverPacketsRef);
clientPackets = ImmutableSet.copyOf(clientPacketsRef);
} else {
throw new FieldAccessException("Cannot retrieve packet client/server sets.");
@ -143,6 +147,13 @@ public class PacketRegistry {
} catch (IllegalAccessException e) {
throw new FieldAccessException("Cannot access field.", e);
}
} else {
// Copy over again if it has changed
if (serverPacketsRef != null && serverPacketsRef.size() != serverPackets.size())
serverPackets = ImmutableSet.copyOf(serverPacketsRef);
if (clientPacketsRef != null && clientPacketsRef.size() != clientPackets.size())
clientPackets = ImmutableSet.copyOf(clientPacketsRef);
}
}