mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-27 18:01:33 +01:00
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.
This commit is contained in:
parent
6e602af816
commit
4a8f19ef7a
@ -51,6 +51,7 @@ public abstract class ConfPaths {
|
|||||||
private static final String LOGGING_EXTENDED = LOGGING + "extended.";
|
private static final String LOGGING_EXTENDED = LOGGING + "extended.";
|
||||||
public static final String LOGGING_EXTENDED_STATUS = LOGGING_EXTENDED + "status";
|
public static final String LOGGING_EXTENDED_STATUS = LOGGING_EXTENDED + "status";
|
||||||
private static final String LOGGING_EXTENDED_ALLVIOLATIONS = LOGGING_EXTENDED + "allviolations.";
|
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";
|
public static final String LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY = LOGGING_EXTENDED_ALLVIOLATIONS + "debugonly";
|
||||||
private static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND = LOGGING_EXTENDED_ALLVIOLATIONS + "backend.";
|
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_TRACE = LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND + "trace";
|
||||||
|
@ -40,6 +40,7 @@ public class DefaultConfig extends ConfigFile {
|
|||||||
set(ConfPaths.LOGGING_ACTIVE, true);
|
set(ConfPaths.LOGGING_ACTIVE, true);
|
||||||
set(ConfPaths.LOGGING_MAXQUEUESIZE, 5000);
|
set(ConfPaths.LOGGING_MAXQUEUESIZE, 5000);
|
||||||
set(ConfPaths.LOGGING_EXTENDED_STATUS, false);
|
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_DEBUGONLY, false);
|
||||||
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE, false);
|
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE, false);
|
||||||
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY, false);
|
set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY, false);
|
||||||
|
@ -16,6 +16,9 @@ public class AllViolationsConfig {
|
|||||||
/** Log all violations to the in-game notification channel. */
|
/** Log all violations to the in-game notification channel. */
|
||||||
public final boolean allToNotify;
|
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. */
|
/** Only log if the player is being "debugged". Currently incomplete. */
|
||||||
public final boolean debugOnly;
|
public final boolean debugOnly;
|
||||||
|
|
||||||
@ -23,13 +26,14 @@ public class AllViolationsConfig {
|
|||||||
// TODO: More filtering like in TestNCP.
|
// TODO: More filtering like in TestNCP.
|
||||||
|
|
||||||
public AllViolationsConfig(ConfigFile config) {
|
public AllViolationsConfig(ConfigFile config) {
|
||||||
debugOnly = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY);
|
|
||||||
allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE);
|
allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE);
|
||||||
allToNotify = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY);
|
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() {
|
public boolean doesLogAnything() {
|
||||||
return allToTrace || allToNotify;
|
return allToTrace || allToNotify || debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -90,22 +90,31 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
|
|||||||
if (config == null) {
|
if (config == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (config.debugOnly) {
|
boolean debugSet = false;
|
||||||
|
if (config.debugOnly || config.debug) {
|
||||||
// TODO: Better mix the debug flag into IViolationInfo, for best performance.
|
// TODO: Better mix the debug flag into IViolationInfo, for best performance.
|
||||||
final CheckDataFactory factory = checkType.getDataFactory();
|
final CheckDataFactory factory = checkType.getDataFactory();
|
||||||
if (factory == null) {
|
if (config.debugOnly && factory == null) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final ICheckData data = factory.getData(player);
|
|
||||||
if (data == null || !data.getDebug()) {
|
|
||||||
return false;
|
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;
|
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.
|
// Generate the message.
|
||||||
// TODO: More colors?
|
// TODO: More colors?
|
||||||
final StringBuilder builder = new StringBuilder(300);
|
final StringBuilder builder = new StringBuilder(300);
|
||||||
@ -130,10 +139,10 @@ public class AllViolationsHook implements NCPHook, ILast, IStats {
|
|||||||
final String message = builder.toString();
|
final String message = builder.toString();
|
||||||
// Send the message.
|
// Send the message.
|
||||||
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
|
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
|
||||||
if (config.allToNotify) {
|
if (toNotify) {
|
||||||
logManager.info(Streams.NOTIFY_INGAME, message);
|
logManager.info(Streams.NOTIFY_INGAME, message);
|
||||||
}
|
}
|
||||||
if (config.allToTrace) {
|
if (toTrace) {
|
||||||
logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message));
|
logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user