Less sensitive godmode check, bugfixes for log messages, better check

names
This commit is contained in:
Evenprime 2011-11-14 00:00:06 +01:00
parent cfd8661f3f
commit 3c44445d9b
18 changed files with 105 additions and 95 deletions

View File

@ -21,5 +21,5 @@ public interface NoCheatPlayer {
public ConfigurationCache getConfiguration(); public ConfigurationCache getConfiguration();
public int getSpeedAmplifier(); public float getSpeedAmplifier();
} }

View File

@ -5,7 +5,6 @@ import net.minecraft.server.Block;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;

View File

@ -12,7 +12,7 @@ public abstract class TimedCheck extends Check {
super(plugin, name, permission); super(plugin, name, permission);
} }
public abstract boolean check(final NoCheatPlayer player, TimedData data, CCTimed cc); public abstract void check(final NoCheatPlayer player, TimedData data, CCTimed cc);
public abstract boolean isEnabled(CCTimed cc); public abstract boolean isEnabled(CCTimed cc);

View File

@ -78,7 +78,7 @@ public class DirectionCheck extends BlockBreakCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.directionVL); return String.format(Locale.US, "%d", (int)player.getData().blockbreak.directionVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);

View File

@ -45,7 +45,7 @@ public class NoswingCheck extends BlockBreakCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.noswingVL); return String.format(Locale.US, "%d", (int)player.getData().blockbreak.noswingVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);

View File

@ -57,7 +57,7 @@ public class ReachCheck extends BlockBreakCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.reachVL); return String.format(Locale.US, "%d", (int)player.getData().blockbreak.reachVL);
case REACHDISTANCE: case REACHDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance); return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance);

View File

@ -91,7 +91,7 @@ public class DirectionCheck extends BlockPlaceCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.directionVL); return String.format(Locale.US, "%d", (int)player.getData().blockplace.directionVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);

View File

@ -56,7 +56,7 @@ public class ReachCheck extends BlockPlaceCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.reachVL); return String.format(Locale.US, "%d", (int)player.getData().blockplace.reachVL);
case REACHDISTANCE: case REACHDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance); return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);

View File

