This commit is contained in:
AimbotPvP 2018-11-16 13:54:34 +00:00 committed by GitHub
commit fc4133650e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 185 additions and 23 deletions

View File

@ -272,6 +272,11 @@ public class MovingFlying extends BaseAdapter {
// TODO: Counters for hasPos, hasLook, both, none.
if (event.getPacket().getBooleans().readSafely(1)) {
data.flyingMoves = 0;
} else {
++data.flyingMoves;
}
// Actual packet frequency check.
// TODO: Consider using the NetStatic check.
if (!cancel && !skipFlyingFrequency
@ -289,6 +294,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,20 +95,31 @@ public class UseEntityAdapter extends BaseAdapter {
private static final int ATTACK = 0x02;
private final AttackFrequency attackFrequency;
private final AttackMotion attackMotion;
private final LegacyReflectionSet legacySet;
public UseEntityAdapter(Plugin plugin) {
super(plugin, PacketType.Play.Client.USE_ENTITY);
this.checkType = CheckType.NET_ATTACKFREQUENCY;
this.checkType = CheckType.NET;
// Add feature tags for checks.
if (NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager().isActiveAnywhere(
CheckType.NET_ATTACKFREQUENCY)) {
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags(
"checks", Arrays.asList(AttackFrequency.class.getSimpleName()));
}
if (NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager().isActiveAnywhere(
CheckType.NET_ATTACKMOTION)) {
NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags(
"checks", Arrays.asList(AttackMotion.class.getSimpleName()));
}
attackFrequency = new AttackFrequency();
attackMotion = new AttackMotion();
NCPAPIProvider.getNoCheatPlusAPI().addComponent(attackFrequency);
NCPAPIProvider.getNoCheatPlusAPI().addComponent(attackMotion);
this.legacySet = getLegacyReflectionSet();
}
@ -181,11 +193,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,9 @@ 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),
NET_POSITIONUPDATE(CheckTypeType.CHECK, NET),
;
public static enum CheckTypeType {

View File

@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@ -383,9 +384,10 @@ public class SurvivalFly extends Check {
// Prevent players from walking on a liquid in a too simple way.
// TODO: Find something more effective against more smart methods (limitjump helps already).
// TODO: yDistance == 0D <- should there not be a tolerance +- or 0...x ?
// TODO: 0D = 0.0
// TODO: Complete re-modeling.
if (hDistanceAboveLimit <= 0D && hDistance > 0.1D && yDistance == 0D && !toOnGround && !fromOnGround
&& lastMove.toIsValid && lastMove.yDistance == 0D
if (hDistanceAboveLimit <= 0.0 && hDistance > 0.1 && yDistance == 0.0 && !toOnGround && !fromOnGround
&& lastMove.toIsValid && lastMove.yDistance == 0.0
&& BlockProperties.isLiquid(to.getTypeId()) && BlockProperties.isLiquid(from.getTypeId())
&& !from.isHeadObstructed() && !to.isHeadObstructed() // TODO: Might decrease margin here.
) {
@ -395,6 +397,16 @@ public class SurvivalFly extends Check {
tags.add("waterwalk");
}
// Prevent players from walking on water or in air with a very low delta between y distances
if (hDistanceAboveLimit <= 0D && hDistance > 0.22 && !toOnGround && !fromOnGround
&& lastMove.toIsValid && (yDistance > 0.0 && yDistance < 0.03 || lastMove.yDistance > 0.0 && lastMove.yDistance < 0.03)
&& BlockProperties.isLiquid(from.getTypeId())
&& !from.isHeadObstructed() && !to.isHeadObstructed()) {
hDistanceAboveLimit = Math.max(hDistanceAboveLimit, hDistance);
tags.add("badwalk");
}
// Prevent players from sprinting if they're moving backwards (allow buffers to cover up !?).
if (sprinting && data.lostSprintCount == 0 && !cc.assumeSprint && hDistance > thisMove.walkSpeed && !data.hasActiveHorVel()) {
// (Ignore some cases, in order to prevent false positives.)

View File

@ -85,9 +85,8 @@ public class FrictionAxisVelocity {
// (Altered entries should be kept, since they get used right away.)
}
// Decrease counts for queued.
final Iterator<AccountEntry> it = queued.iterator();
while (it.hasNext()) {
it.next().actCount --;
for (AccountEntry aQueued : queued) {
aQueued.actCount--;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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;
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.Bukkit;
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 / 12.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.95;
}
return cancel;
}
}

View File

@ -48,14 +48,15 @@ public class FlyingFrequency extends Check {
*/
public boolean check(final Player player, final DataPacketFlying packetData, final long time,
final NetData data, final NetConfig cc, final IPlayerData pData) {
if (data.flyingMoves > 20) {
return true;
}
data.flyingFrequencyAll.add(time, 1f);
final float allScore = data.flyingFrequencyAll.score(1f);
if (allScore / cc.flyingFrequencySeconds > cc.flyingFrequencyPPS
&& executeActions(player, allScore / cc.flyingFrequencySeconds - cc.flyingFrequencyPPS, 1.0 / cc.flyingFrequencySeconds, cc.flyingFrequencyActions).willCancel()) {
return true;
} else {
return false;
}
return allScore / cc.flyingFrequencySeconds > cc.flyingFrequencyPPS
&& executeActions(player, allScore / cc.flyingFrequencySeconds - cc.flyingFrequencyPPS, 1.0 / cc.flyingFrequencySeconds, cc.flyingFrequencyActions).willCancel();
}
}

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 = Math.max(0, 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

@ -47,6 +47,7 @@ public class NetData extends ACheckData {
public boolean flyingFrequencyOnGround = false;
public long flyingFrequencyTimeOnGround = 0L;
public long flyingFrequencyTimeNotOnGround = 0L;
public int flyingMoves;
/**
* Monitors redundant packets, when more than 20 packets per second are
* sent. Use System.currentTimeMillis() for time.
@ -67,6 +68,13 @@ 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

@ -0,0 +1,40 @@
/*
* 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;
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.Bukkit;
import org.bukkit.entity.Player;
public class PositionUpdate extends Check {
public PositionUpdate() {
super(CheckType.NET_POSITIONUPDATE);
}
public boolean check(final Player player, final long time,
final NetData data, final NetConfig cc, final IPlayerData pData, boolean position) {
boolean cancel = false;
//TODO:
return cancel;
}
}

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

@ -579,6 +579,9 @@ public class DefaultConfig extends ConfigFile {
// Superseded
set(ConfPaths.NET_SUPERSEDED_FLYING_CANCELWAITING, true, 1090);
// AttackMotion
set(ConfPaths.NET_ATTACKMOTION_TIME, 25, 1144);
set(ConfPaths.NET_ATTACKMOTION_ACTIONS, "cancel vl>2 cancel log:attackmotion:0:3:if", 1144);
// TODO: An extra file might suit these.
final String start = "[player] failed [check]: ";
@ -659,6 +662,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.STRINGS + ".tempkick1", "ncp tempkick [player] 1 Wait a minute!", 785);
set(ConfPaths.STRINGS + ".tempkick5", "ncp tempkick [player] 5 You have five minutes to think about it!", 785);
set(ConfPaths.STRINGS + ".vehicleenvelope", start + "moved a vehicle too fast ([tags])" + end, 785);
set(ConfPaths.STRINGS + ".attackmotion", start + "attacked at the same tick as motion updates" + end, 1144);
// Compatibility settings.
set(ConfPaths.COMPATIBILITY_EXEMPTIONS_WILDCARD_DEFAULT_METADATA_ACTIVE, true, 785);

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: