NoCheatPlus/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java

195 lines
10 KiB
Java
Raw Normal View History

/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.checks.chat;
2012-09-15 04:34:13 +02:00
import fr.neatmonster.nocheatplus.actions.ActionList;
import fr.neatmonster.nocheatplus.checks.access.ACheckConfig;
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.EnginePlayerConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
2012-11-06 10:11:17 +01:00
import fr.neatmonster.nocheatplus.permissions.Permissions;
[BLEEDING][BREAKING][INSTABLE] Swiftly throw in permission caching. Benefits: * Improves performance, where permission lookup has major impact, with timeout based lookup, static permissions (skip permission check entirely), and world/offline based invalidation. (Once fully implemented.) * Hopefully more efficient: use Bukkit Permission for faster defaults. * (Allows control over how which permission is to be updated/invalidated, which is useful per se.) Risks: * Complex changes yield bugs. * Other plugins depending on NCP might break. * Cache incoherence might happen (permissions are changed dynamically +- unintended malconfiguration, or in case of bugs). * (Endless loops certainly have all been fixed.) Breaking: * Lots of more or less internal API has been changed or removed: Check, CheckType, CheckUtils, TickTask, ... * Permission checking behavior has been altered. Rough points: * Implement a permission cache within PlayerData. * Remove the player tasks and permission updates in favour of handling those within DataManager and PlayerData. * Adjust everything else to it (partly TBD). * Updating sets of permissions (e.g. for CHAT) is done more lazily now, i.e. one per 10 ticks). An actual permission check would still yield an update next tick (asynchronous). * Fixed/extended random spots (DualCollection, MiniListener registration support, StringUtil). Missing: * Basic implementation * Cleanup after logout (stages: 1. non-essential like permissions, 2. unrecoverable like set-back location, 3. complete data removal). * Coverage * Might have missed spots. * NoCheatPlus.nameSetPerms should be replaced by caching + default config for world-wise updating. * Command permissions are always checked. At least for players, cache based lookup should get implemented. * More unit tests. * Extended configurability: Per-world settings/policies. * Efficiency * Not all parts of the implementation are 100%/optimal yet.
2018-01-28 18:52:51 +01:00
import fr.neatmonster.nocheatplus.permissions.RegisteredPermission;
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
import fr.neatmonster.nocheatplus.worlds.IWorldData;
2012-03-01 18:40:03 +01:00
/**
* Configurations specific for the "chat" checks. Every world gets one of these assigned to it, or if a world doesn't
* get it's own, it will use the "global" version.
2012-03-01 18:40:03 +01:00
*/
public class ChatConfig extends ACheckConfig {
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
private static final RegisteredPermission[] preferKeepUpdatedPermissions = new RegisteredPermission[]{
// Only the permissions needed for async. checking.
Permissions.CHAT_COLOR,
Permissions.CHAT_TEXT,
Permissions.CHAT_CAPTCHA,
// TODO: COMMANDS, in case of handleascommand?
};
public static RegisteredPermission[] getPreferKeepUpdatedPermissions() {
return preferKeepUpdatedPermissions;
}
2015-11-13 22:06:31 +01:00
public final boolean captchaSkipCommands;
public final String captchaCharacters;
public final int captchaLength;
public final String captchaQuestion;
public final String captchaSuccess;
public final int captchaTries;
public final ActionList captchaActions;
public final ActionList colorActions;
public final double commandsLevel;
public final int commandsShortTermTicks;
public final double commandsShortTermLevel;
public final ActionList commandsActions;
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
// TODO: Sub check types ?
public final boolean textGlobalCheck;
public final boolean textPlayerCheck;
public final EnginePlayerConfig textEnginePlayerConfig;
public final float textFreqNormFactor;
public final float textFreqNormWeight;
public final float textFreqNormMin;
public final double textFreqNormLevel;
public final ActionList textFreqNormActions;
public final float textFreqShortTermFactor;
public final float textFreqShortTermWeight;
public final float textFreqShortTermLevel;
public final float textFreqShortTermMin;
public final ActionList textFreqShortTermActions;
public final float textMessageLetterCount;
public final float textMessageUpperCase;
public final float textMessagePartition;
public final float textMsgRepeatCancel;
public final float textMsgAfterJoin;
public final float textMsgRepeatSelf;
public final float textMsgRepeatGlobal;
public final float textMsgNoMoving;
// words
public final float textMessageLengthAv;
public final float textMessageLengthMsg;
public final float textMessageNoLetter;
public final float textGlobalWeight;
public final float textPlayerWeight;
public final boolean textEngineMaximum;
public final boolean textAllowVLReset;
public final boolean textDebug;
public final boolean chatWarningCheck;
public final float chatWarningLevel;
public final String chatWarningMessage;
public final long chatWarningTimeout;
public final boolean loginsPerWorldCount;
public final int loginsSeconds;
public final int loginsLimit;
public final String loginsKickMessage;
2012-10-03 14:13:25 +02:00
public final long loginsStartupDelay;
public final boolean consoleOnlyCheck;
public final String consoleOnlyMessage;
2012-08-08 20:39:01 +02:00
public final String relogKickMessage;
public final long relogTimeout;
public final String relogWarningMessage;
public final int relogWarningNumber;
public final long relogWarningTimeout;
public final ActionList relogActions;
/**
* Instantiates a new chat configuration.
*
* @param config
* the data
*/
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
public ChatConfig(final IWorldData worldData) {
super(worldData);
final ConfigFile config = worldData.getRawConfiguration();
2015-11-13 22:06:31 +01:00
captchaSkipCommands = config.getBoolean(ConfPaths.CHAT_CAPTCHA_SKIP_COMMANDS);
captchaCharacters = config.getString(ConfPaths.CHAT_CAPTCHA_CHARACTERS);
captchaLength = config.getInt(ConfPaths.CHAT_CAPTCHA_LENGTH);
captchaQuestion = config.getString(ConfPaths.CHAT_CAPTCHA_QUESTION);
captchaSuccess = config.getString(ConfPaths.CHAT_CAPTCHA_SUCCESS);
captchaTries = config.getInt(ConfPaths.CHAT_CAPTCHA_TRIES);
captchaActions = config.getOptimizedActionList(ConfPaths.CHAT_CAPTCHA_ACTIONS, Permissions.CHAT_CAPTCHA);
colorActions = config.getOptimizedActionList(ConfPaths.CHAT_COLOR_ACTIONS, Permissions.CHAT_COLOR);
commandsLevel = config.getDouble(ConfPaths.CHAT_COMMANDS_LEVEL);
commandsShortTermTicks = config.getInt(ConfPaths.CHAT_COMMANDS_SHORTTERM_TICKS);
commandsShortTermLevel = config.getDouble(ConfPaths.CHAT_COMMANDS_SHORTTERM_LEVEL);;
commandsActions = config.getOptimizedActionList(ConfPaths.CHAT_COMMANDS_ACTIONS, Permissions.CHAT_COMMANDS);
textGlobalCheck = config.getBoolean(ConfPaths.CHAT_TEXT_GL_CHECK, true);
textPlayerCheck = config.getBoolean(ConfPaths.CHAT_TEXT_PP_CHECK, true);
textEnginePlayerConfig = new EnginePlayerConfig(config);
textFreqNormMin = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_NORM_MIN);
textFreqNormFactor = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_NORM_FACTOR);
textFreqNormWeight = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_NORM_WEIGHT);
textFreqShortTermFactor = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_SHORTTERM_FACTOR);
textFreqShortTermWeight = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_SHORTTERM_WEIGHT);
textFreqShortTermLevel = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_SHORTTERM_LEVEL);
textFreqShortTermMin = (float) config.getDouble(ConfPaths.CHAT_TEXT_FREQ_SHORTTERM_MIN);
textFreqShortTermActions = config.getOptimizedActionList(ConfPaths.CHAT_TEXT_FREQ_SHORTTERM_ACTIONS, Permissions.CHAT_TEXT);
textMessageLetterCount = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_LETTERCOUNT);
textMessagePartition = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_PARTITION);
textMessageUpperCase = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_UPPERCASE);
textMsgRepeatCancel = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_REPEATCANCEL);
textMsgAfterJoin = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_AFTERJOIN);
textMsgRepeatSelf = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_REPEATSELF);
textMsgRepeatGlobal = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_REPEATGLOBAL);
textMsgNoMoving = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_NOMOVING);
textMessageLengthAv = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_WORDS_LENGTHAV);
textMessageLengthMsg = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_WORDS_LENGTHMSG);
textMessageNoLetter = (float) config.getDouble(ConfPaths.CHAT_TEXT_MSG_WORDS_NOLETTER);
textGlobalWeight = (float) config.getDouble(ConfPaths.CHAT_TEXT_GL_WEIGHT, 1.0);
textPlayerWeight = (float) config.getDouble(ConfPaths.CHAT_TEXT_PP_WEIGHT, 1.0);
textFreqNormLevel = config.getDouble(ConfPaths.CHAT_TEXT_FREQ_NORM_LEVEL);
textEngineMaximum = config.getBoolean(ConfPaths.CHAT_TEXT_ENGINE_MAXIMUM, true);
textDebug = config.getBoolean(ConfPaths.CHAT_TEXT_DEBUG, false);
textFreqNormActions = config.getOptimizedActionList(ConfPaths.CHAT_TEXT_FREQ_NORM_ACTIONS, Permissions.CHAT_TEXT);
textAllowVLReset = config.getBoolean(ConfPaths.CHAT_TEXT_ALLOWVLRESET);
chatWarningCheck = config.getBoolean(ConfPaths.CHAT_WARNING_CHECK);
chatWarningLevel = (float) config.getDouble(ConfPaths.CHAT_WARNING_LEVEL);
chatWarningMessage = config.getString(ConfPaths.CHAT_WARNING_MESSAGE);
chatWarningTimeout = config.getLong(ConfPaths.CHAT_WARNING_TIMEOUT) * 1000;
loginsPerWorldCount = config.getBoolean(ConfPaths.CHAT_LOGINS_PERWORLDCOUNT);
loginsSeconds = config.getInt(ConfPaths.CHAT_LOGINS_SECONDS);
loginsLimit = config.getInt(ConfPaths.CHAT_LOGINS_LIMIT);
loginsKickMessage = config.getString(ConfPaths.CHAT_LOGINS_KICKMESSAGE);
2012-10-03 14:13:25 +02:00
loginsStartupDelay = config.getInt(ConfPaths.CHAT_LOGINS_STARTUPDELAY) * 1000;
relogKickMessage = config.getString(ConfPaths.CHAT_RELOG_KICKMESSAGE);
relogTimeout = config.getLong(ConfPaths.CHAT_RELOG_TIMEOUT);
relogWarningMessage = config.getString(ConfPaths.CHAT_RELOG_WARNING_MESSAGE);
relogWarningNumber = config.getInt(ConfPaths.CHAT_RELOG_WARNING_NUMBER);
relogWarningTimeout = config.getLong(ConfPaths.CHAT_RELOG_WARNING_TIMEOUT);
relogActions = config.getOptimizedActionList(ConfPaths.CHAT_RELOG_ACTIONS, Permissions.CHAT_RELOG);
consoleOnlyCheck = config.getBoolean(ConfPaths.PROTECT_COMMANDS_CONSOLEONLY_ACTIVE);
consoleOnlyMessage = ColorUtil.replaceColors(config.getString(ConfPaths.PROTECT_COMMANDS_CONSOLEONLY_MSG));
2012-08-08 20:39:01 +02:00
2011-10-18 15:58:14 +02:00
}
}