[BLEEDING] Integrate net checks into the check system.

* Extend CheckConfigFactory with a remove-all method.
* DataManager.clearConfigs() now uses CheckType for getting factories.
* Split off Check.hasBypass method to check exemption + permission.
* Allow null permissions in CheckType (interpret as no bypass).
* Add Check types for FlyingFrequency and SoundDistance.
* Add exemption and actions to FlyingFrequency, alter defaults.
This commit is contained in:
asofold 2015-01-30 01:18:37 +01:00
parent b3fa312ceb
commit 86732764e3
23 changed files with 598 additions and 439 deletions

View File

@ -1,8 +1,6 @@
package fr.neatmonster.nocheatplus.checks.net.protocollib; package fr.neatmonster.nocheatplus.checks.net.protocollib;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -13,14 +11,16 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.moving.MovingData; import fr.neatmonster.nocheatplus.checks.moving.MovingData;
import fr.neatmonster.nocheatplus.checks.net.NetConfig; import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache; import fr.neatmonster.nocheatplus.checks.net.NetConfigCache;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener; import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.checks.net.NetDataFactory;
import fr.neatmonster.nocheatplus.logging.Streams; import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.stats.Counters; import fr.neatmonster.nocheatplus.stats.Counters;
import fr.neatmonster.nocheatplus.time.monotonic.Monotonic; import fr.neatmonster.nocheatplus.time.monotonic.Monotonic;
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
import fr.neatmonster.nocheatplus.utilities.CheckUtils; import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.TrigUtil; import fr.neatmonster.nocheatplus.utilities.TrigUtil;
@ -31,66 +31,36 @@ import fr.neatmonster.nocheatplus.utilities.TrigUtil;
* @author dev1mc * @author dev1mc
* *
*/ */
public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener { public class FlyingFrequency extends PacketAdapter {
public static final double minMoveDistSq = 1f / 256; // PlayerConnection magic. // Setup for flying packets.
public static final float minLookChange = 10f;
// TODO: Most efficient registration + optimize (primary thread or asynchronous).
private class FFData {
public static final int numBooleans = 3; public static final int numBooleans = 3;
public static final int indexOnGround = 0; public static final int indexOnGround = 0;
public static final int indexhasPos = 1; public static final int indexhasPos = 1;
public static final int indexhasLook = 2; public static final int indexhasLook = 2;
public final ActionFrequency all; // Thresholds for firing moving events (CraftBukkit).
// Last move on-ground. public static final double minMoveDistSq = 1f / 256; // PlayerConnection magic.
public boolean onGround = false; public static final float minLookChange = 10f;
public long timeOnGround = 0;
public long timeNotOnGround = 0;
public FFData(int seconds) { /** Dummy check to access hasBypass for FlyingFrequency. */
all = new ActionFrequency(seconds, 1000L); private final Check frequency = new Check(CheckType.NET_FLYINGFREQUENCY) {
} // Dummy check to access hasBypass.
} };
private final Map<String, FFData> freqMap = new HashMap<String, FFData>();
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
private final int idSilent = counters.registerKey("packet.flying.silentcancel");
private final int idRedundant = counters.registerKey("packet.flying.silentcancel.redundant");
private final int idNullPlayer = counters.registerKey("packet.flying.nullplayer"); private final int idNullPlayer = counters.registerKey("packet.flying.nullplayer");
private boolean cancelRedundant = true; private boolean cancelRedundant = true;
private final NetConfigCache configs; private final NetConfigCache configs;
private final NetDataFactory dataFactory;
public FlyingFrequency(NetConfigCache configs, Plugin plugin) { public FlyingFrequency(Plugin plugin) {
// PacketPlayInFlying[3, legacy: 10] // PacketPlayInFlying[3, legacy: 10]
super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate? super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate?
this.configs = configs; this.configs = (NetConfigCache) CheckType.NET.getConfigFactory();
} this.dataFactory = (NetDataFactory) CheckType.NET.getDataFactory();
@Override
public void playerJoins(Player player) {
// Ignore.
}
@Override
public void playerLeaves(Player player) {
freqMap.remove(player.getName());
}
private FFData getData(final String name, final NetConfig cc) {
final FFData freq = this.freqMap.get(name);
if (freq != null) {
return freq;
} else {
final FFData newFreq = new FFData(cc.flyingFrequencySeconds);
this.freqMap.put(name, newFreq);
return newFreq;
}
} }
@Override @Override
@ -109,32 +79,32 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
return; return;
} }
final FFData data = getData(player.getName(), cc); final NetData data = dataFactory.getData(player);
final long t = System.currentTimeMillis(); final long time = Monotonic.millis();
// Counting all packets. // Counting all packets.
data.all.add(t, 1f); // TODO: Consider using the NetStatic check.
final float allScore = data.all.score(1f); data.flyingFrequencyAll.add(time, 1f);
if (allScore > cc.flyingFrequencyMaxPackets) { final float allScore = data.flyingFrequencyAll.score(1f);
counters.add(idSilent, 1); // Until it is sure if we can get these async. if (allScore / cc.flyingFrequencySeconds > cc.flyingFrequencyPPS && !frequency.hasBypass(player) && frequency.executeActions(player, allScore / cc.flyingFrequencySeconds - cc.flyingFrequencyPPS, 1.0 / cc.flyingFrequencySeconds, cc.flyingFrequencyActions, true)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// Cancel redundant packets, when frequency is high anyway. // Cancel redundant packets, when frequency is high anyway.
if (cancelRedundant && cc.flyingFrequencyCancelRedundant && checkRedundantPackets(player, event, allScore, data, cc)) { if (cancelRedundant && cc.flyingFrequencyRedundantActive && checkRedundantPackets(player, event, allScore, time, data, cc) ) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
private boolean checkRedundantPackets(final Player player, final PacketEvent event, final float allScore, final FFData data, final NetConfig cc) { private boolean checkRedundantPackets(final Player player, final PacketEvent event, final float allScore, final long time, final NetData data, final NetConfig cc) {
// TODO: Consider quick return conditions. // TODO: Consider quick return conditions.
// TODO: Debug logging (better with integration into DataManager). // TODO: Debug logging (better with integration into DataManager).
// TODO: Consider to compare to moving data directly, skip keeping track extra. // TODO: Consider to compare to moving data directly, skip keeping track extra.
final PacketContainer packet = event.getPacket(); final PacketContainer packet = event.getPacket();
final List<Boolean> booleans = packet.getBooleans().getValues(); final List<Boolean> booleans = packet.getBooleans().getValues();
if (booleans.size() != FFData.numBooleans) { if (booleans.size() != FlyingFrequency.numBooleans) {
return packetMismatch(); return packetMismatch();
} }
@ -143,30 +113,29 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
// Can not check. // Can not check.
return false; return false;
} }
final boolean hasPos = booleans.get(FFData.indexhasPos).booleanValue(); final boolean hasPos = booleans.get(FlyingFrequency.indexhasPos).booleanValue();
final boolean hasLook = booleans.get(FFData.indexhasLook).booleanValue(); final boolean hasLook = booleans.get(FlyingFrequency.indexhasLook).booleanValue();
final boolean onGround = booleans.get(FFData.indexOnGround).booleanValue(); final boolean onGround = booleans.get(FlyingFrequency.indexOnGround).booleanValue();
boolean onGroundSkip = false; boolean onGroundSkip = false;
// Allow at least one on-ground change per state and second. // Allow at least one on-ground change per state and second.
// TODO: Consider to verify on ground somehow (could tell MovingData the state). // TODO: Consider to verify on ground somehow (could tell MovingData the state).
if (onGround != data.onGround) { if (onGround != data.flyingFrequencyOnGround) {
// Regard as not redundant only if sending the same state happened at least a second ago. // Regard as not redundant only if sending the same state happened at least a second ago.
final long time = Monotonic.millis();
final long lastTime; final long lastTime;
if (onGround) { if (onGround) {
lastTime = data.timeOnGround; lastTime = data.flyingFrequencyTimeOnGround;
data.timeOnGround = time; data.flyingFrequencyTimeOnGround = time;
} else { } else {
lastTime = data.timeNotOnGround; lastTime = data.flyingFrequencyTimeNotOnGround;
data.timeNotOnGround = time; data.flyingFrequencyTimeNotOnGround = time;
} }
if (time - lastTime > 1000) { if (time - lastTime > 1000) {
// Override // Override
onGroundSkip = true; onGroundSkip = true;
} }
} }
data.onGround = onGround; data.flyingFrequencyOnGround = onGround;
if (hasPos) { if (hasPos) {
final List<Double> doubles = packet.getDoubles().getValues(); final List<Double> doubles = packet.getDoubles().getValues();
@ -206,14 +175,16 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
return false; return false;
} }
// TODO: Could check first bucket or even just 50 ms to last packet. // Packet is redundant, if more than 20 packets per second arrive.
if (allScore / cc.flyingFrequencySeconds > 20f) { if (allScore / cc.flyingFrequencySeconds > 20f && !frequency.hasBypass(player)) {
counters.add(idRedundant, 1); // (Must re-check bypass here.)
data.flyingFrequencyRedundantFreq.add(time, 1f);
if (frequency.executeActions(player, data.flyingFrequencyRedundantFreq.score(1f) / cc.flyingFrequencyRedundantSeconds, 1.0 / cc.flyingFrequencyRedundantSeconds, cc.flyingFrequencyRedundantActions, true)) {
return true; return true;
} else {
return false;
} }
} }
return false;
}
/** /**
* Log warning to console, halt checking for redundant packets. * Log warning to console, halt checking for redundant packets.

View File

@ -12,7 +12,7 @@ import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.DisableListener; import fr.neatmonster.nocheatplus.components.DisableListener;
import fr.neatmonster.nocheatplus.components.INotifyReload; import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI; import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
@ -28,7 +28,6 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
*/ */
public class ProtocolLibComponent implements DisableListener, INotifyReload { public class ProtocolLibComponent implements DisableListener, INotifyReload {
private final NetConfigCache configs = new NetConfigCache();
private final List<PacketAdapter> registeredPacketAdapters = new LinkedList<PacketAdapter>(); private final List<PacketAdapter> registeredPacketAdapters = new LinkedList<PacketAdapter>();
public ProtocolLibComponent(Plugin plugin) { public ProtocolLibComponent(Plugin plugin) {
@ -75,7 +74,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
private void register(Class<? extends PacketAdapter> clazz, Plugin plugin) { private void register(Class<? extends PacketAdapter> clazz, Plugin plugin) {
try { try {
// Construct a new instance using reflection. // Construct a new instance using reflection.
PacketAdapter adapter = clazz.getDeclaredConstructor(NetConfigCache.class, Plugin.class).newInstance(configs, plugin); PacketAdapter adapter = clazz.getDeclaredConstructor(Plugin.class).newInstance(plugin);
ProtocolLibrary.getProtocolManager().addPacketListener(adapter); ProtocolLibrary.getProtocolManager().addPacketListener(adapter);
registeredPacketAdapters.add(adapter); registeredPacketAdapters.add(adapter);
} catch (Throwable t) { } catch (Throwable t) {
@ -92,6 +91,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
@Override @Override
public void onReload() { public void onReload() {
unregister(); unregister();
CheckType.NET.getDataFactory().removeAllData(); // Currently needed for FlyingFRequency.
register(Bukkit.getPluginManager().getPlugin("NoCheatPlus")); // Store instead ? register(Bukkit.getPluginManager().getPlugin("NoCheatPlus")); // Store instead ?
} }
@ -107,7 +107,6 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
} }
} }
registeredPacketAdapters.clear(); registeredPacketAdapters.clear();
configs.clearAllConfigs();
} }
} }

