Skip to content

Commit

Permalink
Simplify/optimize morepackets checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jul 17, 2014
1 parent bf0b515 commit 7cc9368
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
@@ -1,7 +1,5 @@
package fr.neatmonster.nocheatplus.checks.moving;

import java.util.Map;

import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -73,17 +71,20 @@ public Location check(final Player player, final PlayerLocation from, final Play

// Player used up buffer, they fail the check.
if (data.morePacketsBuffer < 0) {
data.morePacketsPackets = -data.morePacketsBuffer;


// Increment violation level.
data.morePacketsVL = -data.morePacketsBuffer;

// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (executeActions(player, data.morePacketsVL, -data.morePacketsBuffer, MovingConfig.getConfig(player).morePacketsActions)){
final ViolationData vd = new ViolationData(this, player, data.morePacketsVL, -data.morePacketsBuffer, cc.morePacketsActions);
if (cc.debug || vd.needsParameters()) {
vd.setParameter(ParameterName.PACKETS, Integer.toString(-data.morePacketsBuffer));
}
if (executeActions(vd)){
newTo = data.getMorePacketsSetBack();
}

}

if (data.morePacketsLastTime + 1000 < time) {
Expand Down Expand Up @@ -111,7 +112,7 @@ public Location check(final Player player, final PlayerLocation from, final Play
}
} else if (data.morePacketsLastTime > time) {
// Security check, maybe system time changed.
data.morePacketsLastTime = time;
data.morePacketsLastTime = time;
}

if (newTo == null) {
Expand All @@ -123,10 +124,4 @@ public Location check(final Player player, final PlayerLocation from, final Play
return new Location(player.getWorld(), newTo.getX(), newTo.getY(), newTo.getZ(), to.getYaw(), to.getPitch());
}

@Override
protected Map<ParameterName, String> getParameterMap(final ViolationData violationData) {
final Map<ParameterName, String> parameters = super.getParameterMap(violationData);
parameters.put(ParameterName.PACKETS, String.valueOf(MovingData.getData(violationData.player).morePacketsPackets));
return parameters;
}
}
@@ -1,7 +1,5 @@
package fr.neatmonster.nocheatplus.checks.moving;

import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -70,14 +68,17 @@ public Location check(final Player player, final Location from, final Location t

// Player used up buffer, they fail the check.
if (data.morePacketsVehicleBuffer < 0) {
data.morePacketsVehiclePackets = -data.morePacketsVehicleBuffer;

// Increment violation level.
data.morePacketsVehicleVL = -data.morePacketsVehicleBuffer;

// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (executeActions(player, data.morePacketsVehicleVL, -data.morePacketsVehicleBuffer, cc.morePacketsVehicleActions)){
final ViolationData vd = new ViolationData(this, player, data.morePacketsVehicleVL, -data.morePacketsVehicleBuffer, cc.morePacketsVehicleActions);
if (cc.debug || vd.needsParameters()) {
vd.setParameter(ParameterName.PACKETS, Integer.toString(-data.morePacketsVehicleBuffer));
}
if (executeActions(vd)){
newTo = data.getMorePacketsVehicleSetBack();
}
}
Expand All @@ -91,34 +92,33 @@ public Location check(final Player player, final Location from, final Location t

// If there was a long pause (maybe server lag?), allow buffer to grow up to 100.
if (seconds > 2) {
if (data.morePacketsVehicleBuffer > 100)
data.morePacketsVehicleBuffer = 100;
} else if (data.morePacketsVehicleBuffer > 50)
// Only allow growth up to 50.
if (data.morePacketsVehicleBuffer > 100) {
data.morePacketsVehicleBuffer = 100;
}
} else if (data.morePacketsVehicleBuffer > 50) {
// Only allow growth up to 50.
data.morePacketsVehicleBuffer = 50;

}

// Set the new "last" time.
data.morePacketsVehicleLastTime = time;

// Set the new "setback" location.
if (newTo == null)
data.setMorePacketsVehicleSetBack(from);
} else if (data.morePacketsVehicleLastTime > time)
// Security check, maybe system time changed.
if (newTo == null) {
data.setMorePacketsVehicleSetBack(from);
}
} else if (data.morePacketsVehicleLastTime > time) {
// Security check, maybe system time changed.
data.morePacketsVehicleLastTime = time;
}

if (newTo == null)
return null;
if (newTo == null) {
return null;
}

// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to allow the
// player to look somewhere else despite getting pulled back by NoCheatPlus.
return new Location(player.getWorld(), newTo.getX(), newTo.getY(), newTo.getZ(), to.getYaw(), to.getPitch());
}

@Override
protected Map<ParameterName, String> getParameterMap(final ViolationData violationData) {
final Map<ParameterName, String> parameters = super.getParameterMap(violationData);
parameters.put(ParameterName.PACKETS, String.valueOf(MovingData.getData(violationData.player).morePacketsVehiclePackets));
return parameters;
}
}
Expand Up @@ -149,13 +149,11 @@ public static void onReload() {
// Data of the more packets check.
public int morePacketsBuffer = 50;
public long morePacketsLastTime;
public int morePacketsPackets;
private Location morePacketsSetback = null;

// Data of the more packets vehicle check.
public int morePacketsVehicleBuffer = 50;
public long morePacketsVehicleLastTime;
public int morePacketsVehiclePackets;
private Location morePacketsVehicleSetback = null;
/** Task id of the morepackets set-back task. */
public int morePacketsVehicleTaskId = -1;
Expand Down

0 comments on commit 7cc9368

Please sign in to comment.