v1.1.0. Performance improvements and changes to throttling. Adds /capatchafy status. Light cleanup.

This commit is contained in:
Hockeh 2018-01-06 00:30:05 -06:00
parent 1ba051ebe6
commit 1e642ae243
5 changed files with 50 additions and 30 deletions

View file

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>me.hockey</groupId> <groupId>me.hockey</groupId>
<artifactId>Capatchafy</artifactId> <artifactId>Capatchafy</artifactId>
<version>1.0.1</version> <version>1.1.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View file

@ -35,20 +35,20 @@ public class CapatchafyCommand implements CommandExecutor
if (!sender.hasPermission("capatchafy.command")) if (!sender.hasPermission("capatchafy.command"))
{ {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command."); sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
return true; return false;
} }
if (Capatchafy.configs.config.getBoolean("always-on")) if (Capatchafy.configs.config.getBoolean("always-on"))
{ {
sender.sendMessage(ChatColor.RED + "The server owner has Capatchafy enabled at all times. You are not allowed to turn it off or change the security level."); sender.sendMessage(ChatColor.RED + "The server owner has Capatchafy enabled at all times. You are not allowed to turn it off or change the security level.");
return true; return false;
} }
//TODO Fix arguments problem, it will throw errors if the parameters aren't filled out properly. Also, make it show usage when the security level arg is spelled wrong. //TODO Fix arguments problem, it will throw errors if the parameters aren't filled out properly. Also, make it show usage when the security level arg is spelled wrong.
if (args.length < 1) if (args.length < 1)
{ {
sender.sendMessage("Usage: /capatchafy <on:off> <friendly:moderate:strict>"); sender.sendMessage("Usage: /capatchafy <on:off:status> <friendly:moderate:strict>");
return true; return false;
} }
if (args[0].equalsIgnoreCase("on")) if (args[0].equalsIgnoreCase("on"))
@ -83,9 +83,11 @@ public class CapatchafyCommand implements CommandExecutor
} }
else else
{ {
sender.sendMessage("Usage: /capatchafy <on:off> <friendly:moderate:strict>"); sender.sendMessage("Usage: /capatchafy <on:off:status> <friendly:moderate:strict>");
return false;
} }
sender.sendMessage("Capatchafy will run in security level " + Capatchafy.securityLevel + ". It will not be auto-disabled."); sender.sendMessage("Capatchafy will run in security level " + Capatchafy.securityLevel + ". It will not be auto-disabled.");
return true;
} }
else if (args[0].equalsIgnoreCase("off")) else if (args[0].equalsIgnoreCase("off"))
{ {
@ -99,8 +101,19 @@ public class CapatchafyCommand implements CommandExecutor
{ {
Capatchafy.forced = true; Capatchafy.forced = true;
sender.sendMessage(ChatColor.YELLOW + "Capatchafy " + ChatColor.RED + "will not" + ChatColor.YELLOW + " automatically enable if the server detects an attack."); sender.sendMessage(ChatColor.YELLOW + "Capatchafy " + ChatColor.RED + "will not" + ChatColor.YELLOW + " automatically enable if the server detects an attack.");
return true;
} }
} }
else if (args[0].equalsIgnoreCase("status"))
{
sender.sendMessage(ChatColor.GRAY + "Capatchafy is enabled: " + ChatColor.YELLOW + Capatchafy.enabled);
sender.sendMessage(ChatColor.GRAY + "Capatchafy is set to run in mode: " + ChatColor.YELLOW + Capatchafy.securityLevel);
return true;
}
else
{
sender.sendMessage("Usage: /capatchafy <on:off:status> <friendly:moderate:strict>");
}
return false; return false;
} }
} }

View file

