summaryrefslogtreecommitdiffstats
path: root/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types')
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionList.java86
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionWithParameters.java94
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ConsolecommandAction.java39
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/DummyAction.java26
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/LogAction.java76
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/SpecialAction.java22
6 files changed, 343 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionList.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionList.java
new file mode 100644
index 000000000..25a7ba296
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionList.java
@@ -0,0 +1,86 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.actions.Action;
+import java.util.*;
+
+
+/**
+ * A list of actions, that associates actions to tresholds. It allows to retrieve all actions that match a certain
+ * treshold
+ *
+ */
+public class ActionList
+{
+ // This is a very bad design decision, but it's also really
+ // convenient to define this here
+ public final String permissionSilent;
+
+ public ActionList(String permission)
+ {
+ this.permissionSilent = permission + ".silent";
+ }
+ // If there are no actions registered, we still return an Array. It's
+ // just empty/size=0
+ private final static Action[] emptyArray = new Action[0];
+ // The actions of this ActionList, "bundled" by treshold (violation level)
+ private final Map<Integer, Action[]> actions = new HashMap<Integer, Action[]>();
+ // The tresholds of this list
+ private final List<Integer> tresholds = new ArrayList<Integer>();
+
+ /**
+ * Add an entry to this actionList. The list will be sorted by tresholds automatically after the insertion.
+ *
+ * @param treshold The minimum violation level a player needs to have to be suspected to the given actions
+ * @param actions The actions that will be used if the player reached the accompanying treshold/violation level
+ */
+ public void setActions(Integer treshold, Action[] actions)
+ {
+
+ if (!this.tresholds.contains(treshold))
+ {
+ this.tresholds.add(treshold);
+ Collections.sort(this.tresholds);
+ }
+
+ this.actions.put(treshold, actions);
+ }
+
+ /**
+ * Get a list of actions that match the violation level. The only method that has to be called by a check
+ *
+ * @param violationLevel The violation level that should be matched.
+ * @return The array of actions whose treshold was closest to the violationLevel but not bigger
+ */
+ public Action[] getActions(double violationLevel)
+ {
+
+ Integer result = null;
+
+ for (Integer treshold : tresholds)
+ {
+ if (treshold <= violationLevel)
+ {
+ result = treshold;
+ }
+ }
+
+ if (result != null)
+ {
+ return actions.get(result);
+ }
+ else
+ {
+ return emptyArray;
+ }
+ }
+
+ /**
+ * Get a sorted list of the tresholds/violation levels that were used in this list
+ *
+ * @return The sorted list of tresholds
+ */
+ public List<Integer> getTresholds()
+ {
+ return tresholds;
+ }
+}
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionWithParameters.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionWithParameters.java
new file mode 100644
index 000000000..c07d20198
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ActionWithParameters.java
@@ -0,0 +1,94 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.NoCheatPlayer;
+import com.earth2me.essentials.anticheat.actions.Action;
+import com.earth2me.essentials.anticheat.actions.ParameterName;
+import com.earth2me.essentials.anticheat.checks.Check;
+import java.util.ArrayList;
+
+
+/**
+ * Action with parameters is used to
+ *
+ */
+public abstract class ActionWithParameters extends Action
+{
+ private final ArrayList<Object> messageParts;
+
+ public ActionWithParameters(String name, int delay, int repeat, String message)
+ {
+ super(name, delay, repeat);
+
+ messageParts = new ArrayList<Object>();
+
+ parseMessage(message);
+ }
+
+ private void parseMessage(String message)
+ {
+ String parts[] = message.split("\\[", 2);
+
+ // No opening braces left
+ if (parts.length != 2)
+ {
+ messageParts.add(message);
+ }
+ // Found an opening brace
+ else
+ {
+ String parts2[] = parts[1].split("\\]", 2);
+
+ // Found no matching closing brace
+ if (parts2.length != 2)
+ {
+ messageParts.add(message);
+ }
+ // Found a matching closing brace
+ else
+ {
+ ParameterName w = ParameterName.get(parts2[0]);
+
+ if (w != null)
+ {
+ // Found an existing wildcard inbetween the braces
+ messageParts.add(parts[0]);
+ messageParts.add(w);
+
+ // Go further down recursive
+ parseMessage(parts2[1]);
+ }
+ else
+ {
+ messageParts.add(message);
+ }
+ }
+ }
+ }
+
+ /**
+ * Get a string with all the wildcards replaced with data from LogData
+ *
+ * @param data
+ * @return
+ */
+ protected String getMessage(NoCheatPlayer player, Check check)
+ {
+
+ StringBuilder log = new StringBuilder(100); // Should be big enough most
+ // of the time
+
+ for (Object part : messageParts)
+ {
+ if (part instanceof String)
+ {
+ log.append((String)part);
+ }
+ else
+ {
+ log.append(check.getParameter((ParameterName)part, player));
+ }
+ }
+
+ return log.toString();
+ }
+}
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ConsolecommandAction.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ConsolecommandAction.java
new file mode 100644
index 000000000..5af889c16
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/ConsolecommandAction.java
@@ -0,0 +1,39 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.NoCheatPlayer;
+import com.earth2me.essentials.anticheat.checks.Check;
+
+
+/**
+ * Execute a command by imitating an admin typing the command directly into the console
+ *
+ */
+public class ConsolecommandAction extends ActionWithParameters
+{
+ public ConsolecommandAction(String name, int delay, int repeat, String command)
+ {
+ // Log messages may have color codes now
+ super(name, delay, repeat, command);
+ }
+
+ /**
+ * Fill in the placeholders ( stuff that looks like '[something]') with information, make a nice String out of it
+ * that can be directly used as a command in the console.
+ *
+ * @param player The player that is used to fill in missing data
+ * @param check The check that is used to fill in missing data
+ * @return The complete, ready to use, command
+ */
+ public String getCommand(NoCheatPlayer player, Check check)
+ {
+ return super.getMessage(player, check);
+ }
+
+ /**
+ * Convert the commands data into a string that can be used in the config files
+ */
+ public String toString()
+ {
+ return "cmd:" + name + ":" + delay + ":" + repeat;
+ }
+}
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/DummyAction.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/DummyAction.java
new file mode 100644
index 000000000..d89372144
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/DummyAction.java
@@ -0,0 +1,26 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.actions.Action;
+
+
+/**
+ * If an action can't be parsed correctly, at least keep it stored in this form to not lose it when loading/storing the
+ * config file
+ *
+ */
+public class DummyAction extends Action
+{
+ // The original string used for this action definition
+ private final String def;
+
+ public DummyAction(String def)
+ {
+ super("dummyAction", 10000, 10000);
+ this.def = def;
+ }
+
+ public String toString()
+ {
+ return def;
+ }
+}
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/LogAction.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/LogAction.java
new file mode 100644
index 000000000..16830b8d7
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/LogAction.java
@@ -0,0 +1,76 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.NoCheatPlayer;
+import com.earth2me.essentials.anticheat.checks.Check;
+
+
+/**
+ * Print a log message to various locations
+ *
+ */
+public class LogAction extends ActionWithParameters
+{
+ // Some flags to decide where the log message should show up, based on
+ // the config file
+ private final boolean toChat;
+ private final boolean toConsole;
+ private final boolean toFile;
+
+ public LogAction(String name, int delay, int repeat, boolean toChat, boolean toConsole, boolean toFile, String message)
+ {
+ super(name, delay, repeat, message);
+ this.toChat = toChat;
+ this.toConsole = toConsole;
+ this.toFile = toFile;
+ }
+
+ /**
+ * Parse the final log message out of various data from the player and check that triggered the action.
+ *
+ * @param player The player that is used as a source for the log message
+ * @param check The check that is used as a source for the log message
+ * @return
+ */
+ public String getLogMessage(NoCheatPlayer player, Check check)
+ {
+ return super.getMessage(player, check);
+ }
+
+ /**
+ * Should the message be shown in chat?
+ *
+ * @return true, if yes
+ */
+ public boolean toChat()
+ {
+ return toChat;
+ }
+
+ /**
+ * Should the message be shown in the console?
+ *
+ * @return true, if yes
+ */
+ public boolean toConsole()
+ {
+ return toConsole;
+ }
+
+ /**
+ * Should the message be written to the logfile?
+ *
+ * @return true, if yes
+ */
+ public boolean toFile()
+ {
+ return toFile;
+ }
+
+ /**
+ * Create the string that's used to define the action in the logfile
+ */
+ public String toString()
+ {
+ return "log:" + name + ":" + delay + ":" + repeat + ":" + (toConsole ? "c" : "") + (toChat ? "i" : "") + (toFile ? "f" : "");
+ }
+}
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/SpecialAction.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/SpecialAction.java
new file mode 100644
index 000000000..5e4a93b3d
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/actions/types/SpecialAction.java
@@ -0,0 +1,22 @@
+package com.earth2me.essentials.anticheat.actions.types;
+
+import com.earth2me.essentials.anticheat.actions.Action;
+
+
+/**
+ * Do something check-specific. Usually that is to cancel the event, undo something the player did, or do something the
+ * server should've done
+ *
+ */
+public class SpecialAction extends Action
+{
+ public SpecialAction()
+ {
+ super("cancel", 0, 0);
+ }
+
+ public String toString()
+ {
+ return "cancel";
+ }
+}