View File

@ -10,6 +10,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.net.NetConfig; import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache; import fr.neatmonster.nocheatplus.checks.net.NetConfigCache;
import fr.neatmonster.nocheatplus.utilities.TrigUtil; import fr.neatmonster.nocheatplus.utilities.TrigUtil;
@ -38,9 +39,9 @@ public class SoundDistance extends PacketAdapter {
private final NetConfigCache configs; private final NetConfigCache configs;
private final Location useLoc = new Location(null, 0, 0, 0); private final Location useLoc = new Location(null, 0, 0, 0);
public SoundDistance(NetConfigCache configs, Plugin plugin) { public SoundDistance(Plugin plugin) {
super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT); super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT);
this.configs = configs; this.configs = (NetConfigCache) CheckType.NET.getConfigFactory(); // TODO: DataManager.getConfig(NetConfigCache.class);
} }
@Override @Override

View File

@ -160,7 +160,8 @@ public abstract class Check implements MCAccessHolder{
} }
/** /**
* Checks if this check is enabled for the specified player. * Checks both configuration flags and if the player is exempted from this
* check (hasBypass).
* *
* @param player * @param player
* the player * the player
@ -170,17 +171,29 @@ public abstract class Check implements MCAccessHolder{
if (!type.isEnabled(player)) { if (!type.isEnabled(player)) {
return false; return false;
} }
return !hasBypass(player);
}
/**
* Check if the player is exempted by permissions or otherwise.
*
* @param player
* @return
*/
public boolean hasBypass(final Player player) {
// TODO: Checking for the thread might be a temporary measure. // TODO: Checking for the thread might be a temporary measure.
if (Bukkit.isPrimaryThread()) { if (Bukkit.isPrimaryThread()) {
// Check permissions directly. // Check permissions directly.
if (player.hasPermission(type.getPermission())) { final String permission = type.getPermission();
return false; if (permission != null && player.hasPermission(permission)) {
return true;
} }
} }
else if (type.hasCachedPermission(player)) { else if (type.hasCachedPermission(player)) {
// Assume asynchronously running check. // Assume asynchronously running check.
return false; return true;
} }
// TODO: ExemptionManager relies on initial setup (problematic).
return !NCPExemptionManager.isExempted(player, type); return !NCPExemptionManager.isExempted(player, type);
} }

