Process captcha for cancelled chat events as well.

This commit is contained in:
asofold 2014-02-22 00:00:10 +01:00
parent 4957f2875a
commit d24a13ed12
3 changed files with 37 additions and 40 deletions

View File

@ -39,14 +39,14 @@ public class Captcha extends AsyncCheck implements ICaptcha{
// Have they failed too man times?
if (data.captchTries > cc.captchaTries) {
// Find out if we need to kick the player or not.
executeActions(player, data.captchaVL, 1, cc.captchaActions,
isMainThread);
executeActions(player, data.captchaVL, 1, cc.captchaActions, isMainThread);
// (Resetting captcha tries is done on quit/kick).
}
// Display the question again (if not kicked).
if (player.isOnline())
if (player.isOnline()) {
sendCaptcha(player, cc, data);
}
}
}

View File

@ -121,28 +121,27 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
* @param event
* the event
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.LOWEST)
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncPlayerChatEvent event) {
/*
* ____ _ ____ _ _
* | _ \| | __ _ _ _ ___ _ __ / ___| |__ __ _| |_
* | |_) | |/ _` | | | |/ _ \ '__| | | | '_ \ / _` | __|
* | __/| | (_| | |_| | __/ | | |___| | | | (_| | |_
* |_| |_|\__,_|\__, |\___|_| \____|_| |_|\__,_|\__|
* |___/
*/
final Player player = event.getPlayer();
final boolean alreadyCancelled = event.isCancelled();
// Tell TickTask to update cached permissions.
// (Might omit this if already cancelled.)
TickTask.requestPermissionUpdate(player.getName(), CheckType.CHAT);
// First the color check.
if (color.isEnabled(player)) event.setMessage(color.check(player, event.getMessage(), false));
if (!alreadyCancelled && color.isEnabled(player)) {
event.setMessage(color.check(player, event.getMessage(), false));
}
// Then the no chat check.
if (text.isEnabled(player) && text.check(player, event.getMessage(), captcha, false))
// TODO: isMainThread: Could consider event.isAsync ?
if (textChecks(player, event.getMessage(), false, alreadyCancelled)) {
event.setCancelled(true);
}
}
/**
@ -151,23 +150,8 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
* @param event
* the event
*/
@EventHandler(
priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
/*
* ____ _ ____ _
* | _ \| | __ _ _ _ ___ _ __ / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| |
* | |_) | |/ _` | | | |/ _ \ '__| | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
* | __/| | (_| | |_| | __/ | | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
* |_| |_|\__,_|\__, |\___|_| \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
* |___/
* ____
* | _ \ _ __ ___ _ __ _ __ ___ ___ ___ ___ ___
* | |_) | '__/ _ \ '_ \| '__/ _ \ / __/ _ \/ __/ __|
* | __/| | | __/ |_) | | | (_) | (_| __/\__ \__ \
* |_| |_| \___| .__/|_| \___/ \___\___||___/___/
* |_|
*/
final Player player = event.getPlayer();
// Tell TickTask to update cached permissions.
@ -207,16 +191,23 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
final boolean handleAsChat = chatCommands.hasAnyPrefixWords(lcMessage, lcAltMessage);
if (handleAsChat){
// Treat as chat.
// TODO: At least cut off the command (!).
if (text.isEnabled(player) && text.check(player, message, captcha, true))
event.setCancelled(true);
// TODO: Consider requesting permission updates on these, for consistency.
// TODO: Cut off the command (?).
if (textChecks(player, message, true, false)) {
event.setCancelled(true);
}
}
else if (!commandExclusions.hasAnyPrefixWords(lcMessage, lcAltMessage)){
// Treat as command.
if (commands.isEnabled(player) && commands.check(player, message, captcha))
event.setCancelled(true);
if (commands.isEnabled(player) && commands.check(player, message, captcha)) {
event.setCancelled(true);
}
}
}
private boolean textChecks(final Player player, final String message, final boolean isMainThread, final boolean alreadyCancelled) {
return text.isEnabled(player) && text.check(player, message, captcha, isMainThread, alreadyCancelled);
}
/**

View File

@ -53,15 +53,16 @@ public class Text extends AsyncCheck implements INotifyReload{
* The message to check.
* @param captcha
* Used for starting captcha on failure, if configured so.
* @param alreadyCancelled
* @return
*/
public boolean check(final Player player, final String message, final ICaptcha captcha, boolean isMainThread) {
public boolean check(final Player player, final String message, final ICaptcha captcha, boolean isMainThread, final boolean alreadyCancelled) {
final ChatConfig cc = ChatConfig.getConfig(player);
final ChatData data = ChatData.getData(player);
synchronized (data) {
return unsafeCheck(player, message, captcha, cc, data, isMainThread);
return unsafeCheck(player, message, captcha, cc, data, isMainThread, alreadyCancelled);
}
}
@ -93,15 +94,20 @@ public class Text extends AsyncCheck implements INotifyReload{
* @param cc
* @param data
* @param isMainThread
* @param alreadyCancelled
* @return
*/
private boolean unsafeCheck(final Player player, final String message, final ICaptcha captcha,
final ChatConfig cc, final ChatData data, boolean isMainThread) {
final ChatConfig cc, final ChatData data, boolean isMainThread, final boolean alreadyCancelled) {
// Test captcha.
if (captcha.shouldCheckCaptcha(cc, data)){
// TODO: Skip captcha for "handleaschat" commands? [controversial potential]
if (captcha.shouldCheckCaptcha(cc, data)) {
captcha.checkCaptcha(player, message, cc, data, isMainThread);
return true;
} else if (alreadyCancelled) {
// Skip checking.
return true;
}
// Take time once: