Attack motion check

This commit is contained in:
Skid Revenant 2018-09-16 18:41:07 -05:00
parent 41f75e01fc
commit 2f53fb4dc5
9 changed files with 98 additions and 12 deletions

View File

@ -289,6 +289,7 @@ public class MovingFlying extends BaseAdapter {
// }
// Process cancel and debug log.
data.lastFlyingTime = System.currentTimeMillis();
if (cancel) {
event.setCancelled(true);
}

View File

@ -17,6 +17,7 @@ package fr.neatmonster.nocheatplus.checks.net.protocollib;
import java.lang.reflect.Method;
import java.util.Arrays;
import fr.neatmonster.nocheatplus.checks.net.AttackMotion;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -94,6 +95,7 @@ public class UseEntityAdapter extends BaseAdapter {
private static final int ATTACK = 0x02;
private final AttackFrequency attackFrequency;
private final AttackMotion attackMotion;
private final LegacyReflectionSet legacySet;
@ -107,6 +109,8 @@ public class UseEntityAdapter extends BaseAdapter {
"checks", Arrays.asList(AttackFrequency.class.getSimpleName()));
}
attackFrequency = new AttackFrequency();
attackMotion = new AttackMotion();
NCPAPIProvider.getNoCheatPlusAPI().addComponent(attackFrequency);
this.legacySet = getLegacyReflectionSet();
}
@ -181,11 +185,15 @@ public class UseEntityAdapter extends BaseAdapter {
// AttackFrequency
if (isAttack) {
data.lastUseEntityTime = System.currentTimeMillis();
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
if (attackFrequency.isEnabled(player, pData)
&& attackFrequency.check(player, time, data, cc, pData)) {
cancel = true;
}
cancel = (attackMotion.isEnabled(player, pData) &&
attackMotion.check(player, time, data, cc, pData)) ||
(attackFrequency.isEnabled(player, pData)
&& attackFrequency.check(player, time, data, cc, pData));
}
if (cancel) {

View File

@ -108,6 +108,8 @@ public enum CheckType {
NET_PACKETFREQUENCY(CheckTypeType.CHECK, NET, Permissions.NET_PACKETFREQUENCY),
NET_SOUNDDISTANCE(CheckTypeType.CHECK, NET), // Can not exempt players from this one.
NET_ATTACKMOTION(CheckTypeType.CHECK, NET),
;
public static enum CheckTypeType {

View File

@ -1,4 +1,61 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.checks.net;
public class AttackMotion {
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.players.IPlayerData;
import fr.neatmonster.nocheatplus.utilities.TickTask;
import org.bukkit.entity.Player;
public class AttackMotion extends Check {
public AttackMotion() {
super(CheckType.NET_ATTACKMOTION);
}
public boolean check(final Player player, final long time,
final NetData data, final NetConfig cc, final IPlayerData pData) {
boolean cancel = false;
// The player attacked in the same tick as motion updates
if (data.lastFlyingTime + cc.attackMotionTimeDiff > time) {
// Add a vl depending on the time difference
data.attackMotVL += (System.currentTimeMillis() - data.lastFlyingTime) + 12;
if (data.attackMotVL > 120) {
// Trigger a violation.
final ViolationData vd = new ViolationData(this, player, data.attackMotVL / 20.0, 1.0, cc.attackMotionActions);
if (pData.isDebugActive(type) || vd.needsParameters()) {
vd.setParameter(ParameterName.VIOLATIONS, Integer.toString(data.attackMotVL));
}
if (executeActions(vd).willCancel()) {
cancel = true;
}
// Feed Improbable.
TickTask.requestImprobableUpdate(player.getUniqueId(), 4f);
}
} else {
// Attack didnt come after motion updates
// Decrease their vl
data.attackMotVL *= 0.5;
}
return cancel;
}
}

View File

@ -57,6 +57,9 @@ public class NetConfig extends ACheckConfig {
public final float attackFrequencyLimitSecondsEight;
public final ActionList attackFrequencyActions;
public final ActionList attackMotionActions;
public final long attackMotionTimeDiff;
public final int flyingFrequencySeconds;
public final double flyingFrequencyPPS;
public final ActionList flyingFrequencyActions;
@ -89,6 +92,9 @@ public class NetConfig extends ACheckConfig {
attackFrequencyLimitSecondsEight = config.getInt(ConfPaths.NET_ATTACKFREQUENCY_SECONDS_EIGHT);
attackFrequencyActions = config.getOptimizedActionList(ConfPaths.NET_ATTACKFREQUENCY_ACTIONS, Permissions.NET_ATTACKFREQUENCY);
attackMotionTimeDiff = config.getInt(ConfPaths.NET_ATTACKMOTION_TIME);
attackMotionActions = config.getOptimizedActionList(ConfPaths.NET_ATTACKMOTION_ACTIONS, Permissions.NET_ATTACKMOTION);
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);

View File

@ -41,6 +41,9 @@ public class NetData extends ACheckData {
// AttackFrequency
public ActionFrequency attackFrequencySeconds = new ActionFrequency(16, 500);
// AttackMotion
public ActionFrequency attackMotionSeconds = new ActionFrequency(20, 500);
// FlyingFrequency
/** All flying packets, use System.currentTimeMillis() for time. */
public final ActionFrequency flyingFrequencyAll;
@ -67,6 +70,11 @@ public class NetData extends ACheckData {
*/
public long lastKeepAliveTime = 0L;
public long lastUseEntityTime = 0L;
public int attackMotVL;
public long lastFlyingTime = 0L;
/**
* Detect teleport-ACK packets, consistency check to only use outgoing
* position if there has been a PlayerTeleportEvent for it.

View File

@ -654,7 +654,7 @@ public abstract class ConfPaths {
public static final String MOVING_SURVIVALFLY_SETBACKPOLICY_FALLDAMAGE = MOVING_SURVIVALFLY_SETBACKPOLICY + "falldamage";
public static final String MOVING_SURVIVALFLY_SETBACKPOLICY_VOIDTOVOID = MOVING_SURVIVALFLY_SETBACKPOLICY + "voidtovoid";
public static final String MOVING_SURVIVALFLY_ACTIONS = MOVING_SURVIVALFLY + "actions";
@GlobalConfig
public static final String MOVING_SURVIVALFLY_HOVER = MOVING_SURVIVALFLY + "hover.";
public static final String MOVING_SURVIVALFLY_HOVER_CHECK = MOVING_SURVIVALFLY_HOVER + SUB_ACTIVE;
@ -704,7 +704,7 @@ public abstract class ConfPaths {
private static final String MOVING_VEHICLE_MOREPACKETS = MOVING_VEHICLE + "morepackets.";
public static final String MOVING_VEHICLE_MOREPACKETS_CHECK = MOVING_VEHICLE_MOREPACKETS + SUB_ACTIVE;
public static final String MOVING_VEHICLE_MOREPACKETS_ACTIONS = MOVING_VEHICLE_MOREPACKETS + "actions";
private static final String MOVING_VEHICLE_ENVELOPE = MOVING_VEHICLE + "envelope.";
private static final String MOVING_VEHICLE_ENVELOPE = MOVING_VEHICLE + "envelope.";
public static final String MOVING_VEHICLE_ENVELOPE_ACTIVE = MOVING_VEHICLE_ENVELOPE + SUB_ACTIVE;
public static final String MOVING_VEHICLE_ENVELOPE_HSPEEDCAP = MOVING_VEHICLE_ENVELOPE + "hdistcap"; // Section.
public static final String MOVING_VEHICLE_ENVELOPE_ACTIONS = MOVING_VEHICLE_ENVELOPE + "actions";
@ -760,6 +760,10 @@ public abstract class ConfPaths {
private static final String NET_SUPERSEDED_FLYING = NET_SUPERSEDED + "flying.";
public static final String NET_SUPERSEDED_FLYING_CANCELWAITING = NET_SUPERSEDED_FLYING + "cancelwaiting";
private static final String NET_ATTACKMOTION = NET + "attackmotion.";
public static final String NET_ATTACKMOTION_ACTIONS = NET_ATTACKMOTION + "actions";
public static final String NET_ATTACKMOTION_TIME = NET_ATTACKMOTION + "timedifference";
public static final String STRINGS = "strings";
// Compatibility section (possibly temporary).

View File

@ -160,6 +160,7 @@ public class Permissions {
public static final RegisteredPermission NET_FLYINGFREQUENCY = add(NET + ".flyingfrequency");
public static final RegisteredPermission NET_KEEPALIVEFREQUENCY = add(NET + ".keepalivefrequency");
public static final RegisteredPermission NET_PACKETFREQUENCY = add(NET + ".packetfrequency");
public static final RegisteredPermission NET_ATTACKMOTION = add(NET + ".attackmotion");
public static final RegisteredPermission MOVING = add(CHECKS + ".moving");
public static final RegisteredPermission MOVING_CREATIVEFLY = add(MOVING + ".creativefly");

View File

@ -43,8 +43,6 @@ permissions:
default: false
nocheatplus.checks.blockbreak.noswing.silent:
default: false
nocheatplus.checks.blockbreak.reach.silent:
default: false
nocheatplus.checks.blockbreak.wrongblock.silent:
default: false
nocheatplus.checks.blockinteract.direction.silent:
@ -320,7 +318,9 @@ permissions:
description: Bypass the KeepAliveFrequency check (keep alive packet spam).
nocheatplus.checks.net.packetfrequency:
description: Bypass the PacketFrequency check (overall packet spam).
nocheatplus.checks.net.attackmotion:
description: Bypass the AttackMotion check (attacking in the same tick as motion updated).
nocheatplus.mods:
description: Allow the player to use all the client mods.
children:
@ -412,7 +412,6 @@ permissions:
description: Allow toggling notifications.
children:
nocheatplus.notify: true
nocheatplus.filter.command.nocheatplus: true
nocheatplus.command.reload:
description: Allow the player to reload NoCheatPlus configuration.
children:
@ -509,7 +508,7 @@ permissions:
nocheatplus.bypass.denylogin:
description: Bypass the login denial, such as exists with the ncp denylogin command.
# Various shortcuts:
# Various shortcuts:
nocheatplus.shortcut:
description: 'Shortcut permissions designed to be somewhat "safe" to give (see children permissions).'
children: