Add a config option to log all violations only for debugged players.

This makes logging all violations potentially useful to use alongside
with the "ncp debug player" command in production environments. The flag
debugonly must be set with at least one backend being activated.
This commit is contained in:
asofold 2015-06-07 23:46:27 +02:00
parent f9a2172340
commit 0d7d179853
4 changed files with 34 additions and 10 deletions

View File

@ -52,8 +52,10 @@ 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_TRACE = LOGGING_EXTENDED_ALLVIOLATIONS + "trace";
public static final String LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY = LOGGING_EXTENDED_ALLVIOLATIONS + "notify";
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";
public static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY = LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND + "notify";
@GlobalConfig
private static final String MISCELLANEOUS = "miscellaneous.";

View File

@ -40,8 +40,9 @@ 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_TRACE, false);
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY, false);
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY, false);
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE, false);
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY, false);
set(ConfPaths.LOGGING_BACKEND_CONSOLE_ACTIVE, true);
set(ConfPaths.LOGGING_BACKEND_CONSOLE_PREFIX, "[NoCheatPlus] ");
set(ConfPaths.LOGGING_BACKEND_CONSOLE_ASYNCHRONOUS, true);

View File

@ -15,13 +15,17 @@ public class AllViolationsConfig {
/** Log all violations to the in-game notification channel. */
public final boolean allToNotify;
/** Only log if the player is being "debugged". Currently incomplete. */
public final boolean debugOnly;
// TODO: More config on what to print (uuid, etc., default tags).
// TODO: More filtering like in TestNCP.
public AllViolationsConfig(ConfigFile config) {
allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_TRACE);
allToNotify = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY);
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);
}
public boolean doesLogAnything() {

View File

@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
import fr.neatmonster.nocheatplus.checks.access.IViolationInfo;
import fr.neatmonster.nocheatplus.hooks.ILast;
import fr.neatmonster.nocheatplus.hooks.IStats;
@ -30,7 +32,7 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
private AllViolationsConfig config;
private Integer hookId = null;
/** White list. */
private final ParameterName[] parameters;
private final String[] noParameterTexts;
@ -88,7 +90,23 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
if (config == null) {
return false;
}
// Generate message.
if (config.debugOnly) {
// 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()) {
return false;
}
}
log(checkType, player, info, config);
return false;
}
private void log(final CheckType checkType, final Player player, final IViolationInfo info, final AllViolationsConfig config) {
// Generate the message.
// TODO: More colors?
final StringBuilder builder = new StringBuilder(300);
final String playerName = player.getName();
@ -110,7 +128,7 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
}
}
final String message = builder.toString();
// Send to where it is appropriate.
// Send the message.
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
if (config.allToNotify) {
logManager.info(Streams.NOTIFY_INGAME, message);
@ -118,7 +136,6 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
if (config.allToTrace) {
logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message));
}
return false;
}
}