@ -36,7 +36,6 @@ public class Configuration
public void startup() throws IOException public void startup() throws IOException
{ {
//startup()
saveConfig(); saveConfig();
saveNames(false); saveNames(false);
loadConfigs(); loadConfigs();
@ -62,7 +61,6 @@ public class Configuration
{ {
ips.set("authorized-ips", alwaysAuthorizedList); ips.set("authorized-ips", alwaysAuthorizedList);
ips.save(ipsFile); ips.save(ipsFile);
//Bukkit.broadcastMessage("IP Config Saved(?)");
} }
} }
@ -77,7 +75,6 @@ public class Configuration
{ {
Capatchafy.plugin.saveResource("config.yml", false); Capatchafy.plugin.saveResource("config.yml", false);
} }
//Bukkit.broadcastMessage("Default config saved.");
} }
public void loadConfigs() throws IOException public void loadConfigs() throws IOException
@ -85,7 +82,6 @@ public class Configuration
config = YamlConfiguration.loadConfiguration(configFile); config = YamlConfiguration.loadConfiguration(configFile);
ips = YamlConfiguration.loadConfiguration(ipsFile); ips = YamlConfiguration.loadConfiguration(ipsFile);
alwaysAuthorizedList = ips.getStringList("authorized-ips"); alwaysAuthorizedList = ips.getStringList("authorized-ips");
//Bukkit.broadcastMessage("Configs loaded");
} }
public void setAuthorized(String ip, boolean authorize) public void setAuthorized(String ip, boolean authorize)

View file

