Colors! And getting kicked for extensive (command) spamming by default

now
This commit is contained in:
Evenprime 2011-10-17 21:22:26 +02:00
parent c87f99262e
commit 08ef299290
11 changed files with 64 additions and 41 deletions

View File

@ -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++;

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -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)) {