Permalink
Browse files

Added country whitelist option, maybe it could be useful for continen…

…t only minecraft servers. Also added deregister utility to make sure all old player data is removed.
  • Loading branch information...
1 parent f6283c7 commit dbd0f27043337fd038d9ce74c21b353fc0cefbb8 @SuperSpyTX committed Apr 24, 2012
@@ -15,6 +15,7 @@
import somebody.is.madbro.listeners.BotListener;
import somebody.is.madbro.listeners.ChatListener;
import somebody.is.madbro.listeners.CountryListener;
+import somebody.is.madbro.listeners.KickListener;
import somebody.is.madbro.settings.Settings;
import somebody.is.madbro.settings.SettingsCore;
import somebody.is.madbro.toolbox.UtilityCore;
@@ -25,6 +26,7 @@
private BotListener botlistener = null;
private ChatListener chatlistener = null;
private CountryListener countrylistener = null;
+ private KickListener kicklistener = null;
// utilities
private UtilityCore utilitycore = null;
@@ -57,6 +59,7 @@ public void onEnable() {
botlistener = new BotListener(this);
chatlistener = new ChatListener(this);
countrylistener = new CountryListener(this);
+ kicklistener = new KickListener(this);
// cores
settings = new SettingsCore(this);
@@ -102,6 +105,7 @@ public int getValue() {
getServer().getPluginManager().registerEvents(botlistener, this);
getServer().getPluginManager().registerEvents(chatlistener, this);
getServer().getPluginManager().registerEvents(countrylistener, this);
+ getServer().getPluginManager().registerEvents(kicklistener, this);
// all finished.
PluginDescriptionFile pdfFile = getDescription();
@@ -44,11 +44,6 @@ public void onPlayerQuit(PlayerQuitEvent event) {
if (botclass.getHandler().getPermissions().hasPerms(event.getPlayer())) {
return;
} else {
- // TODO: organize tracker removals/unregisterers.
- botclass.getDataTrack().getBotTracker()
- .removeConnected(event.getPlayer().getName());
- botclass.getDataTrack().getChatTracker().trackplayers.remove(event
- .getPlayer().getName());
if (data.getBotTracker().botcts < 1) {
return;
} else {
@@ -18,18 +18,10 @@ public void handle(PlayerJoinEvent event) {
// check against countrybans!
antibot.getUtility().getDebug().debug("Countrybans size " + antibot.getDataTrack().getCountryTracker().countryBans.size());
antibot.getUtility().getDebug().debug("Checking IP " + IP);
- String country = antibot.getUtility().getGeoIP().lookupIp(IP);
- antibot.getUtility().getDebug().debug("Country " + country);
- if (antibot.getDataTrack().getCountryTracker().countryBans
- .contains(country)) {
+ if (antibot.getUtility().getGeoIP().determineFateForIP(IP)) {
antibot.getUtility().getDebug().debug("Banned IP " + IP);
// oh noes! he's in a forbidden country!
event.getPlayer().kickPlayer(Settings.countryBanMsg);
- // TODO: organize tracker removals/unregisterers.
- antibot.getDataTrack().getBotTracker()
- .removeConnected(event.getPlayer().getName());
- antibot.getDataTrack().getChatTracker().trackplayers.remove(event
- .getPlayer().getName());
if(Settings.banUsers) {
// well, we have permission to autoIP ban these country invaders.
@@ -0,0 +1,28 @@
+package somebody.is.madbro.listeners;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerKickEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+import somebody.is.madbro.AntiBotCore;
+
+public class KickListener implements Listener {
+
+ public AntiBotCore antibot = null;
+
+ public KickListener(AntiBotCore instance) {
+ antibot = instance;
+ }
+
+ @EventHandler
+ public void handle(PlayerKickEvent event) {
+ antibot.getUtility().getDeregister().handle(event.getPlayer());
+ }
+
+ @EventHandler
+ public void handle(PlayerQuitEvent event) {
+ antibot.getUtility().getDeregister().handle(event.getPlayer());
+ }
+
+}
@@ -18,6 +18,7 @@
public static boolean enableMultiAccs = true;
public static boolean banUsers = false;
public static boolean geoIP = true;
+ public static boolean whiteListCountry = false;
public static String kickMsg = "The Ban Hammer has spoken!";
public static String countryBanMsg = "Your country is banned from this server!";
public static String connectMsg = "You are not on the whitelist!";
@@ -44,6 +44,8 @@ public void saveSettings(File dataFolder) {
Boolean.toString(Settings.useOpPerms));
propConfig.setProperty("orgy-notify",
Boolean.toString(Settings.notify));
+ propConfig.setProperty("country-whitelist-mode",
+ Boolean.toString(Settings.whiteListCountry));
propConfig.setProperty("debug-mode",
Boolean.toString(Settings.debugmode));
propConfig.setProperty("enable-by-default",
@@ -176,6 +178,16 @@ public boolean loadSettings(File dataFolder1) {
if (load != null && !load3.equals(Settings.notify)) {
Settings.notify = load3;
}
+
+ load = propConfig.getProperty("country-whitelist-mode");
+ if (load != null) {
+ load3 = Boolean.parseBoolean(load);
+ } else {
+ load3 = Settings.whiteListCountry;
+ }
+ if (load != null && !load3.equals(Settings.whiteListCountry)) {
+ Settings.whiteListCountry = load3;
+ }
load = propConfig.getProperty("ban-users");
if (load != null) {
@@ -1,5 +1,40 @@
package somebody.is.madbro.toolbox;
+import org.bukkit.entity.Player;
+
+import somebody.is.madbro.AntiBotCore;
+
public class DeregisterUtility {
+ public AntiBotCore antibot = null;
+
+ public DeregisterUtility(AntiBotCore instance) {
+ antibot = instance;
+ }
+
+ public String getUserFromIP(String IP) {
+ try {
+ return antibot.getDataTrack().getBotTracker().ipList.get(IP);
+ } catch (Exception e) {
+ return "";
+ }
+ }
+
+ public void handle(String IP) {
+ if (!IP.contains("/")) {
+ IP = "/" + IP;
+ }
+ antibot.getDataTrack().getBotTracker()
+ .removeConnected(getUserFromIP(IP));
+ antibot.getDataTrack().getChatTracker().trackplayers
+ .remove(getUserFromIP(IP));
+ }
+
+ public void handle(Player pl) {
+ antibot.getDataTrack().getBotTracker()
+ .removeConnected(pl.getName());
+ antibot.getDataTrack().getChatTracker().trackplayers
+ .remove(getUserFromIP(pl.getName()));
+ }
+
}
@@ -12,6 +12,7 @@
import com.maxmind.geoip.LookupService;
import somebody.is.madbro.AntiBotCore;
+import somebody.is.madbro.settings.Settings;
public class GeoIPUtility {
@@ -42,14 +43,27 @@ public void initialize() {
System.out.println("Loading failed!");
}
}
-
+
// lookup functions
-
- public String lookupIp(String ip) {
+
+ public boolean determineFateForIP(String ip) {
String code = lkup.getCountry(ip).getCode();
- return code;
+ if (antibot.getDataTrack().getCountryTracker().countryBans
+ .contains(code)) {
+ // now determine the two behaviors.
+ if (Settings.whiteListCountry) {
+ return false; // dont ban.
+ } else {
+ return true; // yesban
+ }
+ } else {
+ if (Settings.whiteListCountry) {
+ return true; // yesban
+ }
+ }
+ return false;
}
-
+
// loading shit.
public boolean checkIfDownloaded() {
if (db.exists()) {
@@ -58,17 +72,18 @@ public boolean checkIfDownloaded() {
return false;
}
}
-
+
public void loadCountryBanList(String list) {
- if(list.length() == 0) {
+ if (list.length() == 0) {
return;
}
String[] liz = list.split(",");
for (int i = 0; i < liz.length; i++) {
antibot.getDataTrack().getCountryTracker().countryBans.add(liz[i]);
System.out.println("Loaded Country " + liz[i]);
}
- System.out.println("Loaded " + liz.length + " entries to CountryBans list.");
+ System.out.println("Loaded " + liz.length
+ + " entries to CountryBans list.");
}
public void preDownload() {
@@ -9,6 +9,7 @@
private BotUtility botutility = null;
private DebugUtility debugutility = null;
private GeoIPUtility geoiputility = null;
+ private DeregisterUtility deregisterutility = null;
//listeners
protected BotListener botlistener = null;
@@ -21,6 +22,7 @@ public UtilityCore(AntiBotCore instance) {
botutility = new BotUtility(instance);
debugutility = new DebugUtility(instance);
geoiputility = new GeoIPUtility(instance);
+ deregisterutility = new DeregisterUtility(instance);
}
public BotUtility getBot() {
@@ -35,5 +37,9 @@ public GeoIPUtility getGeoIP() {
return geoiputility;
}
+ public DeregisterUtility getDeregister() {
+ return deregisterutility;
+ }
+
}

0 comments on commit dbd0f27

Please sign in to comment.