From 4a8f19ef7aab603cef817419d518f4885af8040a Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 28 Nov 2015 21:09:10 +0100 Subject: [PATCH] Log all violations for on-the-fly debugging by default, configurable. This reduces the complexity of explanation :). Performance savers can turn it off, to prevent the hook registering at all. --- .../nocheatplus/config/ConfPaths.java | 1 + .../nocheatplus/config/DefaultConfig.java | 1 + .../allviolations/AllViolationsConfig.java | 10 +++++-- .../allviolations/AllViolationsHook.java | 29 ++++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index d9ae91df..295d8930 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -51,6 +51,7 @@ public abstract class ConfPaths { private static final String LOGGING_EXTENDED = LOGGING + "extended."; public static final String LOGGING_EXTENDED_STATUS = LOGGING_EXTENDED + "status"; private static final String LOGGING_EXTENDED_ALLVIOLATIONS = LOGGING_EXTENDED + "allviolations."; + public static final String LOGGING_EXTENDED_ALLVIOLATIONS_DEBUG = LOGGING_EXTENDED_ALLVIOLATIONS + "debug"; public static final String LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY = LOGGING_EXTENDED_ALLVIOLATIONS + "debugonly"; private static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND = LOGGING_EXTENDED_ALLVIOLATIONS + "backend."; public static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE = LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND + "trace"; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index ab755558..11e27bbd 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -40,6 +40,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.LOGGING_ACTIVE, true); set(ConfPaths.LOGGING_MAXQUEUESIZE, 5000); set(ConfPaths.LOGGING_EXTENDED_STATUS, false); + set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUG, true); set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY, false); set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE, false); set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY, false); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java index b6f28bf1..5b26afe1 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java @@ -15,7 +15,10 @@ public class AllViolationsConfig { /** Log all violations to the in-game notification channel. */ public final boolean allToNotify; - + + /** Log all violations for players/checks for which debug flags are set. */ + public final boolean debug; + /** Only log if the player is being "debugged". Currently incomplete. */ public final boolean debugOnly; @@ -23,13 +26,14 @@ public class AllViolationsConfig { // TODO: More filtering like in TestNCP. public AllViolationsConfig(ConfigFile config) { - debugOnly = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY); allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE); allToNotify = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY); + debug = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUG); + debugOnly = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY) || debug && !allToTrace && !allToNotify; } public boolean doesLogAnything() { - return allToTrace || allToNotify; + return allToTrace || allToNotify || debug; } } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java index 4d77de0c..574d6866 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java @@ -90,22 +90,31 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { if (config == null) { return false; } - if (config.debugOnly) { + boolean debugSet = false; + if (config.debugOnly || config.debug) { // TODO: Better mix the debug flag into IViolationInfo, for best performance. final CheckDataFactory factory = checkType.getDataFactory(); - if (factory == null) { - return false; - } - final ICheckData data = factory.getData(player); - if (data == null || !data.getDebug()) { + if (config.debugOnly && factory == null) { return false; + } else { + final ICheckData data = factory.getData(player); + if (data == null) { + if (config.debugOnly) { + return false; + } + } else { + debugSet = data.getDebug(); + if (config.debugOnly && !debugSet) { + return false; + } + } } } - log(checkType, player, info, config); + log(checkType, player, info, config.allToTrace || debugSet, config.allToNotify); return false; } - private void log(final CheckType checkType, final Player player, final IViolationInfo info, final AllViolationsConfig config) { + private void log(final CheckType checkType, final Player player, final IViolationInfo info, final boolean toTrace, final boolean toNotify) { // Generate the message. // TODO: More colors? final StringBuilder builder = new StringBuilder(300); @@ -130,10 +139,10 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { final String message = builder.toString(); // Send the message. final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager(); - if (config.allToNotify) { + if (toNotify) { logManager.info(Streams.NOTIFY_INGAME, message); } - if (config.allToTrace) { + if (toTrace) { logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message)); } }