mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-14 19:41:21 +01:00
[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:
parent
b3fa312ceb
commit
86732764e3
@ -1,8 +1,6 @@
|
||||
package fr.neatmonster.nocheatplus.checks.net.protocollib;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -13,14 +11,16 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
|
||||
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.net.NetConfig;
|
||||
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.stats.Counters;
|
||||
import fr.neatmonster.nocheatplus.time.monotonic.Monotonic;
|
||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
|
||||
@ -31,66 +31,36 @@ import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
* @author dev1mc
|
||||
*
|
||||
*/
|
||||
public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener {
|
||||
public class FlyingFrequency extends PacketAdapter {
|
||||
|
||||
public static final double minMoveDistSq = 1f / 256; // PlayerConnection magic.
|
||||
|
||||
public static final float minLookChange = 10f;
|
||||
|
||||
// TODO: Most efficient registration + optimize (primary thread or asynchronous).
|
||||
|
||||
private class FFData {
|
||||
// Setup for flying packets.
|
||||
public static final int numBooleans = 3;
|
||||
public static final int indexOnGround = 0;
|
||||
public static final int indexhasPos = 1;
|
||||
public static final int indexhasLook = 2;
|
||||
|
||||
public final ActionFrequency all;
|
||||
// Last move on-ground.
|
||||
public boolean onGround = false;
|
||||
public long timeOnGround = 0;
|
||||
public long timeNotOnGround = 0;
|
||||
// Thresholds for firing moving events (CraftBukkit).
|
||||
public static final double minMoveDistSq = 1f / 256; // PlayerConnection magic.
|
||||
public static final float minLookChange = 10f;
|
||||
|
||||
public FFData(int seconds) {
|
||||
all = new ActionFrequency(seconds, 1000L);
|
||||
}
|
||||
}
|
||||
/** Dummy check to access hasBypass for FlyingFrequency. */
|
||||
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 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 boolean cancelRedundant = true;
|
||||
|
||||
private final NetConfigCache configs;
|
||||
private final NetDataFactory dataFactory;
|
||||
|
||||
public FlyingFrequency(NetConfigCache configs, Plugin plugin) {
|
||||
public FlyingFrequency(Plugin plugin) {
|
||||
// PacketPlayInFlying[3, legacy: 10]
|
||||
super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate?
|
||||
this.configs = configs;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
this.configs = (NetConfigCache) CheckType.NET.getConfigFactory();
|
||||
this.dataFactory = (NetDataFactory) CheckType.NET.getDataFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,32 +79,32 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
||||
return;
|
||||
}
|
||||
|
||||
final FFData data = getData(player.getName(), cc);
|
||||
final long t = System.currentTimeMillis();
|
||||
final NetData data = dataFactory.getData(player);
|
||||
final long time = Monotonic.millis();
|
||||
// Counting all packets.
|
||||
data.all.add(t, 1f);
|
||||
final float allScore = data.all.score(1f);
|
||||
if (allScore > cc.flyingFrequencyMaxPackets) {
|
||||
counters.add(idSilent, 1); // Until it is sure if we can get these async.
|
||||
// TODO: Consider using the NetStatic check.
|
||||
data.flyingFrequencyAll.add(time, 1f);
|
||||
final float allScore = data.flyingFrequencyAll.score(1f);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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: Debug logging (better with integration into DataManager).
|
||||
// TODO: Consider to compare to moving data directly, skip keeping track extra.
|
||||
|
||||
final PacketContainer packet = event.getPacket();
|
||||
final List<Boolean> booleans = packet.getBooleans().getValues();
|
||||
if (booleans.size() != FFData.numBooleans) {
|
||||
if (booleans.size() != FlyingFrequency.numBooleans) {
|
||||
return packetMismatch();
|
||||
}
|
||||
|
||||
@ -143,30 +113,29 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
||||
// Can not check.
|
||||
return false;
|
||||
}
|
||||
final boolean hasPos = booleans.get(FFData.indexhasPos).booleanValue();
|
||||
final boolean hasLook = booleans.get(FFData.indexhasLook).booleanValue();
|
||||
final boolean onGround = booleans.get(FFData.indexOnGround).booleanValue();
|
||||
final boolean hasPos = booleans.get(FlyingFrequency.indexhasPos).booleanValue();
|
||||
final boolean hasLook = booleans.get(FlyingFrequency.indexhasLook).booleanValue();
|
||||
final boolean onGround = booleans.get(FlyingFrequency.indexOnGround).booleanValue();
|
||||
boolean onGroundSkip = false;
|
||||
|
||||
// Allow at least one on-ground change per state and second.
|
||||
// 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.
|
||||
final long time = Monotonic.millis();
|
||||
final long lastTime;
|
||||
if (onGround) {
|
||||
lastTime = data.timeOnGround;
|
||||
data.timeOnGround = time;
|
||||
lastTime = data.flyingFrequencyTimeOnGround;
|
||||
data.flyingFrequencyTimeOnGround = time;
|
||||
} else {
|
||||
lastTime = data.timeNotOnGround;
|
||||
data.timeNotOnGround = time;
|
||||
lastTime = data.flyingFrequencyTimeNotOnGround;
|
||||
data.flyingFrequencyTimeNotOnGround = time;
|
||||
}
|
||||
if (time - lastTime > 1000) {
|
||||
// Override
|
||||
onGroundSkip = true;
|
||||
}
|
||||
}
|
||||
data.onGround = onGround;
|
||||
data.flyingFrequencyOnGround = onGround;
|
||||
|
||||
if (hasPos) {
|
||||
final List<Double> doubles = packet.getDoubles().getValues();
|
||||
@ -206,14 +175,16 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Could check first bucket or even just 50 ms to last packet.
|
||||
if (allScore / cc.flyingFrequencySeconds > 20f) {
|
||||
counters.add(idRedundant, 1);
|
||||
// Packet is redundant, if more than 20 packets per second arrive.
|
||||
if (allScore / cc.flyingFrequencySeconds > 20f && !frequency.hasBypass(player)) {
|
||||
// (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;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log warning to console, halt checking for redundant packets.
|
||||
|
@ -12,7 +12,7 @@ import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
|
||||
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.INotifyReload;
|
||||
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
|
||||
@ -28,7 +28,6 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
||||
*/
|
||||
public class ProtocolLibComponent implements DisableListener, INotifyReload {
|
||||
|
||||
private final NetConfigCache configs = new NetConfigCache();
|
||||
private final List<PacketAdapter> registeredPacketAdapters = new LinkedList<PacketAdapter>();
|
||||
|
||||
public ProtocolLibComponent(Plugin plugin) {
|
||||
@ -75,7 +74,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
|
||||
private void register(Class<? extends PacketAdapter> clazz, Plugin plugin) {
|
||||
try {
|
||||
// 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);
|
||||
registeredPacketAdapters.add(adapter);
|
||||
} catch (Throwable t) {
|
||||
@ -92,6 +91,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
|
||||
@Override
|
||||
public void onReload() {
|
||||
unregister();
|
||||
CheckType.NET.getDataFactory().removeAllData(); // Currently needed for FlyingFRequency.
|
||||
register(Bukkit.getPluginManager().getPlugin("NoCheatPlus")); // Store instead ?
|
||||
}
|
||||
|
||||
@ -107,7 +107,6 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
|
||||
}
|
||||
}
|
||||
registeredPacketAdapters.clear();
|
||||
configs.clearAllConfigs();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
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.NetConfigCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||
@ -38,9 +39,9 @@ public class SoundDistance extends PacketAdapter {
|
||||
private final NetConfigCache configs;
|
||||
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);
|
||||
this.configs = configs;
|
||||
this.configs = (NetConfigCache) CheckType.NET.getConfigFactory(); // TODO: DataManager.getConfig(NetConfigCache.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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
|
||||
* the player
|
||||
@ -170,17 +171,29 @@ public abstract class Check implements MCAccessHolder{
|
||||
if (!type.isEnabled(player)) {
|
||||
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.
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
// Check permissions directly.
|
||||
if (player.hasPermission(type.getPermission())) {
|
||||
return false;
|
||||
final String permission = type.getPermission();
|
||||
if (permission != null && player.hasPermission(permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type.hasCachedPermission(player)) {
|
||||
// Assume asynchronously running check.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// TODO: ExemptionManager relies on initial setup (problematic).
|
||||
return !NCPExemptionManager.isExempted(player, type);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.InventoryData;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -96,6 +98,10 @@ public enum CheckType {
|
||||
MOVING_PASSABLE(MOVING, Permissions.MOVING_PASSABLE),
|
||||
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;
|
||||
|
||||
/** If not null, this is the check group usually. */
|
||||
@ -125,6 +131,10 @@ public enum CheckType {
|
||||
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.
|
||||
* @param configFactory
|
||||
|
@ -18,4 +18,9 @@ public interface CheckConfigFactory {
|
||||
*/
|
||||
public ICheckConfig getConfig(Player player);
|
||||
|
||||
/**
|
||||
* Remove all stored configurations.
|
||||
*/
|
||||
public void removeAllConfigs();
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,11 @@ public class BlockBreakConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return BlockBreakConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -27,6 +27,11 @@ public class BlockInteractConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return BlockInteractConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -30,6 +30,11 @@ public class BlockPlaceConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return BlockPlaceConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -29,6 +29,11 @@ public class ChatConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return ChatConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -30,6 +30,11 @@ public class CombinedConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return CombinedConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
private static final Map<String, CombinedConfig> worldsMap = new HashMap<String, CombinedConfig>();
|
||||
|
@ -29,6 +29,11 @@ public class FightConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return FightConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -31,6 +31,11 @@ public class InventoryConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return InventoryConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -30,6 +30,11 @@ public class MovingConfig extends ACheckConfig {
|
||||
public final ICheckConfig getConfig(final Player player) {
|
||||
return MovingConfig.getConfig(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clear(); // Band-aid.
|
||||
}
|
||||
};
|
||||
|
||||
/** The map containing the configurations per world. */
|
||||
|
@ -1,32 +1,44 @@
|
||||
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.ConfigFile;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
import fr.neatmonster.nocheatplus.permissions.Permissions;
|
||||
|
||||
/**
|
||||
* Configuration for the net checks (fast version, sparse).
|
||||
* @author web4web1
|
||||
*
|
||||
*/
|
||||
public class NetConfig {
|
||||
public class NetConfig extends ACheckConfig {
|
||||
|
||||
public final boolean flyingFrequencyActive;
|
||||
public final int flyingFrequencySeconds;
|
||||
public final int flyingFrequencyMaxPackets;
|
||||
public final boolean flyingFrequencyCancelRedundant;
|
||||
public final double flyingFrequencyPPS;
|
||||
public final ActionList flyingFrequencyActions;
|
||||
public final boolean flyingFrequencyRedundantActive;
|
||||
public final int flyingFrequencyRedundantSeconds;
|
||||
public final ActionList flyingFrequencyRedundantActions;
|
||||
|
||||
public final boolean soundDistanceActive;
|
||||
/** Maximum distance for lightning effects (squared). */
|
||||
public final double soundDistanceSq;
|
||||
|
||||
public NetConfig(final ConfigFile config) {
|
||||
super(config, ConfPaths.NET);
|
||||
|
||||
final ConfigFile globalConfig = ConfigManager.getConfigFile();
|
||||
flyingFrequencyActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE);
|
||||
flyingFrequencySeconds = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_SECONDS));
|
||||
flyingFrequencyMaxPackets = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS));
|
||||
flyingFrequencyCancelRedundant = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT);
|
||||
flyingFrequencyPPS = Math.max(1.0, globalConfig.getDouble(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND));
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
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.WorldConfigCache;
|
||||
|
||||
@ -8,7 +11,7 @@ import fr.neatmonster.nocheatplus.config.WorldConfigCache;
|
||||
* @author web4web1
|
||||
*
|
||||
*/
|
||||
public class NetConfigCache extends WorldConfigCache<NetConfig> {
|
||||
public class NetConfigCache extends WorldConfigCache<NetConfig> implements CheckConfigFactory {
|
||||
|
||||
public NetConfigCache() {
|
||||
super(true);
|
||||
@ -19,4 +22,14 @@ public class NetConfigCache extends WorldConfigCache<NetConfig> {
|
||||
return new NetConfig(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetConfig getConfig(final Player player) {
|
||||
return getConfig(player.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllConfigs() {
|
||||
clearAllConfigs();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -595,7 +595,7 @@ public abstract class ConfPaths {
|
||||
public static final String MOVING_TRACE_SIZE = MOVING_TRACE + "size";
|
||||
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.";
|
||||
public static final String NET_SOUNDDISTANCE_ACTIVE = NET_SOUNDDISTANCE + "active";
|
||||
@ -606,8 +606,12 @@ public abstract class ConfPaths {
|
||||
@GlobalConfig
|
||||
public static final String NET_FLYINGFREQUENCY_SECONDS = NET_FLYINGFREQUENCY + "seconds";
|
||||
@GlobalConfig
|
||||
public static final String NET_FLYINGFREQUENCY_MAXPACKETS = NET_FLYINGFREQUENCY + "maxpackets";
|
||||
public static final String NET_FLYINGFREQUENCY_CANCELREDUNDANT = NET_FLYINGFREQUENCY + "cancelredundant";
|
||||
public static final String NET_FLYINGFREQUENCY_PACKETSPERSECOND = NET_FLYINGFREQUENCY + "packetspersecond";
|
||||
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";
|
||||
@ -650,6 +654,8 @@ public abstract class ConfPaths {
|
||||
public static final String INVENTORY_ENSURECLOSE = "checks.inventory.ensureclose";
|
||||
@Moved(newPath = LOGGING_EXTENDED_STATUS)
|
||||
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
|
||||
public static final String MISCELLANEOUS_REPORTTOMETRICS = "miscellaneous.reporttometrics";
|
||||
@Deprecated
|
||||
@ -666,5 +672,7 @@ public abstract class ConfPaths {
|
||||
public static final String FIGHT_KNOCKBACK_INTERVAL = "checks.fight.knockback.interval";
|
||||
@Deprecated
|
||||
public static final String FIGHT_KNOCKBACK_ACTIONS = "checks.fight.knockback.actions";
|
||||
@Deprecated
|
||||
public static final String NET_FLYINGFREQUENCY_MAXPACKETS = "checks.net.flyingfrequency.maxpackets";
|
||||
|
||||
}
|
||||
|
@ -434,8 +434,11 @@ public class DefaultConfig extends ConfigFile {
|
||||
// FlyingFrequency
|
||||
set(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE, true);
|
||||
set(ConfPaths.NET_FLYINGFREQUENCY_SECONDS, 5);
|
||||
set(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS, 300);
|
||||
set(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT, true);
|
||||
set(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND, 60);
|
||||
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
|
||||
set(ConfPaths.NET_SOUNDDISTANCE_ACTIVE, true);
|
||||
|
@ -114,6 +114,9 @@ public class Permissions {
|
||||
public static final String INVENTORY_ITEMS = INVENTORY + ".items";
|
||||
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_CREATIVEFLY = MOVING + ".creativefly";
|
||||
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
|
||||
|
@ -28,15 +28,7 @@ import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
|
||||
import fr.neatmonster.nocheatplus.checks.access.ICheckConfig;
|
||||
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.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.components.ComponentRegistry;
|
||||
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.
|
||||
*/
|
||||
public static void clearConfigs() {
|
||||
// The dirty bit !
|
||||
BlockBreakConfig.clear();
|
||||
BlockInteractConfig.clear();
|
||||
BlockPlaceConfig.clear();
|
||||
ChatConfig.clear();
|
||||
CombinedConfig.clear();
|
||||
FightConfig.clear();
|
||||
InventoryConfig.clear();
|
||||
MovingConfig.clear();
|
||||
final Set<CheckConfigFactory> factories = new LinkedHashSet<CheckConfigFactory>();
|
||||
for (final CheckType checkType : CheckType.values()) {
|
||||
final CheckConfigFactory factory = checkType.getConfigFactory();
|
||||
if (factory != null) {
|
||||
factories.add(factory);
|
||||
}
|
||||
}
|
||||
for (final CheckConfigFactory factory : factories) {
|
||||
factory.removeAllConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,7 +169,7 @@ permissions:
|
||||
nocheatplus.checks.moving.nofall:
|
||||
description: Allow the player to bypass the NoFall check.
|
||||
nocheatplus.checks.moving.passable:
|
||||
description: Allow bypassing the passable check.
|
||||
description: Allow bypassing the Passable check.
|
||||
nocheatplus.checks.moving.survivalfly:
|
||||
description: Allow the player to bypass the SurvivalFly check.
|
||||
children:
|
||||
@ -183,6 +183,11 @@ permissions:
|
||||
description: Allow the player to sprint backwards.
|
||||
nocheatplus.checks.moving.survivalfly.step:
|
||||
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:
|
||||
description: Allow the player to use all the client mods.
|
||||
|
Loading…
Reference in New Issue
Block a user