@ -16,12 +16,14 @@
*/ */
package me.hockey.capatchafy; package me.hockey.capatchafy;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPreLoginEvent;
import java.util.Date; import java.util.Date;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class Listeners implements Listener public class Listeners implements Listener
@ -33,22 +35,22 @@ public class Listeners implements Listener
public long throttleTime; //The higher, the more often players will be counted as possible spammers. Required time between each login to not be considered an attack. public long throttleTime; //The higher, the more often players will be counted as possible spammers. Required time between each login to not be considered an attack.
public int throttleLogins; //The lower, the quicker the capatchas will auto-enable. Aka max points before capatchafy is enabled. public int throttleLogins; //The lower, the quicker the capatchas will auto-enable. Aka max points before capatchafy is enabled.
public long removeAllPointsTime = 7L; //Remove all points after x seconds. public long removeAllPointsTime = 7L; //Remove all points after x seconds. Default: 7
public int maxAttacks = 3; //Set to 0 to disable this function. public int maxAttacks = 3; //Set to 0 to disable this function. Default: 3
public long startupThrottleTime = 1L; //The throttle time on startup. Default: 1 public long startupThrottleTime = 1L; //The throttle time on startup. Default: 1
public int startupThrottleLogins = 20; //The throttle logins on startup. Default: 20 public int startupThrottleLogins = 20; //The throttle logins on startup. Default: 20
public long defaultThrottleTime = 3L; //After 30 seconds, the server defaults back to this. Default: 3 public long defaultThrottleTime = 3L; //After 30 seconds, the server defaults back to this. Default: 3
public int defaultThrottleLogins = 8; //Default: 9 public int defaultThrottleLogins = 8; //Default: 8
public static String url; public static String url;
//TODO If IP matches IP in TFM, dont force admins to verify. //TODO If IP matches IP in TFM, dont force admins to verify.
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerPreLoginEvent event) public void onPlayerLogin(PlayerLoginEvent event)
{ {
if (!Capatchafy.forced && !Capatchafy.configs.config.getBoolean("always-on")) if (!Capatchafy.forced && !Capatchafy.configs.config.getBoolean("always-on") && !Capatchafy.enabled)
{ {
throttleConnections(); throttleConnections();
} }
@ -56,7 +58,7 @@ public class Listeners implements Listener
String ip = event.getAddress().toString().replaceAll("/", ""); String ip = event.getAddress().toString().replaceAll("/", "");
if (!Capatchafy.configs.isAuthorized(ip)) if (!Capatchafy.configs.isAuthorized(ip))
{ {
event.disallow(PlayerPreLoginEvent.Result.KICK_OTHER, ChatColor.RED + "" + ChatColor.BOLD + "Yikes, we're under attack! Please solve the capatcha.\n" + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + "" + ChatColor.BOLD + "Yikes, we're under attack! Please solve the capatcha.\n" +
ChatColor.WHITE + "Please go to " + ChatColor.GOLD + url + ChatColor.WHITE + " in your web browser and solve the capatcha.\n" + ChatColor.WHITE + "Please go to " + ChatColor.GOLD + url + ChatColor.WHITE + " in your web browser and solve the capatcha.\n" +
"Once solved successfully, you will be able to join."); "Once solved successfully, you will be able to join.");
return; return;
@ -64,8 +66,6 @@ public class Listeners implements Listener
if (Capatchafy.securityLevel == 3) if (Capatchafy.securityLevel == 3)
{ {
Capatchafy.configs.setAuthorized(ip, false); Capatchafy.configs.setAuthorized(ip, false);
//Bukkit.broadcastMessage("Player unauthorized.");
//Bukkit.broadcastMessage("Player is authorized: " + Capatchafy.configs.isAuthorized(ip));
} }
} }
@ -83,24 +83,37 @@ public class Listeners implements Listener
points++; points++;
} }
if (diffInSeconds >= removeAllPointsTime && !Capatchafy.forced) if (diffInSeconds >= removeAllPointsTime)
{ {
points = 0; points = 0;
//Bukkit.broadcastMessage("[Capatchafy] Disabled");
Capatchafy.enabled = false;
} }
if (points == throttleLogins && !Capatchafy.enabled) if (points == throttleLogins && !Capatchafy.enabled)
{ {
//Bukkit.broadcastMessage("[Capatchafy] Enabled"); Bukkit.broadcastMessage(ChatColor.DARK_RED + "Capatcha-based verification has been enabled.");
Capatchafy.enabled = true; Capatchafy.enabled = true;
numberOfAttacks++; numberOfAttacks++;
points = 0;
new BukkitRunnable()
{
@Override
public void run()
{
if (!Capatchafy.forced && Capatchafy.enabled)
{
Bukkit.broadcastMessage(ChatColor.GREEN + "Capatcha-based verification has been disabled.");
Capatchafy.enabled = false;
}
}
}.runTaskLater(Capatchafy.plugin, 5 * 60 * 20); //Default 5 * 60 * 20
} }
if (numberOfAttacks >= maxAttacks && maxAttacks != 0) if (numberOfAttacks >= maxAttacks && maxAttacks != 0)
{ {
//Bukkit.broadcastMessage("[Capatchafy] Enabled for good.");
Capatchafy.enabled = true; Capatchafy.enabled = true;
Capatchafy.forced = true; Capatchafy.forced = true;
lastLogin = currentTime; lastLogin = currentTime;
Bukkit.broadcastMessage(ChatColor.DARK_RED + "Capatchafy will not auto-disable.");
return; return;
} }
lastLogin = currentTime; lastLogin = currentTime;
@ -120,7 +133,6 @@ public class Listeners implements Listener
{ {
this.throttleTime = startupThrottleTime; this.throttleTime = startupThrottleTime;
this.throttleLogins = startupThrottleLogins; this.throttleLogins = startupThrottleLogins;
//Bukkit.getLogger().info("[Capatchafy] Delay started. " + throttleTime + " " + throttleLogins);
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
@ -128,7 +140,6 @@ public class Listeners implements Listener
{ {
throttleTime = defaultThrottleTime; throttleTime = defaultThrottleTime;
throttleLogins = defaultThrottleLogins; throttleLogins = defaultThrottleLogins;
//Bukkit.broadcastMessage("[Capatchafy] Delay ended: " + throttleTime + " " + throttleLogins);
} }
}.runTaskLater(Capatchafy.plugin, 1200); }.runTaskLater(Capatchafy.plugin, 1200);
} }

View file

@ -1,5 +1,5 @@
name: Capatchafy name: Capatchafy
version: 1.0.1 version: 1.1.0
main: me.hockey.capatchafy.Capatchafy main: me.hockey.capatchafy.Capatchafy
commands: commands: