Remove Spambot check, targetting 1.1 R5 now

This commit is contained in:
Evenprime 2012-02-20 21:20:58 +01:00
parent e892d88e72
commit d65ca86074
13 changed files with 4 additions and 290 deletions

View File

@ -69,9 +69,6 @@ permissions:
children:
nocheat.checks.chat.spam:
description: Allow a player to send an infinite amount of chat messages
children:
nocheat.checks.chat.spam.bot:
description: Exempt players from the proxy server check and always declare them as "not spambot"
nocheat.checks.chat.color:
description: Allow a player to send colored chat messages
nocheat.checks.fight:

View File

@ -13,7 +13,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.1-R4-SNAPSHOT</version>
<version>1.1-R5-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -1,18 +0,0 @@
package cc.co.evenprime.bukkit.dnsbl;
import java.util.List;
import org.bukkit.entity.Player;
/**
* The class that handles the results of the proxy checks
* has to implement this.
*/
public interface ProxyServerCheckResultHandler {
/**
* If the list of failures is empty, the player and his ip
* passed all checks. If it is nonempty, it will contain
* the servers that have blacklisted the ip
*/
public void finishedTestForProxies(Player player, String ip, List<String> failures);
}

View File

@ -1,118 +0,0 @@
package cc.co.evenprime.bukkit.dnsbl;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
* Test if the connecting IP address of players belongs to a
* known spam network. Most public proxy servers are used for
* E-Mail spam, therefore almost all public proxy servers that
* are used for Minecraft will be blacklisted for spam
*/
public class ProxyServerChecker {
private static final String[] attributes = {"A"};
private final Plugin plugin;
private final DirContext context;
private final String[] blocklistProviders;
/**
* We need a plugin as the owner for the created Bukkit tasks
* and a string array of adresses of dnsbl providers. See this
* page: http://www.dnsbl.info/dnsbl-list.php for potential
* lists.
*
*/
public ProxyServerChecker(Plugin plugin, String[] dnsblProviders) throws NamingException {
this.plugin = plugin;
this.blocklistProviders = dnsblProviders.clone();
Hashtable<Object, String> environment = new Hashtable<Object, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
context = new InitialDirContext(environment);
}
/**
* Test a player and his IP in a seperate bukkit thread for proxy usage.
* When finished, the handler will be informed in a Bukkit threadsafe way.
*/
public void check(final Player player, final String ip, final ProxyServerCheckResultHandler handler) {
Runnable r = new CheckRunnable(player, ip, handler);
// We have time, therefore let the bukkit scheduler do this
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, r);
}
/**
* Runnable that does the actual dns checking
*
*/
public class CheckRunnable implements Runnable {
private final Player player;
private final ProxyServerCheckResultHandler handler;
private final String ip;
private final List<String> failures = new LinkedList<String>();
public CheckRunnable(Player player, String ip, ProxyServerCheckResultHandler handler) {
this.ip = ip;
this.player = player;
this.handler = handler;
}
@Override
public void run() {
// Invert the IP
String[] parts = ip.split("\\.");
StringBuilder buffer = new StringBuilder();
for(int i = parts.length - 1; i >= 0; i--) {
buffer.append(parts[i]).append('.');
}
final String invertedIp = buffer.toString();
for(String provider : blocklistProviders) {
String lookupHost = invertedIp + provider;
try {
context.getAttributes(lookupHost, attributes);
// If we got a response, the address is listed
// so the player failed that one.
failures.add(provider);
} catch(NameNotFoundException e) {
// great, the player is not on the blacklist
// e.printStackTrace();
} catch(NamingException e) {
// not so great, but I don't care here
// e.printStackTrace();
}
}
// We are done, let's schedule a sync task to handle
// the results
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
handler.finishedTestForProxies(player, ip, failures);
}
});
}
}
}

View File

