mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-03-10 05:29:12 +01:00
Use TickTask.getLag(..., true), within the primary thread.
This counts in if the current tick is taking longer than 50 ms.
This commit is contained in:
parent
78d51b3904
commit
5f82584072
@ -100,7 +100,7 @@ public class FastConsume extends Check implements Listener{
|
||||
final long expectedDuration = cc.fastConsumeDuration;
|
||||
if (timeSpent < expectedDuration){
|
||||
// TODO: Might have to do a specialized check for lag spikes here instead.
|
||||
final float lag = TickTask.getLag(expectedDuration);
|
||||
final float lag = TickTask.getLag(expectedDuration, true);
|
||||
if (timeSpent * lag < expectedDuration){
|
||||
final double difference = (expectedDuration - timeSpent * lag) / 100.0;
|
||||
data.instantEatVL += difference;
|
||||
|
@ -29,7 +29,7 @@ public class Speed extends Check {
|
||||
|
||||
if (data.speedCount > cc.speedLimit){
|
||||
// Lag correction
|
||||
final int correctedCount = (int) ((double) data.speedCount / TickTask.getLag(time - data.speedTime));
|
||||
final int correctedCount = (int) ((double) data.speedCount / TickTask.getLag(time - data.speedTime, true));
|
||||
if (correctedCount > cc.speedLimit){
|
||||
data.speedVL ++;
|
||||
if (executeActions(player, data.speedVL, 1, cc.speedActions)){
|
||||
|
@ -57,7 +57,7 @@ public class AutoSign extends Check {
|
||||
|
||||
final long editTime = time - data.autoSignPlacedTime;
|
||||
long expected = getExpectedEditTime(lines);
|
||||
expected = (long) (expected / TickTask.getLag(expected));
|
||||
expected = (long) (expected / TickTask.getLag(expected, true));
|
||||
|
||||
if (expected > editTime){
|
||||
tags.add("edit_time");
|
||||
|
@ -113,7 +113,7 @@ public class Angle extends Check {
|
||||
// Is the violation is superior to the threshold defined in the configuration?
|
||||
if (violation > cc.angleThreshold) {
|
||||
// Has the server lagged?
|
||||
if (TickTask.getLag(1000) < 1.5f){
|
||||
if (TickTask.getLag(1000, true) < 1.5f){
|
||||
// TODO: 1.5 is a fantasy value.
|
||||
// If it hasn't, increment the violation level.
|
||||
data.angleVL += violation;
|
||||
|
@ -71,7 +71,7 @@ public class Critical extends Check {
|
||||
final List<String> tags = new ArrayList<String>();
|
||||
|
||||
// Player failed the check, but this is influenced by lag so don't do it if there was lag.
|
||||
if (TickTask.getLag(1000) < 1.5){
|
||||
if (TickTask.getLag(1000, true) < 1.5){
|
||||
// TODO: 1.5 is a fantasy value.
|
||||
// Increment the violation level.
|
||||
data.criticalVL += delta;
|
||||
|
@ -31,7 +31,7 @@ public class FastHeal extends Check {
|
||||
}
|
||||
else{
|
||||
// Violation.
|
||||
final double correctedDiff = ((double) time - data.fastHealRefTime) * TickTask.getLag(cc.fastHealInterval);
|
||||
final double correctedDiff = ((double) time - data.fastHealRefTime) * TickTask.getLag(cc.fastHealInterval, true);
|
||||
// TODO: Consider using a simple buffer as well (to get closer to the correct interval).
|
||||
// TODO: Check if we added a buffer.
|
||||
if (correctedDiff < cc.fastHealInterval){
|
||||
|
@ -140,7 +140,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
||||
tickAge = tick - data.lastAttackTick;
|
||||
// TODO: Maybe use 3d distance if dy(normalized) is too big.
|
||||
targetMove = TrigUtil.distance(data.lastAttackedX, data.lastAttackedZ, damagedLoc.getX(), damagedLoc.getZ());
|
||||
msAge = (long) (50f * TickTask.getLag(50L * tickAge) * (float) tickAge);
|
||||
msAge = (long) (50f * TickTask.getLag(50L * tickAge, true) * (float) tickAge);
|
||||
normalizedMove = msAge == 0 ? targetMove : targetMove * Math.min(20.0, 1000.0 / (double) msAge);
|
||||
}
|
||||
// TODO: calculate factor for dists: ticks * 50 * lag
|
||||
|
@ -85,7 +85,7 @@ public class GodMode extends Check {
|
||||
legit = true;
|
||||
}
|
||||
|
||||
// Bukkit.getServer().broadcastMessage("God " + player.getName() + " delta=" + delta + " dt=" + dTick + " dndt=" + dNDT + " acc=" + data.godModeAcc + " d=" + damage + " ndt=" + noDamageTicks + " h=" + health + " slag=" + TickTask.getLag(dTick));
|
||||
// Bukkit.getServer().broadcastMessage("God " + player.getName() + " delta=" + delta + " dt=" + dTick + " dndt=" + dNDT + " acc=" + data.godModeAcc + " d=" + damage + " ndt=" + noDamageTicks + " h=" + health + " slag=" + TickTask.getLag(dTick, true));
|
||||
|
||||
// TODO: might check last damage taken as well (really taken with health change)
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class Knockback extends Check {
|
||||
|
||||
// How long ago has the player started sprinting?
|
||||
final long usedTime = (time - data.knockbackSprintTime);
|
||||
final long effectiveTime = (long) ((float) usedTime * (cc.lag ? TickTask.getLag(usedTime): 1f));
|
||||
final long effectiveTime = (long) ((float) usedTime * (cc.lag ? TickTask.getLag(usedTime, true): 1f));
|
||||
// Pretty rough: Completely skip on lag.
|
||||
if (data.knockbackSprintTime > 0L && effectiveTime < cc.knockbackInterval) {
|
||||
final double difference = cc.knockbackInterval - time + data.knockbackSprintTime;
|
||||
|
@ -88,7 +88,7 @@ public class Reach extends Check {
|
||||
|
||||
if (violation > 0) {
|
||||
// They failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
|
||||
if (TickTask.getLag(1000) < 1.5f){
|
||||
if (TickTask.getLag(1000, true) < 1.5f){
|
||||
// TODO: 1.5 is a fantasy value.
|
||||
data.reachVL += violation;
|
||||
}
|
||||
@ -222,7 +222,7 @@ public class Reach extends Check {
|
||||
boolean cancel = false;
|
||||
if (violation > 0) {
|
||||
// They failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
|
||||
if (TickTask.getLag(1000) < 1.5f){
|
||||
if (TickTask.getLag(1000, true) < 1.5f){
|
||||
// TODO: 1.5 is a fantasy value.
|
||||
data.reachVL += violation;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class FastClick extends Check {
|
||||
// final double difference = 45L - time + data.fastClickLastTime;
|
||||
// final InventoryConfig cc = InventoryConfig.getConfig(player);
|
||||
// final ViolationData vd = new ViolationData(this, player, data.fastClickVL + difference, difference, cc.fastClickActions);
|
||||
// if (TickTask.getLag(150) > 1.7f){
|
||||
// if (TickTask.getLag(150, true) > 1.7f){
|
||||
// // Don't increase vl here.
|
||||
// cancel = vd.hasCancel();
|
||||
// }
|
||||
@ -110,14 +110,14 @@ public class FastClick extends Check {
|
||||
float shortTerm = data.fastClickFreq.bucketScore(0);
|
||||
if (shortTerm > cc.fastClickShortTermLimit){
|
||||
// Check for lag.
|
||||
shortTerm /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration());
|
||||
shortTerm /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration(), true);
|
||||
}
|
||||
shortTerm -= cc.fastClickShortTermLimit;
|
||||
|
||||
float normal = data.fastClickFreq.score(1f);
|
||||
if (normal > cc.fastClickNormalLimit){
|
||||
// Check for lag.
|
||||
normal /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration() * data.fastClickFreq.numberOfBuckets());
|
||||
normal /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration() * data.fastClickFreq.numberOfBuckets(), true);
|
||||
}
|
||||
normal -= cc.fastClickNormalLimit;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class LagCommand extends BaseCommand {
|
||||
long second = 1200L;
|
||||
builder.append("#### TPS lag ####\nPerc.[time]:");
|
||||
for (long ms : new long[]{second, medium, max}){
|
||||
double lag = TickTask.getLag(ms);
|
||||
double lag = TickTask.getLag(ms, true);
|
||||
int p = Math.max(0, (int) ((lag - 1.0) * 100.0));
|
||||
builder.append(" " + p + "%[" + StringUtil.fdec1.format((double) ms / 1200.0) + "s]" );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user