diff options
5 files changed, 157 insertions, 298 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/ConfigurationManager.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/ConfigurationManager.java index 283ad88d2..039254889 100644 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/ConfigurationManager.java +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/ConfigurationManager.java @@ -5,10 +5,8 @@ import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.logging.*; +import org.bukkit.configuration.file.FileConfiguration; /** @@ -17,9 +15,8 @@ import java.util.logging.*; */ public class ConfigurationManager { - private final static String configFileName = "config.yml"; - private final Map<String, ConfigurationCacheStore> worldnameToConfigCacheMap = new HashMap<String, ConfigurationCacheStore>(); private FileHandler fileHandler; + private ConfigurationCacheStore cache; private final NoCheat plugin; @@ -58,12 +55,10 @@ public class ConfigurationManager public ConfigurationManager(NoCheat plugin, File rootConfigFolder) { - this.plugin = plugin; // Setup the real configuration initializeConfig(rootConfigFolder); - } /** @@ -73,105 +68,19 @@ public class ConfigurationManager */ private void initializeConfig(File rootConfigFolder) { - - // First try to obtain and parse the global config file - NoCheatConfiguration root = new NoCheatConfiguration(); - root.setDefaults(new DefaultConfiguration()); - root.options().copyDefaults(true); - root.options().copyHeader(true); - - File globalConfigFile = getGlobalConfigFile(rootConfigFolder); - - if (globalConfigFile.exists()) - { - try - { - root.load(globalConfigFile); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - try - { - root.save(globalConfigFile); - } - catch (Exception e) - { - e.printStackTrace(); - } + FileConfiguration conf = plugin.getConfig(); + conf.options().copyDefaults(true); + conf.options().copyHeader(true); + plugin.saveConfig(); + NoCheatConfiguration root = new NoCheatConfiguration(conf); root.regenerateActionLists(); // Create a corresponding Configuration Cache // put the global config on the config map - worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root)); + cache = new ConfigurationCacheStore(root); plugin.setFileLogger(setupFileLogger(new File(rootConfigFolder, root.getString(ConfPaths.LOGGING_FILENAME)))); - - // Try to find world-specific config files - Map<String, File> worldFiles = getWorldSpecificConfigFiles(rootConfigFolder); - - for (Entry<String, File> worldEntry : worldFiles.entrySet()) - { - - File worldConfigFile = worldEntry.getValue(); - - NoCheatConfiguration world = new NoCheatConfiguration(); - world.setDefaults(root); - - try - { - world.load(worldConfigFile); - - worldnameToConfigCacheMap.put(worldEntry.getKey(), new ConfigurationCacheStore(world)); - - // write the config file back to disk immediately - world.save(worldConfigFile); - - } - catch (Exception e) - { - plugin.getLogger().warning("Couldn't load world-specific config for " + worldEntry.getKey()); - e.printStackTrace(); - } - - world.regenerateActionLists(); - } - } - - private static File getGlobalConfigFile(File rootFolder) - { - - File globalConfig = new File(rootFolder, configFileName); - - return globalConfig; - } - - private static Map<String, File> getWorldSpecificConfigFiles(File rootFolder) - { - - HashMap<String, File> files = new HashMap<String, File>(); - - if (rootFolder.isDirectory()) - { - for (File f : rootFolder.listFiles()) - { - if (f.isFile()) - { - String filename = f.getName(); - if (filename.matches(".+_" + configFileName + "$")) - { - // Get the first part = world name - String worldname = filename.substring(0, filename.length() - (configFileName.length() + 1)); - files.put(worldname, f); - } - } - } - } - return files; } private Logger setupFileLogger(File logfile) @@ -237,21 +146,6 @@ public class ConfigurationManager */ public ConfigurationCacheStore getConfigurationCacheForWorld(String worldname) { - - ConfigurationCacheStore cache = worldnameToConfigCacheMap.get(worldname); - - if (cache != null) - { - return cache; - } - else - { - // Enter a reference to the cache under the new name - // to be faster in looking it up later - cache = worldnameToConfigCacheMap.get(null); - worldnameToConfigCacheMap.put(worldname, cache); - - return cache; - } + return cache; } } diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/DefaultConfiguration.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/DefaultConfiguration.java deleted file mode 100644 index fd61cac5d..000000000 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/DefaultConfiguration.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.earth2me.essentials.anticheat.config; - - -/** - * These are the default settings for NoCheat. They will be used in addition to/in replacement of configurations given - * in the config.yml file - * - */ -public class DefaultConfiguration extends NoCheatConfiguration -{ - public DefaultConfiguration() - { - - super(); - - this.options().header("Main configuration file for NoCheat. Read \"Instructions.txt\""); - - /** - * LOGGING * - */ - set(ConfPaths.LOGGING_ACTIVE, true); - set(ConfPaths.LOGGING_SHOWACTIVECHECKS, false); - set(ConfPaths.LOGGING_DEBUGMESSAGES, false); - set(ConfPaths.LOGGING_PREFIX, "&4NC&f: "); - set(ConfPaths.LOGGING_FILENAME, "nocheat.log"); - set(ConfPaths.LOGGING_LOGTOFILE, true); - set(ConfPaths.LOGGING_LOGTOCONSOLE, true); - set(ConfPaths.LOGGING_LOGTOINGAMECHAT, true); - - /** - * * INVENTORY ** - */ - set(ConfPaths.INVENTORY_DROP_CHECK, true); - set(ConfPaths.INVENTORY_DROP_TIMEFRAME, 20); - set(ConfPaths.INVENTORY_DROP_LIMIT, 100); - set(ConfPaths.INVENTORY_DROP_ACTIONS, "log:drop:0:1:cif cmd:kick"); - - set(ConfPaths.INVENTORY_INSTANTBOW_CHECK, true); - set(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, "log:ibow:2:5:if cancel"); - - set(ConfPaths.INVENTORY_INSTANTEAT_CHECK, true); - set(ConfPaths.INVENTORY_INSTANTEAT_ACTIONS, "log:ieat:2:5:if cancel"); - - /** - * * MOVING ** - */ - set(ConfPaths.MOVING_RUNFLY_CHECK, true); - set(ConfPaths.MOVING_RUNFLY_ALLOWFASTSNEAKING, false); - set(ConfPaths.MOVING_RUNFLY_ACTIONS, "log:moveshort:3:5:f cancel vl>100 log:moveshort:0:5:if cancel vl>400 log:movelong:0:5:cif cancel"); - - set(ConfPaths.MOVING_RUNFLY_CHECKNOFALL, true); - set(ConfPaths.MOVING_RUNFLY_NOFALLAGGRESSIVE, true); - set(ConfPaths.MOVING_RUNFLY_NOFALLACTIONS, "log:nofall:0:5:cif cancel"); - - set(ConfPaths.MOVING_RUNFLY_FLYING_ALLOWALWAYS, false); - set(ConfPaths.MOVING_RUNFLY_FLYING_ALLOWINCREATIVE, true); - set(ConfPaths.MOVING_RUNFLY_FLYING_SPEEDLIMITHORIZONTAL, 60); - set(ConfPaths.MOVING_RUNFLY_FLYING_SPEEDLIMITVERTICAL, 100); - set(ConfPaths.MOVING_RUNFLY_FLYING_HEIGHTLIMIT, 128); - set(ConfPaths.MOVING_RUNFLY_FLYING_ACTIONS, "log:moveshort:3:5:f cancel vl>100 log:moveshort:0:5:if cancel vl>400 log:movelong:0:5:cif cancel"); - - set(ConfPaths.MOVING_MOREPACKETS_CHECK, true); - set(ConfPaths.MOVING_MOREPACKETS_ACTIONS, "log:morepackets:3:2:if cancel vl>20 log:morepackets:0:2:if cancel"); - - /** - * * BLOCKBREAK ** - */ - set(ConfPaths.BLOCKBREAK_REACH_CHECK, true); - set(ConfPaths.BLOCKBREAK_REACH_ACTIONS, "cancel vl>5 log:bbreach:0:2:if cancel"); - - set(ConfPaths.BLOCKBREAK_DIRECTION_CHECK, true); - set(ConfPaths.BLOCKBREAK_DIRECTION_PRECISION, 50); - set(ConfPaths.BLOCKBREAK_DIRECTION_PENALTYTIME, 300); - set(ConfPaths.BLOCKBREAK_DIRECTION_ACTIONS, "cancel vl>10 log:bbdirection:0:5:if cancel"); - - set(ConfPaths.BLOCKBREAK_NOSWING_CHECK, true); - set(ConfPaths.BLOCKBREAK_NOSWING_ACTIONS, "log:bbnoswing:3:2:if cancel"); - - /** - * * BLOCKPLACE ** - */ - set(ConfPaths.BLOCKPLACE_REACH_CHECK, true); - set(ConfPaths.BLOCKPLACE_REACH_ACTIONS, "cancel vl>5 log:bpreach:0:2:if cancel"); - - set(ConfPaths.BLOCKPLACE_DIRECTION_CHECK, true); - set(ConfPaths.BLOCKPLACE_DIRECTION_PRECISION, 75); - set(ConfPaths.BLOCKPLACE_DIRECTION_PENALTYTIME, 100); - set(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS, "cancel vl>10 log:bpdirection:0:3:if cancel"); - - /** - * * CHAT ** - */ - set(ConfPaths.CHAT_COLOR_CHECK, true); - set(ConfPaths.CHAT_COLOR_ACTIONS, "log:color:0:1:if cancel"); - - set(ConfPaths.CHAT_SPAM_CHECK, true); - set(ConfPaths.CHAT_SPAM_WHITELIST, ""); - set(ConfPaths.CHAT_SPAM_TIMEFRAME, 3); - set(ConfPaths.CHAT_SPAM_MESSAGELIMIT, 3); - set(ConfPaths.CHAT_SPAM_COMMANDLIMIT, 12); - set(ConfPaths.CHAT_SPAM_ACTIONS, "log:spam:0:3:if cancel vl>30 log:spam:0:3:cif cancel cmd:kick"); - - /** - * * FIGHT ** - */ - set(ConfPaths.FIGHT_DIRECTION_CHECK, true); - set(ConfPaths.FIGHT_DIRECTION_PRECISION, 75); - set(ConfPaths.FIGHT_DIRECTION_PENALTYTIME, 500); - set(ConfPaths.FIGHT_DIRECTION_ACTIONS, "cancel vl>5 log:fdirection:3:5:f cancel vl>20 log:fdirection:0:5:if cancel vl>50 log:fdirection:0:5:cif cancel"); - - set(ConfPaths.FIGHT_NOSWING_CHECK, true); - set(ConfPaths.FIGHT_NOSWING_ACTIONS, "log:fnoswing:0:5:cif cancel"); - - set(ConfPaths.FIGHT_REACH_CHECK, true); - set(ConfPaths.FIGHT_REACH_LIMIT, 400); - set(ConfPaths.FIGHT_REACH_PENALTYTIME, 500); - set(ConfPaths.FIGHT_REACH_ACTIONS, "cancel vl>10 log:freach:2:5:if cancel"); - - set(ConfPaths.FIGHT_SPEED_CHECK, true); - set(ConfPaths.FIGHT_SPEED_ATTACKLIMIT, 15); - set(ConfPaths.FIGHT_SPEED_ACTIONS, "log:fspeed:0:5:if cancel"); - - set(ConfPaths.FIGHT_GODMODE_CHECK, true); - set(ConfPaths.FIGHT_GODMODE_ACTIONS, "log:fgod:2:5:if cancel"); - - set(ConfPaths.FIGHT_INSTANTHEAL_CHECK, true); - set(ConfPaths.FIGHT_INSTANTHEAL_ACTIONS, "log:fheal:1:1:if cancel"); - - set(ConfPaths.STRINGS + ".drop", "[player] failed [check]: Tried to drop more items than allowed. VL [violations]"); - set(ConfPaths.STRINGS + ".moveshort", "[player] failed [check]. VL [violations]"); - set(ConfPaths.STRINGS + ".movelong", "[player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]"); - set(ConfPaths.STRINGS + ".nofall", "[player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]"); - set(ConfPaths.STRINGS + ".morepackets", "[player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]"); - set(ConfPaths.STRINGS + ".bbreach", "[player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]"); - set(ConfPaths.STRINGS + ".bbdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]"); - set(ConfPaths.STRINGS + ".bbnoswing", "[player] failed [check]: Didn't swing arm. VL [violations]"); - set(ConfPaths.STRINGS + ".bpreach", "[player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]"); - set(ConfPaths.STRINGS + ".bpdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]"); - set(ConfPaths.STRINGS + ".color", "[player] failed [check]: Sent colored chat message '[text]'. VL [violations]"); - set(ConfPaths.STRINGS + ".spam", "[player] failed [check]: Last sent message '[text]'. VL [violations]"); - set(ConfPaths.STRINGS + ".fdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]"); - set(ConfPaths.STRINGS + ".freach", "[player] failed [check]: tried to attack entity out of reach. VL [violations]"); - set(ConfPaths.STRINGS + ".fspeed", "[player] failed [check]: tried to attack more than [limit] times per second. VL [violations]"); - set(ConfPaths.STRINGS + ".fnoswing", "[player] failed [check]: Didn't swing arm. VL [violations]"); - set(ConfPaths.STRINGS + ".fgod", "[player] failed [check]: Avoided taking damage or lagging. VL [violations]"); - set(ConfPaths.STRINGS + ".fheal", "[player] failed [check]: Tried to regenerate health faster than normal. VL [violations]"); - set(ConfPaths.STRINGS + ".ibow", "[player] failed [check]: Fires bow to fast. VL [violations]"); - set(ConfPaths.STRINGS + ".ieat", "[player] failed [check]: Eats food [food] too fast. VL [violations]"); - set(ConfPaths.STRINGS + ".kick", "kick [player]"); - - // Update internal factory based on all the new entries to the "actions" section - regenerateActionLists(); - } -} diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/NoCheatConfiguration.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/NoCheatConfiguration.java index e137ff480..4172174c9 100644 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/NoCheatConfiguration.java +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/config/NoCheatConfiguration.java @@ -2,36 +2,17 @@ package com.earth2me.essentials.anticheat.config; import com.earth2me.essentials.anticheat.actions.Action; import com.earth2me.essentials.anticheat.actions.types.ActionList; -import java.lang.reflect.Field; -import org.bukkit.configuration.MemorySection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.yaml.snakeyaml.DumperOptions; +import org.bukkit.configuration.file.FileConfiguration; -public class NoCheatConfiguration extends YamlConfiguration +public class NoCheatConfiguration { private ActionFactory factory; + private FileConfiguration conf; - @Override - public String saveToString() + public NoCheatConfiguration(FileConfiguration conf) { - // Some reflection wizardry to avoid having a lot of - // linebreaks in the yml file, and get a "footer" into the file - try - { - Field op; - op = YamlConfiguration.class.getDeclaredField("yamlOptions"); - op.setAccessible(true); - DumperOptions options = (DumperOptions)op.get(this); - options.setWidth(200); - } - catch (Exception e) - { - } - - String result = super.saveToString(); - - return result; + this.conf = conf; } /** @@ -39,7 +20,7 @@ public class NoCheatConfiguration extends YamlConfiguration */ public void regenerateActionLists() { - factory = new ActionFactory(((MemorySection)this.get(ConfPaths.STRINGS)).getValues(false)); + factory = new ActionFactory(conf.getConfigurationSection(ConfPaths.STRINGS).getValues(false)); } /** @@ -50,8 +31,7 @@ public class NoCheatConfiguration extends YamlConfiguration */ public ActionList getActionList(String path, String permission) { - - String value = this.getString(path); + String value = conf.getString(path); return factory.createActionList(value, permission); } @@ -77,6 +57,26 @@ public class NoCheatConfiguration extends YamlConfiguration } } - set(path, string.toString().trim()); + conf.set(path, string.toString().trim()); + } + + public int getInt(String path) + { + return conf.getInt(path); + } + + public int getInt(String path, int def) + { + return conf.getInt(path, def); + } + + public boolean getBoolean(String path) + { + return conf.getBoolean(path); + } + + public String getString(String path) + { + return conf.getString(path); } } diff --git a/EssentialsAntiCheat/src/config.yml b/EssentialsAntiCheat/src/config.yml new file mode 100644 index 000000000..81882dea8 --- /dev/null +++ b/EssentialsAntiCheat/src/config.yml @@ -0,0 +1,119 @@ +# Main configuration file for NoCheat. Read "Instructions.txt" +logging: + active: true + showactivechecks: false + debugmessages: false + prefix: '&4NC&f: ' + filename: nocheat.log + file: true + console: true + ingamechat: true +checks: + inventory: + drop: + active: true + time: 20 + limit: 100 + actions: log:drop:0:1:cif cmd:kick + instantbow: + active: true + actions: log:ibow:2:5:if cancel + instanteat: + active: true + actions: log:ieat:2:5:if cancel + moving: + runfly: + active: true + allowfastsneaking: false + actions: log:moveshort:3:5:f cancel vl>100 log:moveshort:0:5:if cancel vl>400 log:movelong:0:5:cif cancel + checknofall: true + nofallaggressivemode: true + nofallactions: log:nofall:0:5:cif cancel + flying: + allowflyingalways: false + allowflyingincreative: true + flyingspeedlimithorizontal: 60 + flyingspeedlimitvertical: 100 + flyingheightlimit: 128 + actions: log:moveshort:3:5:f cancel vl>100 log:moveshort:0:5:if cancel vl>400 log:movelong:0:5:cif cancel + morepackets: + active: true + actions: log:morepackets:3:2:if cancel vl>20 log:morepackets:0:2:if cancel + blockbreak: + reach: + active: true + actions: cancel vl>5 log:bbreach:0:2:if cancel + direction: + active: true + precision: 50 + penaltytime: 300 + actions: cancel vl>10 log:bbdirection:0:5:if cancel + noswing: + active: true + actions: log:bbnoswing:3:2:if cancel + blockplace: + reach: + active: true + actions: cancel vl>5 log:bpreach:0:2:if cancel + direction: + active: true + precision: 75 + penaltytime: 100 + actions: cancel vl>10 log:bpdirection:0:3:if cancel + chat: + color: + active: true + actions: log:color:0:1:if cancel + spam: + active: true + whitelist: '' + timeframe: 3 + messagelimit: 3 + commandlimit: 12 + actions: log:spam:0:3:if cancel vl>30 log:spam:0:3:cif cancel cmd:kick + fight: + direction: + active: true + precision: 75 + penaltytime: 500 + actions: cancel vl>5 log:fdirection:3:5:f cancel vl>20 log:fdirection:0:5:if cancel vl>50 log:fdirection:0:5:cif cancel + noswing: + active: true + actions: log:fnoswing:0:5:cif cancel + reach: + active: true + distance: 400 + penaltytime: 500 + actions: cancel vl>10 log:freach:2:5:if cancel + speed: + active: true + attacklimit: 15 + actions: log:fspeed:0:5:if cancel + godmode: + active: true + actions: log:fgod:2:5:if cancel + instantheal: + active: true + actions: log:fheal:1:1:if cancel +strings: + drop: '[player] failed [check]: Tried to drop more items than allowed. VL [violations]' + moveshort: '[player] failed [check]. VL [violations]' + movelong: '[player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]' + nofall: '[player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]' + morepackets: '[player] failed [check]: Sent [packets] more packets than expected. Total violation level [violations]' + bbreach: '[player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]' + bbdirection: '[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]' + bbnoswing: '[player] failed [check]: Didn''t swing arm. VL [violations]' + bpreach: '[player] failed [check]: tried to interact with a block over distance [reachdistance]. VL [violations]' + bpdirection: '[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]' + color: '[player] failed [check]: Sent colored chat message ''[text]''. VL [violations]' + spam: '[player] failed [check]: Last sent message ''[text]''. VL [violations]' + fdirection: '[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]' + freach: '[player] failed [check]: tried to attack entity out of reach. VL [violations]' + fspeed: '[player] failed [check]: tried to attack more than [limit] times per second. VL [violations]' + fnoswing: '[player] failed [check]: Didn''t swing arm. VL [violations]' + fgod: '[player] failed [check]: Avoided taking damage or lagging. VL [violations]' + fheal: '[player] failed [check]: Tried to regenerate health faster than normal. VL [violations]' + ibow: '[player] failed [check]: Fires bow to fast. VL [violations]' + ieat: '[player] failed [check]: Eats food [food] too fast. VL [violations]' + kick: kick [player] diff --git a/EssentialsAntiCheat/src/plugin.yml b/EssentialsAntiCheat/src/plugin.yml index a1a5afac9..a67825ec9 100644 --- a/EssentialsAntiCheat/src/plugin.yml +++ b/EssentialsAntiCheat/src/plugin.yml @@ -2,7 +2,7 @@ name: EssentialsAntiCheat main: com.earth2me.essentials.anticheat.NoCheat # Note to developers: This next line cannot change, or the automatic versioning system will break. version: ${build.number} -website: http://tiny.cc/EssentialsWiki +website: ${project.url} description: Detect and Fight the exploitation of various Flaws/Bugs in Minecraft. authors: [Evenprime, md_5] commands: |