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:
asofold 2014-08-01 19:25:37 +02:00
parent 78d51b3904
commit 5f82584072
12 changed files with 15 additions and 15 deletions

View File

@ -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;

View File

@ -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)){

View File

@ -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");

View File

@ -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;

View File

@ -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;

View File

@ -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){

View File

@ -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

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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]" );
}