diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java index 25bf16c5..cbf5d7a2 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java @@ -175,7 +175,10 @@ public class ChatListener implements Listener, INotifyReload { */ final Player player = event.getPlayer(); final ChatConfig cc = ChatConfig.getConfig(player); - + + // Reset captcha of player if needed. + noPwnage.resetCaptcha(player); + // Execute the no pwnage check. if (noPwnage.isEnabled(player) && noPwnage.checkLogin(player)) event.disallow(Result.KICK_OTHER, cc.noPwnageReloginKickMessage); diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ICaptcha.java b/src/fr/neatmonster/nocheatplus/checks/chat/ICaptcha.java index 4ac14c87..252a3cf0 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ICaptcha.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ICaptcha.java @@ -53,4 +53,10 @@ public interface ICaptcha { */ public boolean shouldStartCaptcha(ChatConfig cc, ChatData data); + /** + * Just resets tries, generate new captcha if necessary. + * @param cc + * @param data + */ + public void resetCaptcha(ChatConfig cc, ChatData data); } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java b/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java index cccc3d79..14613809 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/NoPwnage.java @@ -246,9 +246,7 @@ public class NoPwnage extends Check implements ICaptcha{ // Find out if we need to kick the player or not. executeActionsThreadSafe(player, data.captchaVL, 1, cc.noPwnageCaptchaActions, isMainThread); - // reset in case of reconnection allowed. - if (!player.isOnline()) - data.noPwnageCaptchTries = 0; + // (Resetting captcha tries is done on quit/kick). } // Display the question again (if not kicked). @@ -260,15 +258,45 @@ public class NoPwnage extends Check implements ICaptcha{ @Override public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) { // Display a captcha to the player. - data.noPwnageGeneratedCaptcha = ""; - for (int i = 0; i < cc.noPwnageCaptchaLength; i++) - data.noPwnageGeneratedCaptcha += cc.noPwnageCaptchaCharacters.charAt(random - .nextInt(cc.noPwnageCaptchaCharacters.length())); + generateCaptcha(cc, data, true); sendCaptcha(player, cc, data); data.noPwnageHasStartedCaptcha = true; } + /** + * Just generate captcha, reset tries if set so. + * @param cc + * @param data + * @param reset + */ + public void generateCaptcha(ChatConfig cc, ChatData data, boolean reset) { + if (reset) data.noPwnageCaptchTries = 0; + data.noPwnageGeneratedCaptcha = ""; + for (int i = 0; i < cc.noPwnageCaptchaLength; i++) + data.noPwnageGeneratedCaptcha += cc.noPwnageCaptchaCharacters.charAt(random + .nextInt(cc.noPwnageCaptchaCharacters.length())); + } + + /** + * Reset captcha, synchronizes over ChatData instance for the player.. + * @param player + */ + public void resetCaptcha(Player player){ + ChatData data = ChatData.getData(player); + synchronized (data) { + resetCaptcha(ChatConfig.getConfig(player), data); + } + } + @Override + public void resetCaptcha(ChatConfig cc, ChatData data){ + data.noPwnageCaptchTries = 0; + if (shouldCheckCaptcha(cc, data) || shouldStartCaptcha(cc, data)){ + generateCaptcha(cc, data, true); + } + } + + @Override public void sendCaptcha(Player player, ChatConfig cc, ChatData data) { player.sendMessage(CheckUtils.replaceColors(cc.noPwnageCaptchaQuestion.replace("[captcha]", data.noPwnageGeneratedCaptcha)));