@ -72,7 +72,7 @@ public class DirectionCheck extends FightCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.directionVL); return String.format(Locale.US, "%d", (int)player.getData().fight.directionVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -45,7 +45,7 @@ public class NoswingCheck extends FightCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.noswingVL); return String.format(Locale.US, "%d", (int)player.getData().fight.noswingVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -20,7 +20,7 @@ public class SelfhitCheck extends FightCheck {
boolean cancel = false; boolean cancel = false;
if(player.getPlayer().equals(data.damagee)) { if(player.getPlayer().equals(data.damagee.getBukkitEntity())) {
// Player failed the check obviously // Player failed the check obviously
data.selfhitVL += 1; data.selfhitVL += 1;
@ -42,7 +42,7 @@ public class SelfhitCheck extends FightCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.selfhitVL); return String.format(Locale.US, "%d", (int)player.getData().fight.selfhitVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -2,11 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale; import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -53,14 +49,10 @@ public class FlyingCheck extends MovingCheck {
// In case of creative gamemode, give at least 0.60 speed limit // In case of creative gamemode, give at least 0.60 speed limit
// horizontal // horizontal
double speedLimitHorizontal = player.getPlayer().getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal; double speedLimitHorizontal = player.getPlayer().getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
EntityPlayer p = ((CraftPlayer) player).getHandle(); speedLimitHorizontal *= player.getSpeedAmplifier();
if(p.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
// Taken directly from Minecraft code, should work
speedLimitHorizontal *= 1.0F + 0.2F * (float) (p.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
}
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal); result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = player.getPlayer().isSprinting(); boolean sprinting = player.getPlayer().isSprinting();
@ -115,7 +107,7 @@ public class FlyingCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyVL); return String.format(Locale.US, "%d", (int)player.getData().moving.runflyVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -109,7 +109,7 @@ public class MorePacketsCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.morePacketsVL); return String.format(Locale.US, "%d", (int)player.getData().moving.morePacketsVL);
case PACKETS: case PACKETS:
return String.valueOf(player.getData().moving.packets); return String.valueOf(player.getData().moving.packets);
default: default:

View File

@ -106,7 +106,7 @@ public class NoFallCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.nofallVL); return String.format(Locale.US, "%d", (int)player.getData().moving.nofallVL);
case FALLDISTANCE: case FALLDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance); return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
default: default:

View File

@ -2,11 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale; import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard; import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
@ -76,7 +71,7 @@ public class RunningCheck extends MovingCheck {
data.jumpPhase++; data.jumpPhase++;
// Slowly reduce the level with each event // Slowly reduce the level with each event
data.runflyVL *= 0.97; data.runflyVL *= 0.95;
if(result > 0) { if(result > 0) {
@ -125,7 +120,7 @@ public class RunningCheck extends MovingCheck {
* Calculate how much the player failed this check * Calculate how much the player failed this check
* *
*/ */
private double checkHorizontal(final NoCheatPlayer player, final MovingData moving, final boolean isSwimming, final double totalDistance, final CCMoving ccmoving) { private double checkHorizontal(final NoCheatPlayer player, final MovingData data, final boolean isSwimming, final double totalDistance, final CCMoving cc) {
// How much further did the player move than expected?? // How much further did the player move than expected??
double distanceAboveLimit = 0.0D; double distanceAboveLimit = 0.0D;
@ -134,58 +129,56 @@ public class RunningCheck extends MovingCheck {
double limit = 0.0D; double limit = 0.0D;
final EntityPlayer p = ((CraftPlayer) player.getPlayer()).getHandle(); String suffix = null;
if(ccmoving.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) { if(cc.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) {
limit = ccmoving.sneakingSpeedLimit; limit = cc.sneakingSpeedLimit;
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) { suffix = "sneaking";
limit = ccmoving.swimmingSpeedLimit; } else if(cc.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) {
limit = cc.swimmingSpeedLimit;
suffix = "swimming";
} else if(!sprinting) { } else if(!sprinting) {
limit = ccmoving.walkingSpeedLimit; limit = cc.walkingSpeedLimit;
suffix = "walking";
} else { } else {
limit = ccmoving.sprintingSpeedLimit; limit = cc.sprintingSpeedLimit;
suffix = "sprinting";
} }
if(p.hasEffect(MobEffectList.FASTER_MOVEMENT)) { // Taken directly from Minecraft code, should work
// Taken directly from Minecraft code, should work limit *= player.getSpeedAmplifier();
limit *= 1.0F + 0.2F * (float) (p.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
}
// Ignore slowdowns for now distanceAboveLimit = totalDistance - limit - data.horizFreedom;
/*
* if(p.hasEffect(MobEffectList.SLOWER_MOVEMENT)) {
* limit *= 1.0F - 0.15F * (float)
* (p.getEffect(MobEffectList.SLOWER_MOVEMENT).getAmplifier() + 1);
* }
*/
distanceAboveLimit = totalDistance - limit - moving.horizFreedom; data.bunnyhopdelay--;
moving.bunnyhopdelay--;
// Did he go too far? // Did he go too far?
if(distanceAboveLimit > 0 && sprinting) { if(distanceAboveLimit > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem // Try to treat it as a the "bunnyhop" problem
if(moving.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) { if(data.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) {
moving.bunnyhopdelay = 3; data.bunnyhopdelay = 3;
distanceAboveLimit = 0; distanceAboveLimit = 0;
} }
} }
if(distanceAboveLimit > 0) { if(distanceAboveLimit > 0) {
// Try to consume the "buffer" // Try to consume the "buffer"
distanceAboveLimit -= moving.horizontalBuffer; distanceAboveLimit -= data.horizontalBuffer;
moving.horizontalBuffer = 0; data.horizontalBuffer = 0;
// Put back the "overconsumed" buffer // Put back the "overconsumed" buffer
if(distanceAboveLimit < 0) { if(distanceAboveLimit < 0) {
moving.horizontalBuffer = -distanceAboveLimit; data.horizontalBuffer = -distanceAboveLimit;
} }
} }
// He was within limits, give the difference as buffer // He was within limits, give the difference as buffer
else { else {
moving.horizontalBuffer = Math.min(maxBonus, moving.horizontalBuffer - distanceAboveLimit); data.horizontalBuffer = Math.min(maxBonus, data.horizontalBuffer - distanceAboveLimit);
}
if(distanceAboveLimit > 0) {
data.checknamesuffix = suffix;
} }
return distanceAboveLimit; return distanceAboveLimit;
@ -195,18 +188,21 @@ public class RunningCheck extends MovingCheck {
* Calculate if and how much the player "failed" this check. * Calculate if and how much the player "failed" this check.
* *
*/ */
private double checkVertical(final MovingData moving, final boolean fromOnGround, final boolean toOnGround, final CCMoving ccmoving) { private double checkVertical(final MovingData data, final boolean fromOnGround, final boolean toOnGround, final CCMoving cc) {
// How much higher did the player move than expected?? // How much higher did the player move than expected??
double distanceAboveLimit = 0.0D; double distanceAboveLimit = 0.0D;
double limit = moving.vertFreedom + ccmoving.jumpheight; double limit = data.vertFreedom + cc.jumpheight;
if(moving.jumpPhase > jumpingLimit) { if(data.jumpPhase > jumpingLimit) {
limit -= (moving.jumpPhase - jumpingLimit) * 0.15D; limit -= (data.jumpPhase - jumpingLimit) * 0.15D;
} }
distanceAboveLimit = moving.to.y - moving.runflySetBackPoint.y - limit; distanceAboveLimit = data.to.y - data.runflySetBackPoint.y - limit;
if(distanceAboveLimit > 0) {
data.checknamesuffix = "vertical";
}
return distanceAboveLimit; return distanceAboveLimit;
} }
@ -220,8 +216,11 @@ public class RunningCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case CHECK:
// Workaround for something until I find a better way to do it
return getName() + "." + player.getData().moving.checknamesuffix;
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyVL); return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -17,11 +17,11 @@ public class GodmodeCheck extends TimedCheck {
} }
@Override @Override
public boolean check(NoCheatPlayer player, TimedData data, CCTimed cc) { public void check(NoCheatPlayer player, TimedData data, CCTimed cc) {
// server lag(ged), skip this, or player dead, therefore it's reasonable // server lag(ged), skip this, or player dead, therefore it's reasonable
// for him to not move :) // for him to not move :)
if(plugin.skipCheck() || player.getPlayer().isDead()) if(plugin.skipCheck() || player.getPlayer().isDead())
return false; return;
final int ticksLived = player.getTicksLived(); final int ticksLived = player.getTicksLived();
@ -31,57 +31,69 @@ public class GodmodeCheck extends TimedCheck {
data.ticksLived = ticksLived; data.ticksLived = ticksLived;
// And give up already // And give up already
return false; return;
} }
boolean cancel = false; boolean cancel = false;
// Compare ingame record of players ticks to our last observed value // How far behind is the player with his ticks
int difference = ticksLived - data.ticksLived; // expected time - real lived time
System.out.println("lived "+ticksLived + " data.ticksLived " + data.ticksLived);
int behind = Math.min(10, (data.ticksLived + cc.tickTime) - ticksLived);
// difference should be >= tickTime for perfect synchronization // difference should be >= tickTime for perfect synchronization
if(difference > cc.tickTime) { if(behind <= 1) {
// player was faster than expected, give him credit for the // player as fast as expected, give him credit for that
// difference
data.ticksBehind -= (difference - cc.tickTime);
// Reduce violation level over time
data.godmodeVL *= 0.9D;
} else if(difference >= cc.tickTime / 2) {
// close enough, let it pass
data.ticksBehind -= cc.tickTime / 2; data.ticksBehind -= cc.tickTime / 2;
// Reduce violation level over time // Reduce violation level over time
data.godmodeVL *= 0.9D; data.godmodeVL -= cc.tickTime / 2.0;
} else if(behind <= (cc.tickTime / 2)+1) {
// close enough, let it pass
data.ticksBehind -= cc.tickTime / 4;
// Reduce violation level over time
data.godmodeVL -= cc.tickTime / 4.0;
} else { } else {
// That's a bit suspicious, why is the player more than half the // That's a bit suspicious, why is the player more than half the
// ticktime behind? Keep that in mind // ticktime behind? Keep that in mind
data.ticksBehind += cc.tickTime - difference; data.ticksBehind += behind;
// Is he way too far behind, then correct that // Is he way too far behind, then correct that
if(data.ticksBehind > cc.godmodeTicksLimit) { if(data.ticksBehind > cc.godmodeTicksLimit) {
data.godmodeVL += cc.tickTime - difference; // Over the limit, start increasing VL for the player
data.godmodeVL += behind;
cancel = executeActions(player, cc.godmodeActions.getActions(data.godmodeVL)); cancel = executeActions(player, cc.godmodeActions.getActions(data.godmodeVL));
// Reduce the time the player is behind accordingly
data.ticksBehind -= cc.tickTime; if(cancel) {
// Catch up for at least some of the ticks
try {
player.increaseAge(cc.tickTime);
}
catch(Exception e) {
e.printStackTrace();
}
// Reduce the time the player is behind accordingly
data.ticksBehind -= cc.tickTime;
}
} }
} }
if(data.ticksBehind < 0) { if(data.ticksBehind < 0) {
data.ticksBehind = 0; data.ticksBehind = 0;
} }
if(cancel) { if(data.godmodeVL < 0) {
// Catch up for at least some of the ticks data.godmodeVL = 0;
player.increaseAge(cc.tickTime);
} }
System.out.println(data.ticksBehind);
// setup data for next time // setup data for next time
data.ticksLived = player.getTicksLived(); data.ticksLived = player.getTicksLived();
return cancel; return;
} }
@ -95,7 +107,7 @@ public class GodmodeCheck extends TimedCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().timed.godmodeVL); return String.format(Locale.US, "%d", (int)player.getData().timed.godmodeVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -43,6 +43,8 @@ public class MovingData extends Data {
public boolean fromOnOrInGround; public boolean fromOnOrInGround;
public boolean toOnOrInGround; public boolean toOnOrInGround;
public String checknamesuffix = "";
@Override @Override
public void clearCriticalData() { public void clearCriticalData() {
teleportTo.reset(); teleportTo.reset();

View File

@ -52,13 +52,19 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
EntityPlayer p = ((CraftPlayer) player).getHandle(); EntityPlayer p = ((CraftPlayer) player).getHandle();
for(int i = 0; i < ticks; i++) { for(int i = 0; i < ticks; i++) {
// TODO: This is highly fragile and breaks every update!! // TODO: This is highly fragile and breaks every update!!
p.b(true); // Catch up with the server, one tick at a time p.b(true); // Catch up with the server, one tick at a time
} }
} }
public int getSpeedAmplifier() { public float getSpeedAmplifier() {
return ((CraftPlayer)player).getHandle().getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); EntityPlayer ep = ((CraftPlayer)player).getHandle();
if(ep.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
// Taken directly from Minecraft code, should work
return 1.0F + 0.2F * ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1;
}
else {
return 1.0F;
}
} }
} }