New check "dupebydeath" + big changes to "speedhack" check

This commit is contained in:
Evenprime 2011-02-28 16:57:15 +01:00
parent eae6bdc967
commit ea414167e0
7 changed files with 116 additions and 34 deletions

View File

@ -3,5 +3,5 @@ name: NoCheatPlugin
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin
version: 0.5.9
version: 0.5.9a

View File

@ -0,0 +1,35 @@
package cc.co.evenprime.bukkit.nocheat;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class DupePrevention {
/**
* Explicitly remove all items that are going to be dropped from the players inventory
* @param event
*/
public static void playerDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof Player) {
Player p = (Player)event.getEntity();
PlayerInventory playerInventory = p.getInventory();
List<ItemStack> drops = event.getDrops();
for(ItemStack drop : drops) {
for(int i = 0; i < playerInventory.getSize(); i++) {
if(playerInventory.getItem(i).equals(drop)) {
p.getInventory().clear(i);
i = playerInventory.getSize();
}
}
}
}
}
}

View File

@ -27,12 +27,12 @@ public class NoCheatConfiguration {
public static boolean speedhackCheckActive = true;
public static boolean movingCheckActive = true;
public static boolean airbuildCheckActive = false;
public static boolean dupebydeathCheckActive = false;
// Limits for the speedhack check
public static int speedhackInterval = 2000;
public static int speedhackLow = 60;
public static int speedhackMed = 90;
public static int speedhackHigh = 120;
public static int speedhackLow = 30;
public static int speedhackMed = 45;
public static int speedhackHigh = 60;
public static int movingFreeMoves = 10;
@ -91,11 +91,11 @@ public class NoCheatConfiguration {
speedhackCheckActive = c.getBoolean("active.speedhack", true);
movingCheckActive = c.getBoolean("active.moving", true);
airbuildCheckActive = c.getBoolean("active.airbuild", false);
dupebydeathCheckActive = c.getBoolean("active.dupebydeath", false);
speedhackInterval = c.getInt("speedhack.interval", 2000);
speedhackLow = c.getInt("speedhack.limits.low", 60);
speedhackMed = c.getInt("speedhack.limits.med", 90);
speedhackHigh = c.getInt("speedhack.limits.high", 120);
speedhackLow = c.getInt("speedhack.limits.low", 30);
speedhackMed = c.getInt("speedhack.limits.med", 45);
speedhackHigh = c.getInt("speedhack.limits.high", 60);
movingLogOnly = c.getBoolean("moving.logonly", false);
movingFreeMoves = c.getInt("moving.freemoves", 10);
@ -141,13 +141,13 @@ public class NoCheatConfiguration {
w.write(" speedhack: true"); w.newLine();
w.write(" moving: true"); w.newLine();
w.write(" airbuild: false"); w.newLine();
w.write(" dupebydeath: false"); w.newLine();
w.write("# Speedhack: interval in milliseconds, limits are events in that interval") ;w.newLine();
w.write("speedhack:"); w.newLine();
w.write(" interval: 2000"); w.newLine();
w.write(" limits:"); w.newLine();
w.write(" low: 60"); w.newLine();
w.write(" med: 90"); w.newLine();
w.write(" high: 120"); w.newLine();
w.write(" low: 30"); w.newLine();
w.write(" med: 45"); w.newLine();
w.write(" high: 60"); w.newLine();
w.write("moving:"); w.newLine();
w.write(" logonly: false"); w.newLine();
w.write(" freemoves: 10"); w.newLine();

View File

@ -0,0 +1,20 @@
package cc.co.evenprime.bukkit.nocheat;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class NoCheatEntityListener extends EntityListener {
@Override
public void onEntityDeath(EntityDeathEvent event) {
if(NoCheatConfiguration.dupebydeathCheckActive) {
DupePrevention.playerDeath(event);
}
}
}

View File

@ -6,12 +6,10 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
@ -33,6 +31,7 @@ public class NoCheatPlugin extends JavaPlugin {
private final NoCheatPluginPlayerListener playerListener;
private final NoCheatPluginVehicleListener vehicleListener;
private final NoCheatPluginBlockListener blockListener;
private final NoCheatEntityListener entityListener;
// My main logger
private static Logger log;
@ -62,6 +61,7 @@ public class NoCheatPlugin extends JavaPlugin {
playerListener = new NoCheatPluginPlayerListener();
vehicleListener = new NoCheatPluginVehicleListener(playerListener);
blockListener = new NoCheatPluginBlockListener();
entityListener = new NoCheatEntityListener();
log = NoCheatConfiguration.logger;
@ -107,6 +107,7 @@ public class NoCheatPlugin extends JavaPlugin {
pm.registerEvent(Event.Type.VEHICLE_EXIT, vehicleListener, Priority.Monitor, this); // used for moving check
pm.registerEvent(Event.Type.VEHICLE_DAMAGE, vehicleListener, Priority.Monitor, this); // used for moving check
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Low, this); // used for airbuild check
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Highest, this); // used for dupebydeath check
PluginDescriptionFile pdfFile = this.getDescription();
@ -118,7 +119,8 @@ public class NoCheatPlugin extends JavaPlugin {
String checks = (NoCheatConfiguration.movingCheckActive ? "moving ": "") +
(NoCheatConfiguration.speedhackCheckActive ? "speedhack " : "") +
(NoCheatConfiguration.airbuildCheckActive ? "airbuild " : "");
(NoCheatConfiguration.airbuildCheckActive ? "airbuild " : "") +
(NoCheatConfiguration.dupebydeathCheckActive ? "dupebydeath " : "");
Logger.getLogger("Minecraft").info( "[NoCheatPlugin] version [" + pdfFile.getVersion() + "] is enabled with the following checks: "+checks);
}

View File

@ -13,15 +13,18 @@ public class NoCheatPluginData {
/**
* Don't rely on any of these yet, they are likely going to change their name/functionality
*/
int movingJumpPhase = 0; // current jumpingPhase
long lastSpeedHackCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
int eventsSinceLastSpeedHackCheck = 0; // used to identify speedhacks
int movingIgnoreNextXEvents = 0;
int movingJumpPhase = 0; // current jumpingPhase
int movingMinorViolationsInARow = 0;
int movingNormalViolationsInARow = 0;
int movingHeavyViolationsInARow = 0;
Location movingSetBackPoint = null;
long speedhackLastCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
int speedhackEventsSinceLastCheck = 0; // used to identify speedhacks
int speedhackViolationsInARow = 0;
NoCheatPluginData() { }
}

View File

@ -10,6 +10,15 @@ import org.bukkit.event.player.PlayerMoveEvent;
*/
public class SpeedhackCheck {
// Violation levels
private static final int HEAVY = 3;
private static final int NORMAL = 2;
private static final int MINOR = 1;
private static final int NONE = 0;
private static final long interval = 1000;
private static final int violationsLimit = 3;
public static void check(NoCheatPluginData data, PlayerMoveEvent event) {
// Should we check at all?
@ -22,27 +31,40 @@ public class SpeedhackCheck {
// Get the time of the server
long time = System.currentTimeMillis();
int vl = NONE;
// Is it time for a speedhack check now?
if(time > NoCheatConfiguration.speedhackInterval + data.lastSpeedHackCheck ) {
if(time > interval + data.speedhackLastCheck ) {
// Yes
// TODO: Needs some better handling for server lag
int limitLow = (int)((NoCheatConfiguration.speedhackLow * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval);
int limitMed = (int)((NoCheatConfiguration.speedhackMed * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval);
int limitHigh = (int)((NoCheatConfiguration.speedhackHigh * (time - data.lastSpeedHackCheck)) / NoCheatConfiguration.speedhackInterval);
int limitLow = (int)((NoCheatConfiguration.speedhackLow * (time - data.speedhackLastCheck)) / interval);
int limitMed = (int)((NoCheatConfiguration.speedhackMed * (time - data.speedhackLastCheck)) / interval);
int limitHigh = (int)((NoCheatConfiguration.speedhackHigh * (time - data.speedhackLastCheck)) / interval);
if(data.speedhackEventsSinceLastCheck > limitHigh) vl = HEAVY;
else if(data.speedhackEventsSinceLastCheck > limitMed) vl = NORMAL;
else if(data.speedhackEventsSinceLastCheck > limitLow) vl = MINOR;
if(data.eventsSinceLastSpeedHackCheck > limitHigh)
NoCheatPlugin.logHeavy("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?");
else if(data.eventsSinceLastSpeedHackCheck > limitMed)
NoCheatPlugin.logNormal("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?");
else if(data.eventsSinceLastSpeedHackCheck > limitLow)
NoCheatPlugin.logMinor("NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.eventsSinceLastSpeedHackCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?");
// Reset values for next check
data.eventsSinceLastSpeedHackCheck = 0;
data.lastSpeedHackCheck = time;
data.speedhackEventsSinceLastCheck = 0;
data.speedhackLastCheck = time;
if(vl > NONE) data.speedhackViolationsInARow++;
else data.speedhackViolationsInARow = 0;
if(data.speedhackViolationsInARow >= violationsLimit) {
String message = "NoCheatPlugin: "+event.getPlayer().getName()+" sent "+ data.speedhackEventsSinceLastCheck + " move events, but only "+limitLow+ " were allowed. Speedhack?";
switch(vl) {
case HEAVY: NoCheatPlugin.logHeavy(message); break;
case NORMAL: NoCheatPlugin.logNormal(message); break;
case MINOR: NoCheatPlugin.logMinor(message); break;
}
}
}
data.eventsSinceLastSpeedHackCheck++;
data.speedhackEventsSinceLastCheck++;
}
}