Adjust Synchronization with captcha.

This commit is contained in:
asofold 2012-10-02 15:32:53 +02:00
parent 1e423b85d4
commit 74b3c1c84f
2 changed files with 18 additions and 41 deletions

View File

@ -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);
}
}
}

View File

@ -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();