View File

@ -20,6 +20,8 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryData; import fr.neatmonster.nocheatplus.checks.inventory.InventoryData;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingData; import fr.neatmonster.nocheatplus.checks.moving.MovingData;
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache;
import fr.neatmonster.nocheatplus.checks.net.NetDataFactory;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
/** /**
@ -96,6 +98,10 @@ public enum CheckType {
MOVING_PASSABLE(MOVING, Permissions.MOVING_PASSABLE), MOVING_PASSABLE(MOVING, Permissions.MOVING_PASSABLE),
MOVING_SURVIVALFLY(MOVING, Permissions.MOVING_SURVIVALFLY), MOVING_SURVIVALFLY(MOVING, Permissions.MOVING_SURVIVALFLY),
NET(new NetConfigCache(), new NetDataFactory(), Permissions.NET),
NET_FLYINGFREQUENCY(NET, Permissions.NET_FLYINGFREQUENCY),
NET_SOUNDDISTANCE(NET), // Can not exempt players from this one.
UNKNOWN; UNKNOWN;
/** If not null, this is the check group usually. */ /** If not null, this is the check group usually. */
@ -125,6 +131,10 @@ public enum CheckType {
this(null, null, permission); this(null, null, permission);
} }
private CheckType(final CheckType parent) {
this(parent, null);
}
/** /**
* Constructor for root checks or check groups, that are not grouped under another check type. * Constructor for root checks or check groups, that are not grouped under another check type.
* @param configFactory * @param configFactory

View File

@ -18,4 +18,9 @@ public interface CheckConfigFactory {
*/ */
public ICheckConfig getConfig(Player player); public ICheckConfig getConfig(Player player);
/**
* Remove all stored configurations.
*/
public void removeAllConfigs();
} }

