diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java index b3043028..b3f910af 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java @@ -71,8 +71,8 @@ public class ChatConfig implements CheckConfig { public final ActionList colorActions; public final boolean globalChatCheck; - public double globalChatFrequencyFactor; - public final double globalChatFrequencyWeight; + public final float globalChatFrequencyFactor; + public final float globalChatFrequencyWeight; public final double globalChatLevel; public final ActionList globalChatActions; @@ -143,8 +143,8 @@ public class ChatConfig implements CheckConfig { colorActions = data.getActionList(ConfPaths.CHAT_COLOR_ACTIONS, Permissions.CHAT_COLOR); globalChatCheck = data.getBoolean(ConfPaths.CHAT_GLOBALCHAT_CHECK); - globalChatFrequencyFactor = data.getDouble(ConfPaths.CHAT_GLOBALCHAT_FREQUENCY_FACTOR); - globalChatFrequencyWeight = data.getDouble(ConfPaths.CHAT_GLOBALCHAT_FREQUENCY_WEIGHT); + globalChatFrequencyFactor = (float) data.getDouble(ConfPaths.CHAT_GLOBALCHAT_FREQUENCY_FACTOR); + globalChatFrequencyWeight = (float) data.getDouble(ConfPaths.CHAT_GLOBALCHAT_FREQUENCY_WEIGHT); globalChatLevel = data.getDouble(ConfPaths.CHAT_GLOBALCHAT_LEVEL); globalChatActions = data.getActionList(ConfPaths.CHAT_GLOBALCHAT_ACTIONS, Permissions.CHAT_GLOBALCHAT); diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java b/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java index 96d60a47..43329d11 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/GlobalChat.java @@ -19,10 +19,13 @@ public class GlobalChat extends Check{ } /** - * + * Start analysis. * @param player + * The player who issued the message. * @param message - * @param captcha Used for starting captcha on failure. + * The message to check. + * @param captcha + * Used for starting captcha on failure, if configured so. * @return */ public boolean check(final Player player, final String message, final ICaptcha captcha) { @@ -40,6 +43,15 @@ public class GlobalChat extends Check{ } } + /** + * Check without further synchronization. + * @param player + * @param message + * @param captcha + * @param cc + * @param data + * @return + */ private boolean unsafeCheck(final Player player, final String message, final ICaptcha captcha, final ChatConfig cc, final ChatData data) { // Take time once: @@ -47,14 +59,21 @@ public class GlobalChat extends Check{ boolean cancel = false; - data.globalChatFrequency.add(time); - double score = cc.globalChatFrequencyWeight * data.globalChatFrequency.getScore(cc.globalChatFrequencyFactor); - if (score < 2.0 * cc.globalChatFrequencyWeight) + // Update the frequency interval weights. + data.globalChatFrequency.update(time); + double score = 0; + if (score < cc.globalChatFrequencyWeight) // Reset the VL. data.globalChatVL = 0.0; + // Weight of this chat message. + float weight = 1.0f; // TODO Core checks.... + // Add weight to frequency counts. + data.globalChatFrequency.add(time, weight); + score += cc.globalChatFrequencyWeight * data.globalChatFrequency.getScore(cc.globalChatFrequencyFactor); + if (score > cc.globalChatLevel){ if (captcha.shouldStartCaptcha(cc, data)){ captcha.sendNewCaptcha(player, cc, data); diff --git a/src/fr/neatmonster/nocheatplus/utilities/ActionFrequency.java b/src/fr/neatmonster/nocheatplus/utilities/ActionFrequency.java index 389dd551..35872b2c 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/ActionFrequency.java +++ b/src/fr/neatmonster/nocheatplus/utilities/ActionFrequency.java @@ -12,12 +12,12 @@ public class ActionFrequency { /** Reference time for filling in. */ long time = 0; - final int[] buckets; + final float[] buckets; final long durBucket; public ActionFrequency(final int nBuckets, final long durBucket){ - this.buckets = new int[nBuckets]; + this.buckets = new float[nBuckets]; this.durBucket = durBucket; } @@ -25,8 +25,9 @@ public class ActionFrequency { * Update and add. * @param ts */ - public void add(final long now){ + public void add(final long now, final float amount){ update(now); + buckets[0] += amount; } /** @@ -38,13 +39,11 @@ public class ActionFrequency { final int shift = (int) ((float) diff / (float) durBucket); if (shift == 0){ // No update, just fill in. - buckets[0] ++; return; } else if (shift >= buckets.length){ // Clear and fill in (beyond range). clear(now); - buckets[0] ++; return; } // Update buckets. @@ -54,7 +53,6 @@ public class ActionFrequency { for (int i = 0; i < shift; i++){ buckets[i] = 0; } - buckets[0] ++; // Set time according to bucket duration (!). time += durBucket * shift; } @@ -72,9 +70,9 @@ public class ActionFrequency { * @param factor * @return */ - public double getScore(final double factor){ - double res = buckets[0]; - double cf = factor; + public float getScore(final float factor){ + float res = buckets[0]; + float cf = factor; for (int i = 1; i < buckets.length; i++){ res += cf * buckets[i]; cf *= factor;