From 40ce01f65edfd66503ef5d34f0454104c2a9bfc2 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 4 Jun 2016 10:44:34 +0200 Subject: [PATCH] #601 Increase captcha count on login start - Increase login count at start of the login process (as done previously) and not only when login has failed AND player is still online - Add missing javadoc to CaptchaManager --- .../java/fr/xephi/authme/cache/CaptchaManager.java | 5 +++++ .../xephi/authme/process/login/AsynchronousLogin.java | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java b/src/main/java/fr/xephi/authme/cache/CaptchaManager.java index 6d262f22..ec7deca9 100644 --- a/src/main/java/fr/xephi/authme/cache/CaptchaManager.java +++ b/src/main/java/fr/xephi/authme/cache/CaptchaManager.java @@ -110,6 +110,11 @@ public class CaptchaManager implements SettingsDependent { return false; } + /** + * Resets the login count of the given player to 0. + * + * @param name the player's name + */ public void resetCounts(String name) { if (isEnabled) { captchaCodes.remove(name.toLowerCase()); diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 593ee25b..4116ffd0 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -73,9 +73,14 @@ public class AsynchronousLogin implements AsynchronousProcess { private boolean needsCaptcha(Player player) { - if (captchaManager.isCaptchaRequired(player.getName())) { - service.send(player, MessageKey.USAGE_CAPTCHA, captchaManager.getCaptchaCodeOrGenerateNew(player.getName())); + final String playerName = player.getName(); + if (captchaManager.isCaptchaRequired(playerName)) { + service.send(player, MessageKey.USAGE_CAPTCHA, captchaManager.getCaptchaCodeOrGenerateNew(playerName)); return true; + } else { + // Increase the count here before knowing the result of the login. + // If login is successful, we clear the count for the player + captchaManager.increaseCount(playerName); } return false; } @@ -199,7 +204,6 @@ public class AsynchronousLogin implements AsynchronousProcess { if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) { ConsoleLogger.info(player.getName() + " used the wrong password"); } - captchaManager.increaseCount(name); if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) { bukkitService.scheduleSyncDelayedTask(new Runnable() { @Override