Use lastKeepAliveTime (NetData) in fight.godmode.

* Update lastKeepAliveTime from KeepAliveFrequency (even if that is
disabled).
* Update lastKeepAliveTime from FlyingFrequency too.
* Allow to test for feature tags efficiently.
This commit is contained in:
asofold 2015-02-09 21:59:37 +01:00
parent de3b95de5d
commit 260ba01246
8 changed files with 182 additions and 143 deletions

View File

@ -22,7 +22,7 @@ import fr.neatmonster.nocheatplus.utilities.TrigUtil;
/**
* Prevent extremely fast ticking by just sending packets that don't do anything
* new and also don't trigger moving events in CraftBukkit.
* new and also don't trigger moving events in CraftBukkit. Also update lastKeepAliveTime.
*
* @author dev1mc
*
@ -71,6 +71,7 @@ public class FlyingFrequency extends BaseAdapter {
counters.add(idHandled, 1);
final NetData data = dataFactory.getData(player);
data.lastKeepAliveTime = time; // Update without much of a contract.
// Counting all packets.
// TODO: Consider using the NetStatic check.

View File

@ -12,6 +12,13 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetData;
/**
* Limit keep alive packet frequency, set lastKeepAliveTime (even if disabled,
* in case fight.godmode is enabled).
*
* @author asofold
*
*/
public class KeepAliveFrequency extends BaseAdapter {
/** Dummy check for bypass checking and actions execution. */
@ -30,15 +37,17 @@ public class KeepAliveFrequency extends BaseAdapter {
event.setCancelled(true);
return;
}
// 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;
}
final NetData data = dataFactory.getData(player);
// TODO: Better modeling of actual packet sequences (flying vs. keep alive vs. request/ping).
// TODO: Better integration wih god-mode check / trigger reset ndt.
// TODO: Better integration with god-mode check / trigger reset ndt.
data.keepAliveFreq.add(time, 1f);
// Use last time accepted as a hard reference.
final float first = data.keepAliveFreq.bucketScore(0);
if (first > 1f && !check.hasBypass(player)) {
// Trigger a violation.

View File

@ -42,9 +42,11 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload {
StaticLog.logInfo("Adding packet level hooks for ProtocolLib (MC " + ProtocolLibrary.getProtocolManager().getMinecraftVersion().getVersion() + ")...");
// Register Classes having a constructor with Plugin as argument.
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
// (Also sets lastKeepAliveTime, if enabled.)
register("fr.neatmonster.nocheatplus.checks.net.protocollib.FlyingFrequency", plugin);
}
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_KEEPALIVEFREQUENCY_ACTIVE)) {
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);
}
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {

View File

@ -3,8 +3,10 @@ package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.TickTask;
@ -120,7 +122,9 @@ public class GodMode extends Check {
}
else{
final int dht = tick - data.godModeHealthDecreaseTick;
if (dht <= 20) return false;
if (dht <= 20) {
return false;
}
}
final FightConfig cc = FightConfig.getConfig(player);
@ -129,11 +133,10 @@ public class GodMode extends Check {
final long now = System.currentTimeMillis();
final long maxAge = cc.godModeLagMaxAge;
long keepAlive = Long.MIN_VALUE;
// TODO: Get keepAlive from NetData, if available.
if (keepAlive > now || keepAlive == Long.MIN_VALUE) {
keepAlive = CheckUtils.guessKeepAliveTime(player, now, maxAge);
if (NCPAPIProvider.getNoCheatPlusAPI().hasFeatureTag("checks", "KeepAliveFrequency")) {
keepAlive = ((NetData) (CheckType.NET_KEEPALIVEFREQUENCY.getDataFactory().getData(player))).lastKeepAliveTime;
}
// TODO: else: still check the other time stamp ?
keepAlive = Math.max(keepAlive, CheckUtils.guessKeepAliveTime(player, now, maxAge));
if (keepAlive != Double.MIN_VALUE && now - keepAlive > cc.godModeLagMinAge && now - keepAlive < maxAge){
// Assume lag.
@ -151,7 +154,9 @@ public class GodMode extends Check {
if (executeActions(player, data.godModeVL, delta, FightConfig.getConfig(player).godModeActions)){
cancel = true;
}
else cancel = false;
else {
cancel = false;
}
}
else{
cancel = false;

View File

@ -30,6 +30,10 @@ public class NetData extends ACheckData {
*/
public ActionFrequency keepAliveFreq = new ActionFrequency(20, 1000);
// Shared.
/** Last time some action was received (keep alive or flying). Also maintained for fight.godmode. */
public long lastKeepAliveTime = 0L;
public NetData(final NetConfig config) {
super(config);
flyingFrequencyAll = new ActionFrequency(config.flyingFrequencySeconds, 1000L);

View File

@ -52,6 +52,14 @@ public interface NoCheatPlusAPI extends ComponentRegistry<Object>, ComponentRegi
*/
public void setFeatureTags(String key, Collection<String> featureTags);
/**
* Test if an entry has been made.
* @param key
* @param feature
* @return
*/
public boolean hasFeatureTag(String key, String feature);
/**
* Get a map with all feature tags that have been set.
* @return

View File

@ -1309,6 +1309,12 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
present.addAll(featureTags);
}
@Override
public boolean hasFeatureTag(final String key, final String feature) {
final Collection<String> features = this.featureTags.get(key);
return features == null ? false : features.contains(feature);
}
@Override
public Map<String, Set<String>> getAllFeatureTags() {
final LinkedHashMap<String, Set<String>> allTags = new LinkedHashMap<String, Set<String>>();

View File

@ -134,6 +134,10 @@ public class PluginTests {
throw new UnsupportedOperationException();
}
@Override
public boolean hasFeatureTag(String key, String feature) {
throw new UnsupportedOperationException();
}
}