From 74b3c1c84f04e9cf781770f3310a9f246abb90f6 Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 2 Oct 2012 15:32:53 +0200 Subject: [PATCH] Adjust Synchronization with captcha. --- .../nocheatplus/checks/chat/ChatListener.java | 34 +++++++++---------- .../nocheatplus/checks/chat/Relog.java | 25 +------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java index e690c34b..a8618d16 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java @@ -202,16 +202,10 @@ public class ChatListener implements Listener, INotifyReload { @EventHandler( priority = EventPriority.NORMAL) public void onPlayerLogin(final PlayerLoginEvent event) { - /* - * ____ _ _ _ - * | _ \| | __ _ _ _ ___ _ __ | | ___ (_)_ __ - * | |_) | |/ _` | | | |/ _ \ '__| _ | |/ _ \| | '_ \ - * | __/| | (_| | |_| | __/ | | |_| | (_) | | | | | - * |_| |_|\__,_|\__, |\___|_| \___/ \___/|_|_| |_| - * |___/ - */ + final Player player = event.getPlayer(); final ChatConfig cc = ChatConfig.getConfig(player); + final ChatData data = ChatData.getData(player); // Tell TickTask to update cached permissions. TickTask.requestPermissionUpdate(player.getName(), CheckType.CHAT); @@ -219,11 +213,15 @@ public class ChatListener implements Listener, INotifyReload { TickTask.updatePermissions(); // Reset captcha of player if needed. - captcha.resetCaptcha(player); + synchronized(data){ + captcha.resetCaptcha(cc, data); + // Execute the no pwnage check. + if (relog.isEnabled(player) && relog.unsafeLoginCheck(player, cc, data)) + event.disallow(Result.KICK_OTHER, cc.relogKickMessage); + + // TODO: Logins check. + } - // Execute the no pwnage check. - if (relog.isEnabled(player) && relog.checkLogin(player)) - event.disallow(Result.KICK_OTHER, cc.relogKickMessage); } @EventHandler( @@ -232,11 +230,13 @@ public class ChatListener implements Listener, INotifyReload { final Player player = event.getPlayer(); final ChatConfig cc = ChatConfig.getConfig(player); final ChatData data = ChatData.getData(player); - if (captcha.isEnabled(player) && captcha.shouldCheckCaptcha(cc, data)){ - // shouldCheckCaptcha: only if really enabled. - // Later: add check for cc.captchaOnLogin or so. - // TODO: maybe schedule this to coma after other plugins messages. - captcha.sendNewCaptcha(player, cc, data); + synchronized (data) { + if (captcha.isEnabled(player) && captcha.shouldCheckCaptcha(cc, data)){ + // shouldCheckCaptcha: only if really enabled. + // TODO: Later: add check for cc.captchaOnLogin or so (before shouldCheckCaptcha). + // TODO: maybe schedule this to come after other plugins messages. + captcha.sendNewCaptcha(player, cc, data); + } } } diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/Relog.java b/src/fr/neatmonster/nocheatplus/checks/chat/Relog.java index e5233c9a..5772c880 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/Relog.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/Relog.java @@ -13,29 +13,6 @@ public class Relog extends Check { super(CheckType.CHAT_RELOG); } - /** - * Checks a player (join). - * - * Only called from the main thread. - * - * @param player - * the player - * @return true, if successful - */ - public boolean checkLogin(final Player player) { - if (!isEnabled(player)) - return false; - - final ChatConfig cc = ChatConfig.getConfig(player); - final ChatData data = ChatData.getData(player); - - // Keep related to ChatData/NoPwnage/Color used lock. - synchronized (data) { - return unsafeLoginCheck(player, cc, data); - } - } - - /** * Check (Join), only call from synchronized code. * @@ -47,7 +24,7 @@ public class Relog extends Check { * the data * @return true, if successful */ - private boolean unsafeLoginCheck(final Player player, final ChatConfig cc, final ChatData data) { + public boolean unsafeLoginCheck(final Player player, final ChatConfig cc, final ChatData data) { boolean cancel = false; final long now = System.currentTimeMillis();