View File

@ -27,6 +27,11 @@ public class BlockBreakConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return BlockBreakConfig.getConfig(player); return BlockBreakConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -27,6 +27,11 @@ public class BlockInteractConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return BlockInteractConfig.getConfig(player); return BlockInteractConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -30,6 +30,11 @@ public class BlockPlaceConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return BlockPlaceConfig.getConfig(player); return BlockPlaceConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -29,6 +29,11 @@ public class ChatConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return ChatConfig.getConfig(player); return ChatConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -30,6 +30,11 @@ public class CombinedConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return CombinedConfig.getConfig(player); return CombinedConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
private static final Map<String, CombinedConfig> worldsMap = new HashMap<String, CombinedConfig>(); private static final Map<String, CombinedConfig> worldsMap = new HashMap<String, CombinedConfig>();

View File

@ -29,6 +29,11 @@ public class FightConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return FightConfig.getConfig(player); return FightConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -31,6 +31,11 @@ public class InventoryConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return InventoryConfig.getConfig(player); return InventoryConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -30,6 +30,11 @@ public class MovingConfig extends ACheckConfig {
public final ICheckConfig getConfig(final Player player) { public final ICheckConfig getConfig(final Player player) {
return MovingConfig.getConfig(player); return MovingConfig.getConfig(player);
} }
@Override
public void removeAllConfigs() {
clear(); // Band-aid.
}
}; };
/** The map containing the configurations per world. */ /** The map containing the configurations per world. */

