Move AttackFrequency and KeepAliveFrequency as checks to NCPCore.

+ Add adapters to "packet-listeners" in feature tags.
This commit is contained in:
asofold 2015-11-24 06:35:58 +01:00
parent 98ae3fb192
commit 8b1eb86543
6 changed files with 69 additions and 20 deletions

View File

@ -1,4 +1,4 @@
package fr.neatmonster.nocheatplus.checks.net.protocollib;
package fr.neatmonster.nocheatplus.checks.net;
import org.bukkit.entity.Player;

View File

@ -1,5 +1,7 @@
package fr.neatmonster.nocheatplus.checks.net.protocollib;
import java.util.Arrays;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -7,10 +9,12 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketEvent;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.net.KeepAliveFrequency;
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
/**
* Limit keep alive packet frequency, set lastKeepAliveTime (even if disabled,
@ -19,13 +23,19 @@ import fr.neatmonster.nocheatplus.checks.net.NetData;
* @author asofold
*
*/
public class KeepAliveFrequency extends BaseAdapter {
public class KeepAliveAdapter extends BaseAdapter {
/** Dummy check for bypass checking and actions execution. */
private final Check check = new Check(CheckType.NET_KEEPALIVEFREQUENCY) {};
private final KeepAliveFrequency frequencyCheck = new KeepAliveFrequency();
public KeepAliveFrequency(Plugin plugin) {
public KeepAliveAdapter(Plugin plugin) {
super(plugin, ListenerPriority.LOW, PacketType.Play.Client.KEEP_ALIVE);
// Add feature tags for checks.
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_KEEPALIVEFREQUENCY_ACTIVE)) {
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("checks", Arrays.asList(KeepAliveFrequency.class.getSimpleName()));
}
NCPAPIProvider.getNoCheatPlusAPI().addComponent(frequencyCheck);
}
@Override
@ -40,21 +50,14 @@ public class KeepAliveFrequency extends BaseAdapter {
// Always update last received time.
final NetData data = dataFactory.getData(player);
data.lastKeepAliveTime = time;
// Check activation.
final NetConfig cc = configFactory.getConfig(player);
if (!cc.keepAliveFrequencyActive) {
return;
}
// Run check(s).
// TODO: Match vs. outgoing keep alive requests.
// TODO: Better modeling of actual packet sequences (flying vs. keep alive vs. request/ping).
// TODO: Better integration with god-mode check / trigger reset ndt.
data.keepAliveFreq.add(time, 1f);
final float first = data.keepAliveFreq.bucketScore(0);
if (first > 1f && !check.hasBypass(player)) {
// Trigger a violation.
final double vl = Math.max(first - 1f, data.keepAliveFreq.score(1f) - data.keepAliveFreq.numberOfBuckets());
if (check.executeActions(player, vl, 1.0, cc.keepAliveFrequencyActions)) {
event.setCancelled(true);
}
if (cc.keepAliveFrequencyActive && frequencyCheck.check(player, time, data, cc)) {
event.setCancelled(true);
}
}

View File

@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.checks.net.protocollib;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;
@ -15,6 +16,8 @@ import fr.neatmonster.nocheatplus.checks.net.FlyingFrequency;
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
@ -55,6 +58,12 @@ public class MovingFlying extends BaseAdapter {
PacketType.Play.Client.POSITION,
PacketType.Play.Client.POSITION_LOOK
});
// Add feature tags for checks.
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("checks", Arrays.asList(FlyingFrequency.class.getSimpleName()));
}
NCPAPIProvider.getNoCheatPlusAPI().addComponent(flyingFrequency);
}
@Override

View File

@ -73,7 +73,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload, Joi
}
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_KEEPALIVEFREQUENCY_ACTIVE) || ConfigManager.isTrueForAnyConfig(ConfPaths.FIGHT_GODMODE_CHECK)) {
// (Set lastKeepAlive if this or fight.godmode is enabled.)
register("fr.neatmonster.nocheatplus.checks.net.protocollib.KeepAliveFrequency", plugin);
register("fr.neatmonster.nocheatplus.checks.net.protocollib.KeepAliveAdapter", plugin);
}
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
register("fr.neatmonster.nocheatplus.checks.net.protocollib.SoundDistance", plugin);
@ -84,7 +84,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload, Joi
names.add(adapter.getClass().getSimpleName());
}
StaticLog.logInfo("Available (and activated) packet level hooks: " + StringUtil.join(names, " | "));
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("checks", names);
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("packet-listeners", names);
} else {
StaticLog.logInfo("No packet level hooks activated.");
}

View File

@ -12,6 +12,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.net.AttackFrequency;
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.config.ConfPaths;

View File

@ -0,0 +1,36 @@
package fr.neatmonster.nocheatplus.checks.net;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class KeepAliveFrequency extends Check {
public KeepAliveFrequency() {
super(CheckType.NET_KEEPALIVEFREQUENCY);
}
/**
* Checks hasBypass on violation only.
* @param player
* @param time
* @param data
* @param cc
* @return If to cancel.
*/
public boolean check(final Player player, final long time, final NetData data, final NetConfig cc) {
data.keepAliveFreq.add(time, 1f);
final float first = data.keepAliveFreq.bucketScore(0);
if (first > 1f && !CheckUtils.hasBypass(CheckType.NET_KEEPALIVEFREQUENCY, player, data)) {
// Trigger a violation.
final double vl = Math.max(first - 1f, data.keepAliveFreq.score(1f) - data.keepAliveFreq.numberOfBuckets());
if (executeActions(player, vl, 1.0, cc.keepAliveFrequencyActions)) {
return true;
}
}
return false;
}
}