From 08ef299290687218eaf49ae78121fa43329d8b2e Mon Sep 17 00:00:00 2001 From: Evenprime Date: Mon, 17 Oct 2011 21:22:26 +0200 Subject: [PATCH] Colors! And getting kicked for extensive (command) spamming by default now --- .../co/evenprime/bukkit/nocheat/NoCheat.java | 6 ++-- .../bukkit/nocheat/actions/ActionManager.java | 4 +-- .../nocheat/actions/types/LogAction.java | 6 ++-- .../checks/moving/MorePacketsCheck.java | 4 +-- .../bukkit/nocheat/config/Configuration.java | 1 + .../nocheat/config/DefaultConfiguration.java | 35 ++++++++++--------- .../nocheat/config/cache/CCLogging.java | 5 +-- .../bukkit/nocheat/data/BaseData.java | 2 +- .../bukkit/nocheat/data/DataManager.java | 16 +++++---- .../evenprime/bukkit/nocheat/log/Colors.java | 19 ++++++++++ .../bukkit/nocheat/log/LogManager.java | 7 ++-- 11 files changed, 64 insertions(+), 41 deletions(-) create mode 100644 src/cc/co/evenprime/bukkit/nocheat/log/Colors.java diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index 9806b74b..1ff02638 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -39,8 +39,6 @@ import cc.co.evenprime.bukkit.nocheat.log.LogManager; * * Check various player events for their plausibility and log/deny them/react to * them based on configuration - * - * @author Evenprime */ public class NoCheat extends JavaPlugin { @@ -118,6 +116,10 @@ public class NoCheat extends JavaPlugin { lastIngamesecondDuration = time - lastIngamesecondTime; if(lastIngamesecondDuration < 1000) lastIngamesecondDuration = 1000; + else if(lastIngamesecondDuration > 3600000) { + lastIngamesecondDuration = 3600000; // top limit of 1 + // hour per "second" + } lastIngamesecondTime = time; ingameseconds++; diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java index 4b9ac06f..3be3c39c 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/ActionManager.java @@ -17,8 +17,6 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData; * Will trace the history of action executions to decide if an action 'really' * gets executed. * - * @author Evenprime - * */ public class ActionManager { @@ -55,7 +53,7 @@ public class ActionManager { } private void executeLogAction(LogAction l, LogData data, ConfigurationCache cc) { - plugin.getLogManager().log(l.level, l.getMessage(data), cc); + plugin.getLogManager().log(l.level, cc.logging.prefix + l.getMessage(data), cc); } private void executeConsoleCommand(ConsolecommandAction action, LogData data) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java index 9710efdf..4c2fff98 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/LogAction.java @@ -1,20 +1,20 @@ package cc.co.evenprime.bukkit.nocheat.actions.types; import cc.co.evenprime.bukkit.nocheat.data.LogData; +import cc.co.evenprime.bukkit.nocheat.log.Colors; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * Print a message to various locations * - * @author Evenprime - * */ public class LogAction extends ActionWithParameters { public final LogLevel level; public LogAction(String name, int delay, int repeat, LogLevel level, String message) { - super(name, delay, repeat, message); + // Log messages may have color codes now + super(name, delay, repeat, Colors.replaceColors(message)); this.level = level; } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java index 947b7922..340d4b2b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/moving/MorePacketsCheck.java @@ -16,8 +16,6 @@ import cc.co.evenprime.bukkit.nocheat.data.BaseData; * It monitors the number of packets sent to the server within 1 second and * compares it to the "legal" number of packets for that timeframe (22). * - * @author Evenprime - * */ public class MorePacketsCheck { @@ -103,7 +101,7 @@ public class MorePacketsCheck { int difference = limit - data.moving.morePacketsCounter; - data.moving.morePacketsBuffer = data.moving.morePacketsBuffer + difference; + data.moving.morePacketsBuffer += difference; if(data.moving.morePacketsBuffer > bufferLimit) data.moving.morePacketsBuffer = bufferLimit; // Are we over the 22 event limit for that time frame now? (limit diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java index 971afef2..e17638f4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java @@ -22,6 +22,7 @@ public abstract class Configuration { private final static OptionNode LOGGING = new OptionNode("logging", ROOT, DataType.PARENT); public final static OptionNode LOGGING_ACTIVE = new OptionNode("active", LOGGING, DataType.BOOLEAN); + public final static OptionNode LOGGING_PREFIX = new OptionNode("prefix", LOGGING, DataType.STRING); public final static OptionNode LOGGING_FILENAME = new OptionNode("filename", LOGGING, DataType.STRING); public final static OptionNode LOGGING_FILELEVEL = new OptionNode("filelevel", LOGGING, DataType.LOGLEVEL); public final static OptionNode LOGGING_CONSOLELEVEL = new OptionNode("consolelevel", LOGGING, DataType.LOGLEVEL); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java index e31aa5ef..76678ed5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java @@ -22,6 +22,7 @@ public class DefaultConfiguration extends Configuration { /*** LOGGING ***/ { setValue(LOGGING_ACTIVE, true); + setValue(LOGGING_PREFIX, "&4NC&f: "); setValue(LOGGING_FILENAME, "nocheat.log"); setValue(LOGGING_FILELEVEL, LogLevel.LOW); setValue(LOGGING_CONSOLELEVEL, LogLevel.HIGH); @@ -134,6 +135,7 @@ public class DefaultConfiguration extends Configuration { ActionList spamActionList = new ActionList(); spamActionList.setActions(0, action.getActions("spamLog spamCancel".split(" "))); + spamActionList.setActions(50, action.getActions("spamLog spamCancel spamkick".split(" "))); setValue(CHAT_SPAM_ACTIONS, spamActionList); } @@ -210,27 +212,27 @@ public class DefaultConfiguration extends Configuration { w(w, "# - Then comes the 'message', depending on where the action is used, different keywords in [ ] may be used"); w(w, ""); w(w, "# Gives a very short log message of the violation, only containing name, violation type and total violation value, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log moveLogLowShort 3 15 low NC: [player] failed [check]"); - w(w, "log moveLogMedShort 0 15 med NC: [player] failed [check]"); - w(w, "log moveLogHighShort 0 15 high NC: [player] failed [check]"); + w(w, "log moveLogLowShort 3 15 low [player] failed [check]"); + w(w, "log moveLogMedShort 0 15 med [player] failed [check]"); + w(w, "log moveLogHighShort 0 15 high [player] failed [check]"); w(w, ""); w(w, "# Gives a log message of the violation, only containing name, violation type and total violation value, at most once every second, only if more than 5 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log morepacketsLow 5 1 low NC: [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); - w(w, "log morepacketsMed 0 1 med NC: [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); - w(w, "log morepacketsHigh 0 1 high NC: [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsLow 5 1 low [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsMed 0 1 med [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); + w(w, "log morepacketsHigh 0 1 high [player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]."); w(w, ""); w(w, "# Gives a lengthy log message of the violation, containing name, location, violation type and total violation, at most once every 15 seconds, only if more than 3 violations happened within the last minute (low) and immediatly (med,high)"); - w(w, "log moveLogLowLong 3 15 low NC: [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); - w(w, "log moveLogMedLong 0 15 med NC: [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); - w(w, "log moveLogHighLong 0 15 high NC: [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogLowLong 3 15 low [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogMedLong 0 15 med [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); + w(w, "log moveLogHighLong 0 15 high [player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]."); w(w, ""); w(w, "# Some other log messages that are limited a bit by default, to avoid too extreme spam"); - w(w, "log reachLog 0 1 med NC: [player] failed [check]: tried to interact with a block over distance [reachdistance]."); - w(w, "log directionLog 2 1 med NC: [player] failed [check]: tried to destroy a block out of line of sight."); - w(w, "log onliquidLog 2 1 med NC: [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst]."); - w(w, "log spamLog 0 4 med NC: [player] failed [check]: Last sent message \"[text]\"."); - w(w, "log nofallLog 0 1 med NC: [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks."); - w(w, "log fightDirectionLog 0 5 med NC: [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]"); + w(w, "log reachLog 0 1 med [player] failed [check]: tried to interact with a block over distance [reachdistance]."); + w(w, "log directionLog 2 1 med [player] failed [check]: tried to destroy a block out of line of sight."); + w(w, "log onliquidLog 2 1 med [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst]."); + w(w, "log spamLog 0 4 med [player] failed [check]: Last sent message \"[text]\"."); + w(w, "log nofallLog 0 1 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks."); + w(w, "log fightDirectionLog 0 5 med [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]"); w(w, ""); w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event."); w(w, "# - They start with the word 'special'"); @@ -255,7 +257,8 @@ public class DefaultConfiguration extends Configuration { w(w, "# - Then comes the command. You can use the same [ ] that you use for log actions. You'll most likely want to use [player] at some point."); w(w, ""); w(w, "# E.g. Kick a player"); - w(w, "consolecommand kick 0 0 kick [player]"); + w(w, "consolecommand kick 0 1 kick [player]"); + w(w, "consolecommand spamkick 0 1 kick [player]"); w.flush(); w.close(); } catch(IOException e) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java index 57bc27f3..2832d141 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/cache/CCLogging.java @@ -3,13 +3,12 @@ package cc.co.evenprime.bukkit.nocheat.config.cache; import java.util.logging.Logger; import cc.co.evenprime.bukkit.nocheat.config.Configuration; +import cc.co.evenprime.bukkit.nocheat.log.Colors; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; /** * Configurations specific for logging. Every world gets one of these. * - * @author Evenprime - * */ public class CCLogging { @@ -18,10 +17,12 @@ public class CCLogging { public final LogLevel chatLevel; public final Logger filelogger; public final boolean active; + public final String prefix; public CCLogging(Configuration data, Logger worldSpecificFileLogger) { active = data.getBoolean(Configuration.LOGGING_ACTIVE); + prefix = Colors.replaceColors(data.getString(Configuration.LOGGING_PREFIX)); fileLevel = data.getLogLevel(Configuration.LOGGING_FILELEVEL); consoleLevel = data.getLogLevel(Configuration.LOGGING_CONSOLELEVEL); chatLevel = data.getLogLevel(Configuration.LOGGING_CHATLEVEL); diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java b/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java index cd239d1a..e7ef3e27 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/BaseData.java @@ -11,7 +11,7 @@ public class BaseData extends Data { public final MovingData moving; public final FightData fight; - private final Data[] data; + private final Data[] data; // for convenience private long removalTime; diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/DataManager.java b/src/cc/co/evenprime/bukkit/nocheat/data/DataManager.java index 9604532b..d2067e82 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/DataManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/DataManager.java @@ -59,18 +59,18 @@ public class DataManager { * */ public void queueForRemoval(Player player) { - BaseData bd = this.map.get(player); + BaseData data = this.map.get(player); - if(bd != null) { - bd.markForRemoval(true); + if(data != null) { + data.markForRemoval(true); } } public void unqueueForRemoval(Player player) { - BaseData bd = this.map.get(player); + BaseData data = this.map.get(player); - if(bd != null) { - bd.markForRemoval(false); + if(data != null) { + data.markForRemoval(false); } } @@ -98,7 +98,9 @@ public class DataManager { public void clearCriticalData(Player player) { BaseData data = this.map.get(player); - data.clearCriticalData(); + if(data != null) { + data.clearCriticalData(); + } } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java b/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java new file mode 100644 index 00000000..2967eda9 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/log/Colors.java @@ -0,0 +1,19 @@ +package cc.co.evenprime.bukkit.nocheat.log; + +import org.bukkit.ChatColor; + +/** + * Somehow manage color codes in NoCheat + * + */ +public class Colors { + + public static String replaceColors(String text) { + + for(ChatColor c : ChatColor.values()) { + text = text.replace("&" + Integer.toHexString(c.getCode()), c.toString()); + } + + return text; + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java b/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java index 50d1d871..269d7e55 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/log/LogManager.java @@ -3,6 +3,7 @@ package cc.co.evenprime.bukkit.nocheat.log; import java.util.logging.Logger; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import cc.co.evenprime.bukkit.nocheat.config.Permissions; @@ -13,8 +14,6 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; * specific place or go through configuration/permissions to decide if and where * the message will be visible * - * @author Evenprime - * */ public class LogManager { @@ -35,11 +34,11 @@ public class LogManager { return; if(cc.logging.fileLevel.matches(level)) { - logToFile(level, message, cc.logging.filelogger); + logToFile(level, ChatColor.stripColor(message), cc.logging.filelogger); } if(cc.logging.consoleLevel.matches(level)) { - logToConsole(level, message); + logToConsole(level, ChatColor.stripColor(message)); } if(cc.logging.chatLevel.matches(level)) {