mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 16:49:39 +01:00
captcha: adjust to reset on login.
This commit is contained in:
parent
0160924567
commit
f3a9250ee9
@ -176,6 +176,9 @@ public class ChatListener implements Listener, INotifyReload {
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final ChatConfig cc = ChatConfig.getConfig(player);
|
final ChatConfig cc = ChatConfig.getConfig(player);
|
||||||
|
|
||||||
|
// Reset captcha of player if needed.
|
||||||
|
noPwnage.resetCaptcha(player);
|
||||||
|
|
||||||
// Execute the no pwnage check.
|
// Execute the no pwnage check.
|
||||||
if (noPwnage.isEnabled(player) && noPwnage.checkLogin(player))
|
if (noPwnage.isEnabled(player) && noPwnage.checkLogin(player))
|
||||||
event.disallow(Result.KICK_OTHER, cc.noPwnageReloginKickMessage);
|
event.disallow(Result.KICK_OTHER, cc.noPwnageReloginKickMessage);
|
||||||
|
@ -53,4 +53,10 @@ public interface ICaptcha {
|
|||||||
*/
|
*/
|
||||||
public boolean shouldStartCaptcha(ChatConfig cc, ChatData data);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -246,9 +246,7 @@ public class NoPwnage extends Check implements ICaptcha{
|
|||||||
// Find out if we need to kick the player or not.
|
// Find out if we need to kick the player or not.
|
||||||
executeActionsThreadSafe(player, data.captchaVL, 1, cc.noPwnageCaptchaActions,
|
executeActionsThreadSafe(player, data.captchaVL, 1, cc.noPwnageCaptchaActions,
|
||||||
isMainThread);
|
isMainThread);
|
||||||
// reset in case of reconnection allowed.
|
// (Resetting captcha tries is done on quit/kick).
|
||||||
if (!player.isOnline())
|
|
||||||
data.noPwnageCaptchTries = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the question again (if not kicked).
|
// Display the question again (if not kicked).
|
||||||
@ -260,12 +258,42 @@ public class NoPwnage extends Check implements ICaptcha{
|
|||||||
@Override
|
@Override
|
||||||
public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
|
public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
|
||||||
// Display a captcha to the player.
|
// Display a captcha to the player.
|
||||||
|
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 = "";
|
data.noPwnageGeneratedCaptcha = "";
|
||||||
for (int i = 0; i < cc.noPwnageCaptchaLength; i++)
|
for (int i = 0; i < cc.noPwnageCaptchaLength; i++)
|
||||||
data.noPwnageGeneratedCaptcha += cc.noPwnageCaptchaCharacters.charAt(random
|
data.noPwnageGeneratedCaptcha += cc.noPwnageCaptchaCharacters.charAt(random
|
||||||
.nextInt(cc.noPwnageCaptchaCharacters.length()));
|
.nextInt(cc.noPwnageCaptchaCharacters.length()));
|
||||||
sendCaptcha(player, cc, data);
|
}
|
||||||
data.noPwnageHasStartedCaptcha = true;
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user