View File

@ -1,32 +1,44 @@
package fr.neatmonster.nocheatplus.checks.net; package fr.neatmonster.nocheatplus.checks.net;
import fr.neatmonster.nocheatplus.actions.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.access.ACheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
/** /**
* Configuration for the net checks (fast version, sparse). * Configuration for the net checks (fast version, sparse).
* @author web4web1 * @author web4web1
* *
*/ */
public class NetConfig { public class NetConfig extends ACheckConfig {
public final boolean flyingFrequencyActive; public final boolean flyingFrequencyActive;
public final int flyingFrequencySeconds; public final int flyingFrequencySeconds;
public final int flyingFrequencyMaxPackets; public final double flyingFrequencyPPS;
public final boolean flyingFrequencyCancelRedundant; public final ActionList flyingFrequencyActions;
public final boolean flyingFrequencyRedundantActive;
public final int flyingFrequencyRedundantSeconds;
public final ActionList flyingFrequencyRedundantActions;
public final boolean soundDistanceActive; public final boolean soundDistanceActive;
/** Maximum distance for lightning effects (squared). */ /** Maximum distance for lightning effects (squared). */
public final double soundDistanceSq; public final double soundDistanceSq;
public NetConfig(final ConfigFile config) { public NetConfig(final ConfigFile config) {
super(config, ConfPaths.NET);
final ConfigFile globalConfig = ConfigManager.getConfigFile(); final ConfigFile globalConfig = ConfigManager.getConfigFile();
flyingFrequencyActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE); flyingFrequencyActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE);
flyingFrequencySeconds = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_SECONDS)); flyingFrequencySeconds = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_SECONDS));
flyingFrequencyMaxPackets = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS)); flyingFrequencyPPS = Math.max(1.0, globalConfig.getDouble(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND));
flyingFrequencyCancelRedundant = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT); flyingFrequencyActions = config.getOptimizedActionList(ConfPaths.NET_FLYINGFREQUENCY_ACTIONS, Permissions.NET_FLYINGFREQUENCY);
flyingFrequencyRedundantActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT);
flyingFrequencyRedundantSeconds = Math.max(1, config.getInt(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_SECONDS));
// Same permission for "silent".
flyingFrequencyRedundantActions = config.getOptimizedActionList(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_ACTIONS, Permissions.NET_FLYINGFREQUENCY);
soundDistanceActive = config.getBoolean(ConfPaths.NET_SOUNDDISTANCE_ACTIVE); soundDistanceActive = config.getBoolean(ConfPaths.NET_SOUNDDISTANCE_ACTIVE);
double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE); double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE);
@ -34,4 +46,16 @@ public class NetConfig {
} }
@Override
public boolean isEnabled(final CheckType checkType) {
switch(checkType) {
case NET_FLYINGFREQUENCY:
return flyingFrequencyActive;
case NET_SOUNDDISTANCE:
return soundDistanceActive;
default:
return true;
}
}
} }

