From bb24ecaa93070be5b2753d86e42a6238768185fd Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 18 Sep 2012 17:53:30 +0200 Subject: [PATCH] Allow feeding yawrate violations to improbable check. Rename methods for yawRate. --- .../nocheatplus/checks/combined/Combined.java | 31 +++++++++++-------- .../checks/combined/CombinedConfig.java | 6 ++-- .../checks/combined/CombinedListener.java | 2 +- .../checks/fight/FightListener.java | 2 +- .../nocheatplus/config/ConfPaths.java | 1 + .../nocheatplus/config/DefaultConfig.java | 3 +- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/Combined.java b/src/fr/neatmonster/nocheatplus/checks/combined/Combined.java index d0c2b1f3..89397d38 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/Combined.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/Combined.java @@ -18,8 +18,8 @@ public class Combined { * @param worldName * @return */ - public static final boolean checkYaw(final Player player, final float yaw, final long now, final String worldName){ - return checkYaw(player, yaw, now, worldName, CombinedData.getData(player)); + public static final boolean checkYawRate(final Player player, final float yaw, final long now, final String worldName){ + return checkYawRate(player, yaw, now, worldName, CombinedData.getData(player)); } /** @@ -29,8 +29,8 @@ public class Combined { * @param now * @param worldName */ - public static final void feedYaw(final Player player, final float yaw, final long now, final String worldName){ - feedYaw(player, yaw, now, worldName, CombinedData.getData(player)); + public static final void feedYawRate(final Player player, final float yaw, final long now, final String worldName){ + feedYawRate(player, yaw, now, worldName, CombinedData.getData(player)); } /** @@ -41,7 +41,7 @@ public class Combined { * @param worldName * @param data */ - private static final void feedYaw(final Player player, final float yaw, final long now, final String worldName, final CombinedData data) { + private static final void feedYawRate(final Player player, final float yaw, final long now, final String worldName, final CombinedData data) { // Reset on world change or timeout. if (now - data.lastYawTime > 999 || !worldName.equals(data.lastWorld)){ data.lastYaw = yaw; @@ -70,20 +70,25 @@ public class Combined { * @param worldName * @return */ - private static final boolean checkYaw(Player player, float yaw, long now, final String worldName, final CombinedData data) { + private static final boolean checkYawRate(Player player, float yaw, long now, final String worldName, final CombinedData data) { - feedYaw(player, yaw, now, worldName, data); + feedYawRate(player, yaw, now, worldName, data); final CombinedConfig cc = CombinedConfig.getConfig(player); // Angle diff per second final float total = Math.max(data.yawFreq.getScore(1f), data.yawFreq.getScore(0) * 3f); - final float threshold = cc.lastYawRate; + final float threshold = cc.yawRate; + boolean cancel = false; if (total > threshold){ // Add time - data.timeFreeze = Math.max(data.timeFreeze, now + (long) ((total - threshold) / threshold * 1000f)); + final float amount = ((total - threshold) / threshold * 1000f); + data.timeFreeze = Math.max(data.timeFreeze, now + (long) amount); + if (cc.yawRateImprobable && Improbable.check(player, 5f * amount / 1000f, now)) + cancel = true; } - return now < data.timeFreeze; + if (now < data.timeFreeze) cancel = true; + return cancel; } /** @@ -95,10 +100,10 @@ public class Combined { * @param yawRateCheck If to actually check the yaw rate, or just feed. * @return */ - public static final boolean checkYaw(final Player player, final float yaw, final long now, final String worldName, final boolean yawRateCheck) { - if (yawRateCheck) return checkYaw(player, yaw, now, worldName); + public static final boolean checkYawRate(final Player player, final float yaw, final long now, final String worldName, final boolean yawRateCheck) { + if (yawRateCheck) return checkYawRate(player, yaw, now, worldName); else { - feedYaw(player, yaw, now, worldName); + feedYawRate(player, yaw, now, worldName); return false; } } diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java index 492f4632..17614251 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java @@ -43,14 +43,16 @@ public class CombinedConfig extends ACheckConfig { public final ActionList improbableActions; // Last yaw tracking - public final float lastYawRate; + public final float yawRate; + public final boolean yawRateImprobable; public CombinedConfig(final ConfigFile config) { improbableCheck = config.getBoolean(ConfPaths.COMBINED_IMPROBABLE_CHECK, false); improbableLevel = (float) config.getDouble(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300); improbableActions = config.getActionList(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, Permissions.COMBINED_IMPROBABLE); - lastYawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE); + yawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE); + yawRateImprobable = config.getBoolean(ConfPaths.COMBINED_YAWRATE_IMPROBABLE); } @Override diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java index 17e756eb..6620739a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java @@ -41,7 +41,7 @@ public class CombinedListener implements Listener { // Just add the yaw to the list. final Location loc = player.getLocation(); final String worldName = loc.getWorld().getName(); - Combined.feedYaw(player, loc.getYaw(), System.currentTimeMillis(), worldName); + Combined.feedYawRate(player, loc.getYaw(), System.currentTimeMillis(), worldName); } // (possibly other types of events, but these combine with fighting). diff --git a/src/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/src/fr/neatmonster/nocheatplus/checks/fight/FightListener.java index d631dc1e..efaec825 100644 --- a/src/fr/neatmonster/nocheatplus/checks/fight/FightListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/fight/FightListener.java @@ -119,7 +119,7 @@ public class FightListener implements Listener { final boolean worldChanged = !worldName.equals(data.lastWorld); // Improbable yaw: - if (Combined.checkYaw(player, player.getLocation().getYaw(), now, worldName, cc.yawRateCheck)){ + if (Combined.checkYawRate(player, player.getLocation().getYaw(), now, worldName, cc.yawRateCheck)){ cancelled = true; } diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 34079dd4..fb06b494 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -303,6 +303,7 @@ public abstract class ConfPaths { private static final String COMBINED_YAWRATE = COMBINED + "yawrate."; public static final String COMBINED_YAWRATE_RATE = COMBINED_YAWRATE + "rate"; + public static final String COMBINED_YAWRATE_IMPROBABLE = COMBINED_YAWRATE + "improbable"; /* * 888'Y88 ,e, 888 d8 diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index a03fc7da..87dca6cb 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -228,7 +228,8 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK, false); set(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, "cancel log:improbable:2:8:if"); - set(ConfPaths.COMBINED_YAWRATE_RATE , "380"); + set(ConfPaths.COMBINED_YAWRATE_RATE , 380); + set(ConfPaths.COMBINED_YAWRATE_IMPROBABLE, true); /* * 888'Y88 ,e, 888 d8