mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-15 12:01:51 +01:00
Unify and simplify Check / AsyncCheck, ACheckConfig / AsyncCheckConfig.
Hinting at further changes to unify permission access and caching. Later permission caching can also be done for moving checks, though checking for the current thread may be exchanged in favor of config flags. Generic configuration will allow to set individual timeouts for checks, check groups and default. There could also be change policies like "world change only", possibly listening to permission updates, if feasible. CheckData / AsyncCheckData are not as simple to unify, if we want to keep the footprint as low as possible there. There could even be more implementations to match different policies.
This commit is contained in:
parent
1eb8d98860
commit
8b43e5e5f1
@ -1,25 +0,0 @@
|
||||
package fr.neatmonster.nocheatplus.checks;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
||||
|
||||
public abstract class AsyncCheck extends Check {
|
||||
|
||||
public AsyncCheck(CheckType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Player player) {
|
||||
try {
|
||||
if (!type.isEnabled(player) || type.hasCachedPermission(player))
|
||||
return false;
|
||||
} catch (final Exception e) {
|
||||
LogUtil.scheduleLogSevere(e);
|
||||
}
|
||||
return !NCPExemptionManager.isExempted(player, type);
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.checks;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||
@ -162,12 +163,19 @@ public abstract class Check implements MCAccessHolder{
|
||||
* @return true, if the check is enabled
|
||||
*/
|
||||
public boolean isEnabled(final Player player) {
|
||||
try {
|
||||
if (!type.isEnabled(player) || player.hasPermission(type.getPermission()))
|
||||
if (!type.isEnabled(player)) {
|
||||
return false;
|
||||
}
|
||||
// TODO: Checking for the thread might be a temporary measure.
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
// Check permissions directly.
|
||||
if (player.hasPermission(type.getPermission())) {
|
||||
return false;
|
||||
} catch (final Exception e) {
|
||||
// TODO: this should be mostly obsolete.
|
||||
LogUtil.logSevere(e);
|
||||
}
|
||||
}
|
||||
else if (type.hasCachedPermission(player)) {
|
||||
// Assume asynchronously running check.
|
||||
return false;
|
||||
}
|
||||
return !NCPExemptionManager.isExempted(player, type);
|
||||
}
|
||||
|
@ -13,24 +13,38 @@ public abstract class ACheckConfig implements ICheckConfig {
|
||||
/** For on the fly debug setting. */
|
||||
public boolean debug = false;
|
||||
|
||||
/** For adaption to server side lag. */
|
||||
/** If to adapt to server side lag. */
|
||||
public final boolean lag;
|
||||
|
||||
/** Permissions to hold in player data cache, not final for flexibility. */
|
||||
protected String[] cachePermissions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param config
|
||||
* @param pathPrefix Path prefix for the check section (example for use: prefix+"debug").
|
||||
*/
|
||||
public ACheckConfig(final ConfigFile config, final String pathPrefix){
|
||||
// TODO: Path prefix construction is somewhat inconsistent with debug hierarchy ?
|
||||
this(config, pathPrefix, null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param config
|
||||
* @param pathPrefix Path prefix for the check section (example for use: prefix+"debug").
|
||||
* @param cachePermissions cachePermissions Permissions to hold in player data cache. Can be null.
|
||||
*/
|
||||
public ACheckConfig(final ConfigFile config, final String pathPrefix, final String[] cachePermissions){
|
||||
// TODO: Path prefix construction is somewhat inconsistent with debug hierarchy ?
|
||||
debug = config.getBoolean(pathPrefix + ConfPaths.SUB_DEBUG, config.getBoolean(ConfPaths.CHECKS_DEBUG, false));
|
||||
// TODO: Use lag flag where appropriate and document it (or get rid of it).
|
||||
lag = config.getBoolean(pathPrefix + ConfPaths.SUB_LAG, true) && config.getBoolean(ConfPaths.MISCELLANEOUS_LAG, true);
|
||||
this.cachePermissions = cachePermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCachePermissions() {
|
||||
return null;
|
||||
return cachePermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,31 +0,0 @@
|
||||
package fr.neatmonster.nocheatplus.checks.access;
|
||||
|
||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||
|
||||
/**
|
||||
* CheckConfig for async checks such as chat, adding permissions to cache.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public abstract class AsyncCheckConfig extends ACheckConfig {
|
||||
|
||||
/** Permissions to hold in player data cache, not final for flexibility. */
|
||||
protected String[] cachePermissions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param config
|
||||
* @param pathPrefix Path prefix for the check section (example for use: prefix+"debug").
|
||||
* @param cachePermissions cachePermissions Permissions to hold in player data cache.
|
||||
*/
|
||||
public AsyncCheckConfig(final ConfigFile config, final String pathPrefix, final String[] cachePermissions){
|
||||
super(config, pathPrefix);
|
||||
this.cachePermissions = cachePermissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCachePermissions() {
|
||||
return cachePermissions;
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ import java.util.Random;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.AsyncCheck;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.permissions.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
|
||||
@ -14,7 +14,7 @@ import fr.neatmonster.nocheatplus.utilities.ColorUtil;
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class Captcha extends AsyncCheck implements ICaptcha{
|
||||
public class Captcha extends Check implements ICaptcha{
|
||||
|
||||
public Captcha() {
|
||||
super(CheckType.CHAT_CAPTCHA);
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.ActionList;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.access.AsyncCheckConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ACheckConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ICheckConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.EnginePlayerConfig;
|
||||
@ -21,7 +21,7 @@ import fr.neatmonster.nocheatplus.utilities.ColorUtil;
|
||||
* 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.
|
||||
*/
|
||||
public class ChatConfig extends AsyncCheckConfig {
|
||||
public class ChatConfig extends ACheckConfig {
|
||||
|
||||
/** The factory creating configurations. */
|
||||
public static final CheckConfigFactory factory = new CheckConfigFactory() {
|
||||
|
@ -2,13 +2,13 @@ package fr.neatmonster.nocheatplus.checks.chat;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.AsyncCheck;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
/**
|
||||
* The Color check verifies that no color codes are sent in players' messages.
|
||||
*/
|
||||
public class Color extends AsyncCheck {
|
||||
public class Color extends Check {
|
||||
|
||||
/**
|
||||
* Instantiates a new color check.
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.AsyncCheck;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
|
||||
@ -29,7 +29,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class Text extends AsyncCheck implements INotifyReload{
|
||||
public class Text extends Check implements INotifyReload {
|
||||
|
||||
private LetterEngine engine = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user