View File

@ -1,5 +1,8 @@
package fr.neatmonster.nocheatplus.checks.net; package fr.neatmonster.nocheatplus.checks.net;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
import fr.neatmonster.nocheatplus.config.ConfigFile; import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.WorldConfigCache; import fr.neatmonster.nocheatplus.config.WorldConfigCache;
@ -8,7 +11,7 @@ import fr.neatmonster.nocheatplus.config.WorldConfigCache;
* @author web4web1 * @author web4web1
* *
*/ */
public class NetConfigCache extends WorldConfigCache<NetConfig> { public class NetConfigCache extends WorldConfigCache<NetConfig> implements CheckConfigFactory {
public NetConfigCache() { public NetConfigCache() {
super(true); super(true);
@ -19,4 +22,14 @@ public class NetConfigCache extends WorldConfigCache<NetConfig> {
return new NetConfig(configFile); return new NetConfig(configFile);
} }
@Override
public NetConfig getConfig(final Player player) {
return getConfig(player.getWorld());
}
@Override
public void removeAllConfigs() {
clearAllConfigs();
}
} }

View File

@ -0,0 +1,30 @@
package fr.neatmonster.nocheatplus.checks.net;
import fr.neatmonster.nocheatplus.checks.access.ACheckData;
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
/**
* Primary thread only.
* @author web4web1
*
*/
public class NetData extends ACheckData {
/** All flying packets, use Monotonic.millis() for time. */
public final ActionFrequency flyingFrequencyAll;
public boolean flyingFrequencyOnGround = false;
public long flyingFrequencyTimeOnGround = 0L;
public long flyingFrequencyTimeNotOnGround = 0L;
/**
* Monitors redundant packets, when more than 20 packets per second are
* sent. Use Monotonic.millis() for time.
*/
public final ActionFrequency flyingFrequencyRedundantFreq;
public NetData(final NetConfig config) {
super(config);
flyingFrequencyAll = new ActionFrequency(config.flyingFrequencySeconds, 1000L);
flyingFrequencyRedundantFreq = new ActionFrequency(config.flyingFrequencyRedundantSeconds, 1000L);
}
}

View File

@ -0,0 +1,41 @@
package fr.neatmonster.nocheatplus.checks.net;
import java.util.HashMap;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
/**
* Currently primary thread only!
* @author web4web1
*
*/
public class NetDataFactory implements CheckDataFactory {
private final HashMap<String, NetData> dataMap = new HashMap<String, NetData>();
@Override
public void removeAllData() {
dataMap.clear();
}
@Override
public NetData getData(Player player) {
NetData data = dataMap.get(player.getName());
if (data != null) {
return data;
} else {
data = new NetData((NetConfig) CheckType.NET.getConfigFactory().getConfig(player));
dataMap.put(player.getName(), data);
return data;
}
}
@Override
public NetData removeData(String playerName) {
return dataMap.remove(playerName);
}
}

View File

@ -595,7 +595,7 @@ public abstract class ConfPaths {
public static final String MOVING_TRACE_SIZE = MOVING_TRACE + "size"; public static final String MOVING_TRACE_SIZE = MOVING_TRACE + "size";
public static final String MOVING_TRACE_MERGEDIST = MOVING_TRACE + "mergedist"; public static final String MOVING_TRACE_MERGEDIST = MOVING_TRACE + "mergedist";
private static final String NET = CHECKS + "net."; public static final String NET = CHECKS + "net.";
private static final String NET_SOUNDDISTANCE = NET + "sounddistance."; private static final String NET_SOUNDDISTANCE = NET + "sounddistance.";
public static final String NET_SOUNDDISTANCE_ACTIVE = NET_SOUNDDISTANCE + "active"; public static final String NET_SOUNDDISTANCE_ACTIVE = NET_SOUNDDISTANCE + "active";
@ -606,8 +606,12 @@ public abstract class ConfPaths {
@GlobalConfig @GlobalConfig
public static final String NET_FLYINGFREQUENCY_SECONDS = NET_FLYINGFREQUENCY + "seconds"; public static final String NET_FLYINGFREQUENCY_SECONDS = NET_FLYINGFREQUENCY + "seconds";
@GlobalConfig @GlobalConfig
public static final String NET_FLYINGFREQUENCY_MAXPACKETS = NET_FLYINGFREQUENCY + "maxpackets"; public static final String NET_FLYINGFREQUENCY_PACKETSPERSECOND = NET_FLYINGFREQUENCY + "packetspersecond";
public static final String NET_FLYINGFREQUENCY_CANCELREDUNDANT = NET_FLYINGFREQUENCY + "cancelredundant"; public static final String NET_FLYINGFREQUENCY_ACTIONS = NET_FLYINGFREQUENCY + "actions";
private static final String NET_FLYINGFREQUENCY_REDUNDANT = NET_FLYINGFREQUENCY + "reduceredundant.";
public static final String NET_FLYINGFREQUENCY_REDUNDANT_ACTIVE = NET_FLYINGFREQUENCY_REDUNDANT + "active";
public static final String NET_FLYINGFREQUENCY_REDUNDANT_SECONDS = NET_FLYINGFREQUENCY_REDUNDANT + "seconds";
public static final String NET_FLYINGFREQUENCY_REDUNDANT_ACTIONS = NET_FLYINGFREQUENCY_REDUNDANT + "actions";
public static final String STRINGS = "strings"; public static final String STRINGS = "strings";
@ -650,6 +654,8 @@ public abstract class ConfPaths {
public static final String INVENTORY_ENSURECLOSE = "checks.inventory.ensureclose"; public static final String INVENTORY_ENSURECLOSE = "checks.inventory.ensureclose";
@Moved(newPath = LOGGING_EXTENDED_STATUS) @Moved(newPath = LOGGING_EXTENDED_STATUS)
public static final String LOGGING_DEBUG = "logging.debug"; public static final String LOGGING_DEBUG = "logging.debug";
@Moved(newPath = NET_FLYINGFREQUENCY_REDUNDANT_ACTIVE)
public static final String NET_FLYINGFREQUENCY_CANCELREDUNDANT = "checks.net.flyingfrequency.cancelredundant";
@Deprecated @Deprecated
public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics"; public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics";
@Deprecated @Deprecated
@ -666,5 +672,7 @@ public abstract class ConfPaths {
public static final String FIGHT_KNOCKBACK_INTERVAL = "checks.fight.knockback.interval"; public static final String FIGHT_KNOCKBACK_INTERVAL = "checks.fight.knockback.interval";
@Deprecated @Deprecated
public static final String FIGHT_KNOCKBACK_ACTIONS = "checks.fight.knockback.actions"; public static final String FIGHT_KNOCKBACK_ACTIONS = "checks.fight.knockback.actions";
@Deprecated
public static final String NET_FLYINGFREQUENCY_MAXPACKETS = "checks.net.flyingfrequency.maxpackets";
} }

View File

@ -434,8 +434,11 @@ public class DefaultConfig extends ConfigFile {
// FlyingFrequency // FlyingFrequency
set(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE, true); set(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE, true);
set(ConfPaths.NET_FLYINGFREQUENCY_SECONDS, 5); set(ConfPaths.NET_FLYINGFREQUENCY_SECONDS, 5);
set(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS, 300); set(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND, 60);
set(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT, true); set(ConfPaths.NET_FLYINGFREQUENCY_ACTIONS, "cancel"); // TODO: Log actions.
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_ACTIVE, true);
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_SECONDS, 3);
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_ACTIONS, "cancel"); // TODO: Log actions.
// SoundDistance // SoundDistance
set(ConfPaths.NET_SOUNDDISTANCE_ACTIVE, true); set(ConfPaths.NET_SOUNDDISTANCE_ACTIVE, true);

View File

@ -114,6 +114,9 @@ public class Permissions {
public static final String INVENTORY_ITEMS = INVENTORY + ".items"; public static final String INVENTORY_ITEMS = INVENTORY + ".items";
public static final String INVENTORY_OPEN = INVENTORY + ".open"; public static final String INVENTORY_OPEN = INVENTORY + ".open";
public static final String NET = CHECKS + ".net";
public static final String NET_FLYINGFREQUENCY = NET + ".flyingfrequency";
public static final String MOVING = CHECKS + ".moving"; public static final String MOVING = CHECKS + ".moving";
public static final String MOVING_CREATIVEFLY = MOVING + ".creativefly"; public static final String MOVING_CREATIVEFLY = MOVING + ".creativefly";
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets"; public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";

View File

@ -28,15 +28,7 @@ import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory; import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
import fr.neatmonster.nocheatplus.checks.access.ICheckConfig; import fr.neatmonster.nocheatplus.checks.access.ICheckConfig;
import fr.neatmonster.nocheatplus.checks.access.ICheckData; import fr.neatmonster.nocheatplus.checks.access.ICheckData;
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig;
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig;
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceConfig;
import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
import fr.neatmonster.nocheatplus.checks.combined.CombinedConfig;
import fr.neatmonster.nocheatplus.checks.combined.CombinedData; import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.compat.BridgeMisc; import fr.neatmonster.nocheatplus.compat.BridgeMisc;
import fr.neatmonster.nocheatplus.components.ComponentRegistry; import fr.neatmonster.nocheatplus.components.ComponentRegistry;
import fr.neatmonster.nocheatplus.components.ComponentWithName; import fr.neatmonster.nocheatplus.components.ComponentWithName;
@ -406,19 +398,20 @@ public class DataManager implements Listener, INotifyReload, INeedConfig, Compon
} }
/** /**
* Clear all stored (check) config instances.<br> * Clear all cached CheckConfig instances.<br>
* This does not cleanup ConfigManager, i.e. stored yml-versions. * This does not cleanup ConfigManager, i.e. stored yml-versions.
*/ */
public static void clearConfigs() { public static void clearConfigs() {
// The dirty bit ! final Set<CheckConfigFactory> factories = new LinkedHashSet<CheckConfigFactory>();
BlockBreakConfig.clear(); for (final CheckType checkType : CheckType.values()) {
BlockInteractConfig.clear(); final CheckConfigFactory factory = checkType.getConfigFactory();
BlockPlaceConfig.clear(); if (factory != null) {
ChatConfig.clear(); factories.add(factory);
CombinedConfig.clear(); }
FightConfig.clear(); }
InventoryConfig.clear(); for (final CheckConfigFactory factory : factories) {
MovingConfig.clear(); factory.removeAllConfigs();
}
} }
/** /**

View File

@ -169,7 +169,7 @@ permissions:
nocheatplus.checks.moving.nofall: nocheatplus.checks.moving.nofall:
description: Allow the player to bypass the NoFall check. description: Allow the player to bypass the NoFall check.
nocheatplus.checks.moving.passable: nocheatplus.checks.moving.passable:
description: Allow bypassing the passable check. description: Allow bypassing the Passable check.
nocheatplus.checks.moving.survivalfly: nocheatplus.checks.moving.survivalfly:
description: Allow the player to bypass the SurvivalFly check. description: Allow the player to bypass the SurvivalFly check.
children: children:
@ -183,6 +183,11 @@ permissions:
description: Allow the player to sprint backwards. description: Allow the player to sprint backwards.
nocheatplus.checks.moving.survivalfly.step: nocheatplus.checks.moving.survivalfly.step:
description: Allow the player to use the 'step' functionality of his client. description: Allow the player to use the 'step' functionality of his client.
nocheatplus.checks.net:
description: Allow a player to bypass the net (packet) checks.
children:
nocheatplus.checks.net.flyingfrequency:
description: Bypass the FlyingFrequency check (flying packet spam).
nocheatplus.mods: nocheatplus.mods:
description: Allow the player to use all the client mods. description: Allow the player to use all the client mods.