Adjust nopwnage speed check, remove timeout interval for a queue.

This commit is contained in:
asofold 2012-09-03 11:16:51 +02:00
parent 4144e14bac
commit b997a651fb
6 changed files with 34 additions and 26 deletions

View File

@ -1,10 +1,7 @@
package fr.neatmonster.nocheatplus.checks.chat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.entity.Player;
@ -74,14 +71,12 @@ public class ChatConfig implements CheckConfig {
public final boolean globalChatCheck;
public final boolean globalChatEngineCheck;
public final Set<String> globalChatCommands;
public final float globalChatFrequencyFactor;
public final float globalChatFrequencyWeight;
public final double globalChatLevel;
public final ActionList globalChatActions;
public final boolean noPwnageCheck;
public final List<String> noPwnageExclusions;
public final int noPwnageLevel;
public final float noPwnageVLFactor;
@ -121,7 +116,7 @@ public class ChatConfig implements CheckConfig {
public final int noPwnageRepeatWeight;
public final boolean noPwnageSpeedCheck;
public final long noPwnageSpeedTimeout;
// public final long noPwnageSpeedTimeout;
public final int noPwnageSpeedWeight;
public final int noPwnageWarnLevel;
@ -149,20 +144,12 @@ public class ChatConfig implements CheckConfig {
globalChatCheck = data.getBoolean(ConfPaths.CHAT_GLOBALCHAT_CHECK);
globalChatEngineCheck = data.getBoolean(ConfPaths.CHAT_GLOBALCHAT_ENGINE_CHECK);
final List<String> commands = data.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS);
globalChatCommands = new HashSet<String>();
if (commands != null){
for (String cmd : commands){
globalChatCommands.add(cmd.trim().toLowerCase());
}
}
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);
noPwnageCheck = data.getBoolean(ConfPaths.CHAT_NOPWNAGE_CHECK);
noPwnageExclusions = data.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS);
noPwnageLevel = data.getInt(ConfPaths.CHAT_NOPWNAGE_LEVEL);
// VL decreasing factor, hidden option.
noPwnageVLFactor = (float) data.getDouble(ConfPaths.CHAT_NOPWNAGE_VL_FACTOR, 0.95);
@ -203,7 +190,7 @@ public class ChatConfig implements CheckConfig {
noPwnageRepeatWeight = data.getInt(ConfPaths.CHAT_NOPWNAGE_REPEAT_WEIGHT);
noPwnageSpeedCheck = data.getBoolean(ConfPaths.CHAT_NOPWNAGE_SPEED_CHECK);
noPwnageSpeedTimeout = data.getLong(ConfPaths.CHAT_NOPWNAGE_SPEED_TIMEOUT);
// noPwnageSpeedTimeout = data.getLong(ConfPaths.CHAT_NOPWNAGE_SPEED_TIMEOUT);
noPwnageSpeedWeight = data.getInt(ConfPaths.CHAT_NOPWNAGE_SPEED_WEIGHT);
noPwnageWarnLevel = data.getInt(ConfPaths.CHAT_NOPWNAGE_WARN_LEVEL);

View File

@ -68,6 +68,7 @@ public class ChatData implements CheckData {
public long noPwnageLeaveTime;
public int noPwnageReloginWarnings;
public long noPwnageReloginWarningTime;
public final ActionFrequency noPwnageSpeed = new ActionFrequency(5, 1000);
/**
* Clear the data of the no pwnage check.

View File

@ -11,6 +11,10 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerMoveEvent;
import fr.neatmonster.nocheatplus.checks.chat.analysis.ds.SimpleCharPrefixTree;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.Permissions;
/*
@ -37,6 +41,17 @@ public class ChatListener implements Listener {
/** Global chat check (experiment: alternative / supplement). */
private final GlobalChat globalChat = new GlobalChat();
private final SimpleCharPrefixTree commandExclusions = new SimpleCharPrefixTree();
private final SimpleCharPrefixTree chatCommands = new SimpleCharPrefixTree();
public ChatListener(){
// Read some things from the global config file.
ConfigFile config = ConfigManager.getConfigFile();
commandExclusions.feedAll(config.getStringList(ConfPaths.CHAT_NOPWNAGE_EXCLUSIONS), true, true);
chatCommands.feedAll(config.getStringList(ConfPaths.CHAT_GLOBALCHAT_COMMANDS), true, true);
}
/**
* We listen to PlayerChat events for obvious reasons.
@ -123,10 +138,12 @@ public class ChatListener implements Listener {
// First the color check.
event.setMessage(color.check(player, event.getMessage(), true));
final boolean handleAsChat = cc.globalChatCommands.contains(command) || cc.globalChatCommands.contains("/"+command);
final String lcMessage = event.getMessage().trim().toLowerCase();
final boolean handleAsChat = chatCommands.hasPrefix(lcMessage);
// Then the no pwnage check.
if (noPwnage.check(player, event.getMessage(), !handleAsChat, true))
if (!commandExclusions.hasPrefix(lcMessage) && noPwnage.check(player, event.getMessage(), !handleAsChat, true))
event.setCancelled(true);
else if (handleAsChat && globalChat.check(player, event.getMessage(), noPwnage, true))
event.setCancelled(true);

View File

@ -129,11 +129,6 @@ public class NoPwnage extends Check implements ICaptcha{
final boolean isMainThread, final ChatConfig cc, final ChatData data) {
boolean cancel = false;
// Don't not check excluded messages/commands.
for (final String exclusion : cc.noPwnageExclusions)
if (message.startsWith(exclusion))
return false;
final long now = System.currentTimeMillis();
// Forget expired VL.
@ -165,8 +160,16 @@ public class NoPwnage extends Check implements ICaptcha{
// NoPwnage will check if a player sends messages too fast. If a message is sent within "timeout"
// milliseconds after the previous message, increase suspicion by "weight".
if (cc.noPwnageSpeedCheck && now - data.noPwnageLastMessageTime < cc.noPwnageSpeedTimeout)
suspicion += cc.noPwnageSpeedWeight;
// TODO: update description or method :p
if (cc.noPwnageSpeedCheck){
// First add old messages score:
data.noPwnageSpeed.update(now);
suspicion += data.noPwnageSpeed.getScore(0.7f) * cc.noPwnageSpeedWeight;
// Then add this message.
data.noPwnageSpeed.add(now, 1.0f);
}
// NoPwnage will check if a player repeats his messages within the "timeout" timeframe. Even if the message
// is a bit different, it will be counted as being a repetition. The suspicion is increased by "weight".

View File

@ -203,7 +203,7 @@ public abstract class ConfPaths {
private static final String CHAT_NOPWNAGE_SPEED = CHAT_NOPWNAGE + "speed.";
public static final String CHAT_NOPWNAGE_SPEED_CHECK = CHAT_NOPWNAGE_SPEED + "active";
public static final String CHAT_NOPWNAGE_SPEED_TIMEOUT = CHAT_NOPWNAGE_SPEED + "timeout";
// public static final String CHAT_NOPWNAGE_SPEED_TIMEOUT = CHAT_NOPWNAGE_SPEED + "timeout";
public static final String CHAT_NOPWNAGE_SPEED_WEIGHT = CHAT_NOPWNAGE_SPEED + "weight";
public static final String CHAT_NOPWNAGE_VL = CHAT_NOPWNAGE + "vl.";

View File

@ -181,7 +181,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.CHAT_NOPWNAGE_REPEAT_WEIGHT, 150);
set(ConfPaths.CHAT_NOPWNAGE_SPEED_CHECK, true);
set(ConfPaths.CHAT_NOPWNAGE_SPEED_TIMEOUT, 500L);
// set(ConfPaths.CHAT_NOPWNAGE_SPEED_TIMEOUT, 500L);
set(ConfPaths.CHAT_NOPWNAGE_SPEED_WEIGHT, 200);
set(ConfPaths.CHAT_NOPWNAGE_WARN_LEVEL, 400);