From 95763d35c8a8920b4d4d216b84fa5e1d8498aa48 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 31 Oct 2014 11:03:23 +0100 Subject: [PATCH] Add after-failure config flag checks for net/packet checks. Obviously these have been forgotten, but are not marked with @GlobalConfig. Using after-failure checking, because the raw config getting and accessing might be slightly heavy-ish. --- .../net/protocollib/FlyingFrequency.java | 17 ++++--- .../net/protocollib/ProtocolLibComponent.java | 4 +- .../net/protocollib/SoundDistance.java | 51 ++++++++++--------- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java index 9385bba0..fc90e5e8 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/FlyingFrequency.java @@ -70,13 +70,16 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener @Override public void onPacketReceiving(final PacketEvent event) { - // TODO: Add several (at least has look + has pos individually, maybe none/onground) - final ActionFrequency freq = getFreq(event.getPlayer().getName()); - freq.add(System.currentTimeMillis(), 1f); - if (freq.score(1f) > maxPackets) { - event.setCancelled(true); - counters.add(idSilent, 1); // Until it is sure if we can get these async. - } + // TODO: Add several (at least has look + has pos individually, maybe none/onground) + final ActionFrequency freq = getFreq(event.getPlayer().getName()); + freq.add(System.currentTimeMillis(), 1f); + if (freq.score(1f) > maxPackets) { + // TODO: Get from a NetConfig (optimized). + if (ConfigManager.getConfigFile(event.getPlayer().getWorld().getName()).getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) { + event.setCancelled(true); + counters.add(idSilent, 1); // Until it is sure if we can get these async. + } + } } } diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java index 4b8d702d..4e37026d 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/ProtocolLibComponent.java @@ -35,9 +35,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload{ } private void register(Plugin plugin) { - // REgister Classes having a constructor with Plugin as argument. - // TODO: Config paths for activation flags ... - // TODO: @GlobalConfig simple setup at first. + // Register Classes having a constructor with Plugin as argument. if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) { register(FlyingFrequency.class, plugin); } diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/SoundDistance.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/SoundDistance.java index eea094f0..86edd978 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/SoundDistance.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/net/protocollib/SoundDistance.java @@ -16,30 +16,30 @@ import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.utilities.TrigUtil; public class SoundDistance extends PacketAdapter { - - // TODO: Will not be effective with 512 radius, if they add the patch by @Amranth. - // TODO: For lower distances more packets might need to be intercepted. - + + // TODO: Will not be effective with 512 radius, if they add the patch by @Amranth. + // TODO: For lower distances more packets might need to be intercepted. + private static final String[] effectNames = new String[] { // Prefix tree? - "ambient.weather.thunder", - "wither-spawn-sound-radius", - "dragon-death-sound-radius" - // other ? + "ambient.weather.thunder", + "wither-spawn-sound-radius", + "dragon-death-sound-radius" + // other ? }; - + private static final boolean contains(final String ref) { - for (int i = 0; i < effectNames.length; i++) { - if (effectNames[i].equals(ref)) { - return true; - } - } - return false; + for (int i = 0; i < effectNames.length; i++) { + if (effectNames[i].equals(ref)) { + return true; + } + } + return false; } - + /** Maximum distance for thunder effects (squared). */ private final double distSq; - public SoundDistance(Plugin plugin) { + public SoundDistance(Plugin plugin) { super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT); ConfigFile config = ConfigManager.getConfigFile(); double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE); @@ -49,20 +49,23 @@ public class SoundDistance extends PacketAdapter { @Override public void onPacketSending(final PacketEvent event) { final PacketContainer packetContainer = event.getPacket(); - final Player player = event.getPlayer(); - + // Compare sound effect name. if (!contains(packetContainer.getStrings().read(0))) { - return; + return; } - + + final Player player = event.getPlayer(); final Location loc = player.getLocation(); // TODO: Use getLocation(useLoc) [synced if async]. - + // Compare distance of player to the weather location. final StructureModifier ints = packetContainer.getIntegers(); if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ()) > distSq) { - event.setCancelled(true); + // TODO: Get from a NetConfig (optimized). + if (ConfigManager.getConfigFile(player.getWorld().getName()).getBoolean(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) { + event.setCancelled(true); + } } } - + }