Simplify/optimize morepackets checks.

This commit is contained in:
asofold 2014-07-17 20:06:20 +02:00
parent bf0b515889
commit 7cc936878e
3 changed files with 30 additions and 37 deletions

View File

@ -1,7 +1,5 @@
package fr.neatmonster.nocheatplus.checks.moving; package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -73,14 +71,17 @@ public class MorePackets extends Check {
// Player used up buffer, they fail the check. // Player used up buffer, they fail the check.
if (data.morePacketsBuffer < 0) { if (data.morePacketsBuffer < 0) {
data.morePacketsPackets = -data.morePacketsBuffer;
// Increment violation level. // Increment violation level.
data.morePacketsVL = -data.morePacketsBuffer; data.morePacketsVL = -data.morePacketsBuffer;
// Execute whatever actions are associated with this check and the violation level and find out if we should // Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event. // 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(); newTo = data.getMorePacketsSetBack();
} }
@ -123,10 +124,4 @@ public class MorePackets extends Check {
return new Location(player.getWorld(), newTo.getX(), newTo.getY(), newTo.getZ(), to.getYaw(), to.getPitch()); 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;
}
} }

View File

@ -1,7 +1,5 @@
package fr.neatmonster.nocheatplus.checks.moving; package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -70,14 +68,17 @@ public class MorePacketsVehicle extends Check {
// Player used up buffer, they fail the check. // Player used up buffer, they fail the check.
if (data.morePacketsVehicleBuffer < 0) { if (data.morePacketsVehicleBuffer < 0) {
data.morePacketsVehiclePackets = -data.morePacketsVehicleBuffer;
// Increment violation level. // Increment violation level.
data.morePacketsVehicleVL = -data.morePacketsVehicleBuffer; data.morePacketsVehicleVL = -data.morePacketsVehicleBuffer;
// Execute whatever actions are associated with this check and the violation level and find out if we should // Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event. // 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(); newTo = data.getMorePacketsVehicleSetBack();
} }
} }
@ -91,34 +92,33 @@ public class MorePacketsVehicle extends Check {
// If there was a long pause (maybe server lag?), allow buffer to grow up to 100. // If there was a long pause (maybe server lag?), allow buffer to grow up to 100.
if (seconds > 2) { if (seconds > 2) {
if (data.morePacketsVehicleBuffer > 100) if (data.morePacketsVehicleBuffer > 100) {
data.morePacketsVehicleBuffer = 100; data.morePacketsVehicleBuffer = 100;
} else if (data.morePacketsVehicleBuffer > 50) }
} else if (data.morePacketsVehicleBuffer > 50) {
// Only allow growth up to 50. // Only allow growth up to 50.
data.morePacketsVehicleBuffer = 50; data.morePacketsVehicleBuffer = 50;
}
// Set the new "last" time. // Set the new "last" time.
data.morePacketsVehicleLastTime = time; data.morePacketsVehicleLastTime = time;
// Set the new "setback" location. // Set the new "setback" location.
if (newTo == null) if (newTo == null) {
data.setMorePacketsVehicleSetBack(from); data.setMorePacketsVehicleSetBack(from);
} else if (data.morePacketsVehicleLastTime > time) }
} else if (data.morePacketsVehicleLastTime > time) {
// Security check, maybe system time changed. // Security check, maybe system time changed.
data.morePacketsVehicleLastTime = time; data.morePacketsVehicleLastTime = time;
}
if (newTo == null) if (newTo == null) {
return null; return null;
}
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to allow the // 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. // 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()); 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;
}
} }

View File

@ -149,13 +149,11 @@ public class MovingData extends ACheckData {
// Data of the more packets check. // Data of the more packets check.
public int morePacketsBuffer = 50; public int morePacketsBuffer = 50;
public long morePacketsLastTime; public long morePacketsLastTime;
public int morePacketsPackets;
private Location morePacketsSetback = null; private Location morePacketsSetback = null;
// Data of the more packets vehicle check. // Data of the more packets vehicle check.
public int morePacketsVehicleBuffer = 50; public int morePacketsVehicleBuffer = 50;
public long morePacketsVehicleLastTime; public long morePacketsVehicleLastTime;
public int morePacketsVehiclePackets;
private Location morePacketsVehicleSetback = null; private Location morePacketsVehicleSetback = null;
/** Task id of the morepackets set-back task. */ /** Task id of the morepackets set-back task. */
public int morePacketsVehicleTaskId = -1; public int morePacketsVehicleTaskId = -1;