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 int getSpeedAmplifier();
public float getSpeedAmplifier();
}

View File

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

View File

@ -12,7 +12,7 @@ public abstract class TimedCheck extends Check {
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);

View File

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

View File

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

View File

@ -57,7 +57,7 @@ public class ReachCheck extends BlockBreakCheck {
switch (wildcard) {
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:
return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance);

View File

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

View File

@ -56,7 +56,7 @@ public class ReachCheck extends BlockPlaceCheck {
switch (wildcard) {
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:
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);

View File

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

View File

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

View File

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

View File

@ -2,11 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
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
// horizontal
double speedLimitHorizontal = player.getPlayer().getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
EntityPlayer p = ((CraftPlayer) player).getHandle();
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);
}
speedLimitHorizontal *= player.getSpeedAmplifier();
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = player.getPlayer().isSprinting();
@ -115,7 +107,7 @@ public class FlyingCheck extends MovingCheck {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyVL);
return String.format(Locale.US, "%d", (int)player.getData().moving.runflyVL);
default:
return super.getParameter(wildcard, player);
}

View File

@ -109,7 +109,7 @@ public class MorePacketsCheck extends MovingCheck {
switch (wildcard) {
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:
return String.valueOf(player.getData().moving.packets);
default:

View File

@ -106,7 +106,7 @@ public class NoFallCheck extends MovingCheck {
switch (wildcard) {
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:
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
default:

View File

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

View File

@ -17,11 +17,11 @@ public class GodmodeCheck extends TimedCheck {
}
@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
// for him to not move :)
if(plugin.skipCheck() || player.getPlayer().isDead())
return false;
return;
final int ticksLived = player.getTicksLived();
@ -31,57 +31,69 @@ public class GodmodeCheck extends TimedCheck {
data.ticksLived = ticksLived;
// And give up already
return false;
return;
}
boolean cancel = false;
// Compare ingame record of players ticks to our last observed value
int difference = ticksLived - data.ticksLived;
// How far behind is the player with his ticks
// 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
if(difference > cc.tickTime) {
// player was faster than expected, give him credit for the
// 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
if(behind <= 1) {
// player as fast as expected, give him credit for that
data.ticksBehind -= cc.tickTime / 2;
// 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 {
// That's a bit suspicious, why is the player more than half the
// ticktime behind? Keep that in mind
data.ticksBehind += cc.tickTime - difference;
data.ticksBehind += behind;
// Is he way too far behind, then correct that
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));
// 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) {
data.ticksBehind = 0;
}
if(cancel) {
// Catch up for at least some of the ticks
player.increaseAge(cc.tickTime);
if(data.godmodeVL < 0) {
data.godmodeVL = 0;
}
System.out.println(data.ticksBehind);
// setup data for next time
data.ticksLived = player.getTicksLived();
return cancel;
return;
}
@ -95,7 +107,7 @@ public class GodmodeCheck extends TimedCheck {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().timed.godmodeVL);
return String.format(Locale.US, "%d", (int)player.getData().timed.godmodeVL);
default:
return super.getParameter(wildcard, player);
}

View File

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

View File

@ -52,13 +52,19 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
EntityPlayer p = ((CraftPlayer) player).getHandle();
for(int i = 0; i < ticks; i++) {
// TODO: This is highly fragile and breaks every update!!
p.b(true); // Catch up with the server, one tick at a time
}
}
public int getSpeedAmplifier() {
return ((CraftPlayer)player).getHandle().getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier();
public float getSpeedAmplifier() {
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;
}
}
}