@ -14,7 +14,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import cc.co.evenprime.bukkit.dnsbl.ProxyServerChecker;
import cc.co.evenprime.bukkit.nocheat.checks.WorkaroundsListener;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceCheckListener;
@ -204,8 +203,4 @@ public class NoCheat extends JavaPlugin implements Listener {
public void setFileLogger(Logger logger) {
this.fileLogger = logger;
}
public ProxyServerChecker getProxyServerChecker() {
return this.conf.getProxyServerChecker();
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import cc.co.evenprime.bukkit.nocheat.EventManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -17,7 +16,6 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
public class ChatCheckListener implements Listener, EventManager {
private final SpamCheck spamCheck;
private final SpambotTest spambotCheck;
private final ColorCheck colorCheck;
private final NoCheat plugin;
@ -28,7 +26,6 @@ public class ChatCheckListener implements Listener, EventManager {
spamCheck = new SpamCheck(plugin);
colorCheck = new ColorCheck(plugin);
spambotCheck = new SpambotTest(plugin);
}
@EventHandler(priority = EventPriority.LOWEST)
@ -65,21 +62,6 @@ public class ChatCheckListener implements Listener, EventManager {
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void connect(PlayerJoinEvent event) {
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
ChatConfig config = ChatCheck.getConfig(player.getConfigurationStore());
final ChatData data = ChatCheck.getData(player.getDataStore());
if(!config.spambotCheck || player.hasPermission(Permissions.CHAT_SPAM_BOT)) {
data.botcheckpassed = true;
} else {
data.botcheckpassed = false;
spambotCheck.startTestForProxies(event.getPlayer(), event.getPlayer().getAddress().getAddress().getHostAddress());
}
}
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
LinkedList<String> s = new LinkedList<String>();
@ -88,8 +70,6 @@ public class ChatCheckListener implements Listener, EventManager {
s.add("chat.spam");
if(c.colorCheck)
s.add("chat.color");
if(c.spamCheck && c.spambotCheck)
s.add("chat.spambot");
return s;
}
}

View File

@ -17,11 +17,6 @@ public class ChatConfig implements ConfigItem {
public final boolean colorCheck;
public final ActionList colorActions;
public final int spamCommandLimit;
public final boolean spambotCheck;
public final ActionList spambotActions;
public final int spambotCommandLimit;
public final int spambotMessageLimit;
public final int spambotTimeframe;
public ChatConfig(NoCheatConfiguration data) {
@ -33,11 +28,6 @@ public class ChatConfig implements ConfigItem {
spamActions = data.getActionList(ConfPaths.CHAT_SPAM_ACTIONS);
colorCheck = data.getBoolean(ConfPaths.CHAT_COLOR_CHECK);
colorActions = data.getActionList(ConfPaths.CHAT_COLOR_ACTIONS);
spambotCheck = data.getBoolean(ConfPaths.CHAT_SPAMBOT_CHECK);
spambotActions = data.getActionList(ConfPaths.CHAT_SPAMBOT_ACTIONS);
spambotCommandLimit = data.getInt(ConfPaths.CHAT_SPAMBOT_COMMANDLIMIT);
spambotMessageLimit = data.getInt(ConfPaths.CHAT_SPAMBOT_MESSAGELIMIT);
spambotTimeframe = data.getInt(ConfPaths.CHAT_SPAMBOT_TIMEFRAME);
}
private String[] splitWhitelist(String string) {

View File

@ -4,7 +4,6 @@ import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
public class SpamCheck extends ChatCheck {
@ -24,20 +23,10 @@ public class SpamCheck extends ChatCheck {
}
}
int commandLimit = 0;
int messageLimit = 0;
int timeframe = 0;
int commandLimit = cc.spamCommandLimit;
int messageLimit = cc.spamMessageLimit;
int timeframe = cc.spamTimeframe;
// Set limits depending on "proxy server check" results
if(data.botcheckpassed || player.hasPermission(Permissions.CHAT_SPAM_BOT)) {
commandLimit = cc.spamCommandLimit;
messageLimit = cc.spamMessageLimit;
timeframe = cc.spamTimeframe;
} else {
commandLimit = cc.spambotCommandLimit;
messageLimit = cc.spambotMessageLimit;
timeframe = cc.spambotTimeframe;
}
final long time = System.currentTimeMillis() / 1000;
if(data.spamLastTime + timeframe <= time) {

View File

@ -1,67 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.chat;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.dnsbl.ProxyServerCheckResultHandler;
import cc.co.evenprime.bukkit.dnsbl.ProxyServerChecker;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
/**
* The actual spam check is done at "SpamCheck". This will only
* do the initial test for proxy usage.
*
*/
public class SpambotTest extends ChatCheck implements ProxyServerCheckResultHandler {
public SpambotTest(NoCheat plugin) {
super(plugin, "chat.spambot");
}
public void startTestForProxies(Player player, String ip) {
ProxyServerChecker checker = plugin.getProxyServerChecker();
checker.check(player, ip, this);
}
/**
* This gets called after the checker finished his work. The checker
* makes sure that this is called in a save, synchronized way
*/
public void finishedTestForProxies(Player player, String ip, List<String> failures) {
NoCheatPlayer ncplayer = plugin.getPlayer(player);
ChatData data = ChatCheck.getData(ncplayer.getDataStore());
ChatConfig config = ChatCheck.getConfig(ncplayer.getConfigurationStore());
boolean cancelled = false;
if(failures.size() > 0 && config.spambotCheck && !player.hasPermission(Permissions.CHAT_SPAM_BOT)) {
data.spamBotFailed = new LinkedList<String>(failures);
// cancelled means the player stays in "spambot" status
cancelled = executeActions(ncplayer, config.spambotActions.getActions(failures.size()));
}
if(!cancelled) {
data.botcheckpassed = true;
}
}
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).spamBotFailed.size());
else if(wildcard == ParameterName.SERVERS) {
StringBuilder sb = new StringBuilder();
List<String> strings = getData(player.getDataStore()).spamBotFailed;
for(String s : strings) {
sb.append(s).append(" ");
}
return sb.toString().trim();
} else
return super.getParameter(wildcard, player);
}
}

View File

@ -106,14 +106,6 @@ public abstract class ConfPaths {
public final static String CHAT_SPAM_COMMANDLIMIT = CHAT_SPAM + "commandlimit";
public final static String CHAT_SPAM_ACTIONS = CHAT_SPAM + "actions";
private final static String CHAT_SPAMBOT = CHAT_SPAM + "bot.";
public static final String CHAT_SPAMBOT_CHECK = CHAT_SPAMBOT + "active";
public static final String CHAT_SPAMBOT_TIMEFRAME = CHAT_SPAMBOT + "timeframe";
public static final String CHAT_SPAMBOT_COMMANDLIMIT = CHAT_SPAMBOT + "commandlimit";
public static final String CHAT_SPAMBOT_MESSAGELIMIT = CHAT_SPAMBOT + "messagelimit";
public static final String CHAT_SPAMBOT_SERVERS = CHAT_SPAMBOT + "servers";
public static final String CHAT_SPAMBOT_ACTIONS = CHAT_SPAMBOT + "actions";
private final static String FIGHT = CHECKS + "fight.";
private final static String FIGHT_DIRECTION = FIGHT + "direction.";

View File

@ -13,8 +13,6 @@ import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.naming.NamingException;
import cc.co.evenprime.bukkit.dnsbl.ProxyServerChecker;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
/**
@ -30,8 +28,6 @@ public class ConfigurationManager {
private FileHandler fileHandler;
private final NoCheat plugin;
private ProxyServerChecker proxyServerChecker;
private static class LogFileFormatter extends Formatter {
private final SimpleDateFormat date;
@ -103,15 +99,6 @@ public class ConfigurationManager {
root.regenerateActionLists();
// Setup spambot checker
ProxyServerChecker checker = null;
try {
checker = new ProxyServerChecker(plugin, root.getString(ConfPaths.CHAT_SPAMBOT_SERVERS).split("\\s+"));
} catch(NamingException e1) {
System.out.println("Nocheat couldn't setup the 'ProxyServerChecker': " + e1.getMessage());
}
proxyServerChecker = checker;
// Create a corresponding Configuration Cache
// put the global config on the config map
worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root));
@ -239,8 +226,4 @@ public class ConfigurationManager {
return cache;
}
}
public ProxyServerChecker getProxyServerChecker() {
return proxyServerChecker;
}
}

View File

@ -89,13 +89,6 @@ public class DefaultConfiguration extends NoCheatConfiguration {
set(ConfPaths.CHAT_SPAM_COMMANDLIMIT, 12);
set(ConfPaths.CHAT_SPAM_ACTIONS, "log:spam:0:3:if cancel vl>30 log:spam:0:3:cif cancel cmd:kick");
set(ConfPaths.CHAT_SPAMBOT_CHECK, true);
set(ConfPaths.CHAT_SPAMBOT_TIMEFRAME, 60);
set(ConfPaths.CHAT_SPAMBOT_MESSAGELIMIT, 3);
set(ConfPaths.CHAT_SPAMBOT_COMMANDLIMIT, 12);
set(ConfPaths.CHAT_SPAMBOT_SERVERS, "bl.spamcop.net cbl.abuseat.org socks.dnsbl.sorbs.net tor.efnet.org xbl.spamhaus.org");
set(ConfPaths.CHAT_SPAMBOT_ACTIONS, "log:sbot:0:0:cif vl>2 log:sbot:0:0:cif cancel vl>4 log:sbot:0:0:cif cancel cmd:kick");
/*** FIGHT ***/
set(ConfPaths.FIGHT_DIRECTION_CHECK, true);
@ -130,7 +123,6 @@ public class DefaultConfiguration extends NoCheatConfiguration {
set(ConfPaths.STRINGS + ".bpdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]");
set(ConfPaths.STRINGS + ".color", "[player] failed [check]: Sent colored chat message '[text]'. VL [violations]");
set(ConfPaths.STRINGS + ".spam", "[player] failed [check]: Last sent message '[text]'. VL [violations]");
set(ConfPaths.STRINGS + ".sbot", "[player] failed [check]: Blacklisted at [violations] servers: [servers]");
set(ConfPaths.STRINGS + ".fdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]");
set(ConfPaths.STRINGS + ".freach", "[player] failed [check]: tried to attack entity out of reach. VL [violations]");
set(ConfPaths.STRINGS + ".fspeed", "[player] failed [check]: tried to attack more than [limit] times per second. VL [violations]");

View File

@ -29,7 +29,6 @@ public class Permissions {
public final static String CHAT = CHECKS + ".chat";
public final static String CHAT_SPAM = CHAT + ".spam";
public static final String CHAT_SPAM_BOT = CHAT_SPAM + ".bot";
public static final String CHAT_COLOR = CHAT + ".color";
public static final String FIGHT = CHECKS + ".fight";