Archiviert
13
0

Make sure the packet IDs are actually valid.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-09-27 05:26:02 +02:00
Ursprung eb8abd4635
Commit 8293c71a4c

Datei anzeigen

@ -180,10 +180,12 @@ public final class PacketFilterManager implements ProtocolManager {
if (hasSending || hasReceiving) { if (hasSending || hasReceiving) {
// Add listeners and hooks // Add listeners and hooks
if (hasSending) { if (hasSending) {
verifyWhitelist(listener, sending);
sendingListeners.addListener(listener, sending); sendingListeners.addListener(listener, sending);
enablePacketFilters(ConnectionSide.SERVER_SIDE, sending.getWhitelist()); enablePacketFilters(ConnectionSide.SERVER_SIDE, sending.getWhitelist());
} }
if (hasReceiving) { if (hasReceiving) {
verifyWhitelist(listener, receiving);
recievedListeners.addListener(listener, receiving); recievedListeners.addListener(listener, receiving);
enablePacketFilters(ConnectionSide.CLIENT_SIDE, receiving.getWhitelist()); enablePacketFilters(ConnectionSide.CLIENT_SIDE, receiving.getWhitelist());
@ -196,6 +198,20 @@ public final class PacketFilterManager implements ProtocolManager {
} }
} }
/**
* Determine if the packet IDs in a whitelist is valid.
* @param whitelist - whitelist of packet IDs.
*/
private void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist) {
for (Integer id : whitelist.getWhitelist()) {
if (id >= 256 || id < 0) {
throw new IllegalArgumentException(String.format("Invalid packet id %s in listener %s.",
id, PacketAdapter.getPluginName(listener))
);
}
}
}
/** /**
* Determine if a listener is valid or not. * Determine if a listener is valid or not.
* @param listener - listener to check. * @param listener - listener to check.