public AllViolationsConfig(ConfigFile config) { 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 MCAccessConfig(final ConfigFile config) { this.enableCBDedicated = config.getBoolean(ConfPaths.COMPATIBILITY_SERVER_CBDEDICATED_ENABLE); this.enableCBReflect = config.getBoolean(ConfPaths.COMPATIBILITY_SERVER_CBREFLECT_ENABLE); }
private StreamID getRegistryStreamId() { // TODO: Select by config, or add Streams.REGISTRY for a new default. // For now prefer log file, unless extended status is set. return ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS) ? Streams.STATUS : Streams.DEFAULT_FILE; }
@Override public void run() { // Debug information about unknown blocks. // (Probably removed later.) ConfigFile config = ConfigManager.getConfigFile(); BlockProperties.dumpBlocks(config.getBoolean(ConfPaths.BLOCKBREAK_DEBUG, config.getBoolean(ConfPaths.CHECKS_DEBUG, false))); } });
public MetaDataListCheck(final ConfigFile config, final String pathActive, final String pathKeys) { this(config.getBoolean(pathActive) ? config.getStringList(pathKeys) : null); }
/** * Read the settings from the given configuration file, using default paths, * assuming DefaultConfig as defaults. * * @param config */ public ExemptionSettings(final ConfigFile config) { this( new MetaDataListCheck(config, ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_DEFAULT_METADATA_ACTIVE, ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_DEFAULT_METADATA_KEYS), config.getBoolean(ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_NPC_ACTIVE), config.getBoolean(ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_NPC_BUKKITINTERFACE), new MetaDataListCheck(config, ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_NPC_METADATA_ACTIVE, ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_NPC_METADATA_KEYS) ); }
/** * Returns this object. * @param config * @param prefix Prefix for direct addition of config path. * @return This object. */ public DigestedWordsSettings applyConfig(ConfigFile config, String prefix){ this.sort = config.getBoolean(prefix + "sort", this.sort); this.compress = config.getBoolean(prefix + "compress", this.compress); this.split = config.getBoolean(prefix + "split", this.split); this.weight = (float) config.getDouble(prefix + "weight", this.weight); this.minWordSize = config.getInt(prefix + "minwordsize", this.minWordSize); this.maxWordSize = config.getInt(prefix + "maxwordsize", this.maxWordSize); return this; } }
/** * Instantiates a new command action. * * @param name * the name * @param delay * the delay * @param repeat * the repeat * @param command * the command */ public CommandAction(final String name, final int delay, final int repeat, final String command) { // Log messages may have color codes now. super(name, delay, repeat, command); logDebug = ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_COMMANDS_ACTIONS); }
private static void checkLogEntry(final String tag) { // New entry. if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) { StaticLog.logInfo("Try old health API: " + tag); } }
/** * Set instance members based on the given configuration. This is meant to * work after reloading the configuration too. * * @param config */ private void setInstanceMembers(final ConfigFile config) { configProblemsChat = ConfigManager.isConfigUpToDate(config, config.getInt(ConfPaths.CONFIGVERSION_NOTIFYMAXPATHS)); configProblemsFile = configProblemsChat == null ? null : ConfigManager.isConfigUpToDate(config, -1); clearExemptionsOnJoin = config.getBoolean(ConfPaths.COMPATIBILITY_EXEMPTIONS_REMOVE_JOIN); clearExemptionsOnLeave = config.getBoolean(ConfPaths.COMPATIBILITY_EXEMPTIONS_REMOVE_LEAVE); NCPExemptionManager.setExemptionSettings(new ExemptionSettings(config)); }
/** * Send block codes to the player according to allowed or disallowed client-mods or client-mod features. * @param player */ public static void motdOnJoin(final Player player) { final ConfigFile config = ConfigManager.getConfigFile(); if (!config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ACTIVE)){ // No message is to be sent. return; } // TODO: Somebody test this all ! // TODO: add feature to check world specific (!). // Check if we allow all the client mods. final boolean allowAll = config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ALLOWALL); String message = ""; final IPlayerData data = DataManager.getPlayerData(player); for (int i = 0; i < motdS.length; i++){ message = motdS[i].onPlayerJoin(message, player, data, allowAll); } if (!message.isEmpty()){ player.sendMessage(message); } }
/** * Check if any config has a boolean set to true for the given path. * <hr/> * NOTE: Check activation flags need a query to the WorldDataManager, as * MAYBE typically means to activate, if the parent is active (checks <- * check group <- check (<- sub check)). * * @param path * @return True if any config has a boolean set to true for the given path. */ public static boolean isTrueForAnyConfig(String path) { final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager(); final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator(); while (it.hasNext()){ if (it.next().getValue().getRawConfiguration().getBoolean(path, false)) { return true; } } return false; }
public EnginePlayerConfig(final ConfigFile config){ // NOTE: These settings should be compared to the global settings done in the LetterEngine constructor. ppWordsCheck = config.getBoolean(ConfPaths.CHAT_TEXT_PP_WORDS_CHECK, false); if (ppWordsCheck){ ppWordsSettings = new FlatWordsSettings(); ppWordsSettings.maxSize = 150; // Adapt to smaller size. ppWordsSettings.applyConfig(config, ConfPaths.CHAT_TEXT_PP_WORDS); } else ppWordsSettings = null; // spare some memory. ppPrefixesCheck = config.getBoolean(ConfPaths.CHAT_TEXT_PP_PREFIXES_CHECK, false); if (ppPrefixesCheck){ ppPrefixesSettings = new WordPrefixesSettings(); ppPrefixesSettings.maxAdd = 320; // Adapt to smaller size. ppPrefixesSettings.applyConfig(config, ConfPaths.CHAT_TEXT_PP_PREFIXES); } else ppPrefixesSettings = null; ppSimilarityCheck = config.getBoolean(ConfPaths.CHAT_TEXT_PP_SIMILARITY_CHECK, false); if (ppSimilarityCheck){ ppSimilaritySettings = new SimilarWordsBKLSettings(); ppSimilaritySettings.maxSize = 100; // Adapt to smaller size; ppSimilaritySettings.applyConfig(config, ConfPaths.CHAT_TEXT_PP_SIMILARITY); } else ppSimilaritySettings = null; } }
public LetterEngine(ConfigFile config){ // Add word processors. // NOTE: These settings should be compared to the per player settings done in the EnginePlayerConfig constructor. if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_WORDS_CHECK, false)){ FlatWordsSettings settings = new FlatWordsSettings(); settings.maxSize = 1000; settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_WORDS); processors.add(new FlatWords("glWords",settings)); } if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_PREFIXES_CHECK , false)){ WordPrefixesSettings settings = new WordPrefixesSettings(); settings.maxAdd = 2000; settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_PREFIXES); processors.add(new WordPrefixes("glPrefixes", settings)); } if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_SIMILARITY_CHECK , false)){ SimilarWordsBKLSettings settings = new SimilarWordsBKLSettings(); settings.maxSize = 1000; settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_SIMILARITY); processors.add(new SimilarWordsBKL("glSimilarity", settings)); } // TODO: At least expiration duration configurable? (Entries expire after 10 minutes.) dataMap = new EnginePlayerDataMap(600000L, 100, 0.75f); }
/** * Fetch settings from the current default config. */ private void adjustSettings() { final ConfigFile config = ConfigManager.getConfigFile(); doExpireData = config.getBoolean(ConfPaths.DATA_EXPIRATION_ACTIVE); durExpireData = config.getLong(ConfPaths.DATA_EXPIRATION_DURATION, 1, 1000000, 60) * 60000L; // in minutes deleteData = config.getBoolean(ConfPaths.DATA_EXPIRATION_DATA, true); // hidden. deleteHistory = config.getBoolean(ConfPaths.DATA_EXPIRATION_HISTORY); // TODO: Per world permission registries: need world configs (...). Set<RegisteredPermission> changedPermissions = null; try { // TODO: Only update if changes are there - should have a config-path hash+size thing (+ setting). changedPermissions = permissionRegistry.updateSettings(PermissionSettings.fromConfig(config, ConfPaths.PERMISSIONS_POLICY_DEFAULT, ConfPaths.PERMISSIONS_POLICY_RULES)); } catch (Exception e) { StaticLog.logSevere("Failed to read the permissions setup. Relay to ALWAYS policy."); StaticLog.logSevere(e); permissionRegistry.updateSettings(new PermissionSettings(null, null, new PermissionPolicy())); } // Invalidate all already fetched permissions. for(final Entry<UUID, PlayerData> entry : playerData.iterable()) { entry.getValue().adjustSettings(changedPermissions); } }
private void updateBlockChangeTracker(final ConfigFile config) { // Activation / listener. if (config.getBoolean(ConfPaths.COMPATIBILITY_BLOCKS_CHANGETRACKER_ACTIVE) && config.getBoolean(ConfPaths.COMPATIBILITY_BLOCKS_CHANGETRACKER_PISTONS)) { if (blockChangeListener == null) { blockChangeListener = new BlockChangeListener(blockChangeTracker); blockChangeListener.register(); } blockChangeListener.setEnabled(true); } else if (blockChangeListener != null) { blockChangeListener.setEnabled(false); blockChangeTracker.clear(); } // Configuration. blockChangeTracker.setExpirationAgeTicks(config.getInt(ConfPaths.COMPATIBILITY_BLOCKS_CHANGETRACKER_MAXAGETICKS)); blockChangeTracker.setWorldNodeSkipSize(config.getInt(ConfPaths.COMPATIBILITY_BLOCKS_CHANGETRACKER_PERWORLD_MAXENTRIES)); blockChangeTracker.updateBlockCacheHandle(); }
private void scheduleConsistencyCheckers() { BukkitScheduler sched = getServer().getScheduler(); if (consistencyCheckerTaskId != -1) { sched.cancelTask(consistencyCheckerTaskId); } ConfigFile config = ConfigManager.getConfigFile(); if (!config.getBoolean(ConfPaths.DATA_CONSISTENCYCHECKS_CHECK, true)) { return; } // Schedule task in seconds. final long delay = 20L * config.getInt(ConfPaths.DATA_CONSISTENCYCHECKS_INTERVAL, 1, 3600, 10); consistencyCheckerTaskId = sched.scheduleSyncRepeatingTask(this, new Runnable() { @Override public void run() { runConsistencyChecks(); } }, delay, delay ); }
@Override protected void registerInitLogger() { synchronized (registryCOWLock) { if (!hasStream(Streams.INIT)) { createInitStream(); } else if (hasLogger(Streams.INIT.name)) { // Shallow check. return; } // Attach a new restrictive init logger. boolean bukkitLoggerAsynchronous = ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_BACKEND_CONSOLE_ASYNCHRONOUS); LoggerID initLoggerID = registerStringLogger(serverLogger, new LogOptions(Streams.INIT.name, bukkitLoggerAsynchronous ? CallContext.ANY_THREAD_DIRECT : CallContext.PRIMARY_THREAD_ONLY)); attachStringLogger(initLoggerID, Streams.INIT); } }
@Override public void execute(final ViolationData violationData) { // TODO: Consider permission caching or removing the feature? [Besides, check earlier?] final RegisteredPermission permissionSilent = violationData.getPermissionSilent(); // TODO: Store PlayerData in ViolationData ? Must query cache here. if (permissionSilent != null && DataManager.getPlayerData(violationData.player).hasPermission(permissionSilent, violationData.player)) { return; } final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager(); final String message = getMessage(violationData); final String messageNoColor = stripColor ? ColorUtil.removeColors(message) : null; final String messageWithColor = replaceColor ? ColorUtil.replaceColors(message) : null; final ConfigFile configFile = checkActive ? ConfigManager.getConfigFile() : null; for (int i = 0; i < configs.length; i ++) { final GenericLogActionConfig config = configs[i]; if (checkActive && config.configPathActive != null && !configFile.getBoolean(config.configPathActive)) { continue; } logManager.log(config.streamID, config.level, config.chatColor ? messageWithColor : messageNoColor); } }
/** * All action done on reload. */ private void processReload() { final ConfigFile config = ConfigManager.getConfigFile(); setInstanceMembers(config); // TODO: Process registered ComponentFactory instances. // Set up MCAccess. initMCAccess(config); // Initialize BlockProperties initBlockProperties(config); // Reset Command protection. undoCommandChanges(); if (config.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)) { setupCommandProtection(); } // (Re-) schedule consistency checking. scheduleConsistencyCheckers(); // Cache some things. TODO: Where is this comment from !? // Re-setup allViolationsHook. allViolationsHook.setConfig(new AllViolationsConfig(config)); // Set block change tracker. updateBlockChangeTracker(config); }