Add essential configurability for "stray-packet" cancelling (TP-ACK).

This commit is contained in:
asofold 2015-10-18 17:26:43 +02:00
parent 0b7a259985
commit 1e70dc0730
6 changed files with 35 additions and 25 deletions

View File

@ -106,24 +106,26 @@ public class FlyingFrequency extends BaseAdapter {
}
return;
}
switch(data.teleportQueue.processAck(packetData)) {
case CANCEL: {
// TODO: Configuration for cancel (or implement skipping violation level escalation)?
event.setCancelled(true);
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " wait for ACK on teleport, cancel packet: " + packetData);
if (cc.flyingFrequencyStrayPacketsCancel) {
switch(data.teleportQueue.processAck(packetData)) {
case CANCEL: {
// TODO: Configuration for cancel (or implement skipping violation level escalation)?
event.setCancelled(true);
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " wait for ACK on teleport, cancel packet: " + packetData);
}
return;
}
return;
}
case ACK: {
// Skip processing ACK packets, no cancel.
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " interpret as ACK for a teleport: " + packetData);
case ACK: {
// Skip processing ACK packets, no cancel.
if (data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " interpret as ACK for a teleport: " + packetData);
}
return;
}
default: {
// Continue.
}
return;
}
default: {
// Continue.
}
}
}

View File

@ -10,6 +10,7 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
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.logging.Streams;
@ -37,14 +38,15 @@ public class OutgoingPosition extends BaseAdapter {
}
final long time = System.currentTimeMillis();
// TODO: Configurability.
final Player player = event.getPlayer();
final NetData data = dataFactory.getData(player);
final DataPacketFlying packetData = interpretPacket(event.getPacket(), time, data);
if (packetData != null && data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " Expect ACK on outgoing position: " + packetData);
final NetConfig cc = configFactory.getConfig(player);
if (cc.flyingFrequencyActive && cc.flyingFrequencyStrayPacketsCancel) {
final NetData data = dataFactory.getData(player);
final DataPacketFlying packetData = interpretPacket(event.getPacket(), time, data);
if (packetData != null && data.debug) {
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " Expect ACK on outgoing position: " + packetData);
}
}
}
private DataPacketFlying interpretPacket(final PacketContainer packet, final long time, final NetData data) {

View File

@ -170,7 +170,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload, Joi
}
final Player player = event.getPlayer();
final NetConfig cc = configFactory.getConfig(player);
if (cc.flyingFrequencyActive) {
if (cc.flyingFrequencyActive && cc.flyingFrequencyStrayPacketsCancel) {
final NetData data = dataFactory.getData(player);
// Register expected location for comparison with outgoing packets.
data.teleportQueue.onTeleportEvent(new DataPacketFlying(false, to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch(), System.currentTimeMillis()));

View File

@ -19,6 +19,7 @@ public class NetConfig extends ACheckConfig {
public final int flyingFrequencySeconds;
public final double flyingFrequencyPPS;
public final ActionList flyingFrequencyActions;
public final boolean flyingFrequencyStrayPacketsCancel;
public final boolean flyingFrequencyRedundantActive;
public final int flyingFrequencyRedundantSeconds;
public final ActionList flyingFrequencyRedundantActions;
@ -32,14 +33,15 @@ public class NetConfig extends ACheckConfig {
public NetConfig(final ConfigFile config) {
super(config, ConfPaths.NET, new String[] {
Permissions.NET_FLYINGFREQUENCY, Permissions.NET_KEEPALIVEFREQUENCY
});
Permissions.NET_FLYINGFREQUENCY, Permissions.NET_KEEPALIVEFREQUENCY
});
final ConfigFile globalConfig = ConfigManager.getConfigFile();
flyingFrequencyActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE);
flyingFrequencySeconds = Math.max(1, globalConfig.getInt(ConfPaths.NET_FLYINGFREQUENCY_SECONDS));
flyingFrequencyPPS = Math.max(1.0, globalConfig.getDouble(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND));
flyingFrequencyActions = config.getOptimizedActionList(ConfPaths.NET_FLYINGFREQUENCY_ACTIONS, Permissions.NET_FLYINGFREQUENCY);
flyingFrequencyStrayPacketsCancel = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_STRAYPACKETS_CANCEL);
flyingFrequencyRedundantActive = config.getBoolean(ConfPaths.NET_FLYINGFREQUENCY_CANCELREDUNDANT);
flyingFrequencyRedundantSeconds = Math.max(1, config.getInt(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_SECONDS));
// Same permission for "silent".

View File

@ -618,6 +618,9 @@ public abstract class ConfPaths {
@GlobalConfig
public static final String NET_FLYINGFREQUENCY_PACKETSPERSECOND = NET_FLYINGFREQUENCY + "packetspersecond";
public static final String NET_FLYINGFREQUENCY_ACTIONS = NET_FLYINGFREQUENCY + "actions";
public static final String NET_FLYINGFREQUENCY_STRAYPACKETS = NET_FLYINGFREQUENCY + "straypackets";
public static final String NET_FLYINGFREQUENCY_STRAYPACKETS_CANCEL = NET_FLYINGFREQUENCY_STRAYPACKETS + "cancel";
// TODO: Reduceredundant has been removed (implement or remove config).
private static final String NET_FLYINGFREQUENCY_REDUNDANT = NET_FLYINGFREQUENCY + "reduceredundant.";
public static final String NET_FLYINGFREQUENCY_REDUNDANT_ACTIVE = NET_FLYINGFREQUENCY_REDUNDANT + "active";
@GlobalConfig

View File

@ -450,6 +450,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.NET_FLYINGFREQUENCY_SECONDS, 5);
set(ConfPaths.NET_FLYINGFREQUENCY_PACKETSPERSECOND, 60);
set(ConfPaths.NET_FLYINGFREQUENCY_ACTIONS, "cancel"); // TODO: Log actions.
set(ConfPaths.NET_FLYINGFREQUENCY_STRAYPACKETS_CANCEL, true);
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_ACTIVE, true);
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_SECONDS, 3);
set(ConfPaths.NET_FLYINGFREQUENCY_REDUNDANT_ACTIONS, "cancel"); // TODO: Log actions.