From 75101fa9dfecfaab0d5a9e37cb6c9789824d53cd Mon Sep 17 00:00:00 2001 From: were491 <34976611+were491@users.noreply.github.com> Date: Sun, 6 Feb 2022 01:05:13 -0600 Subject: [PATCH] Add files via upload --- .../easyauth/commands/LoginCommand.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/xyz/nikitacartes/easyauth/commands/LoginCommand.java b/src/main/java/xyz/nikitacartes/easyauth/commands/LoginCommand.java index ba9508c0..04a38dfb 100644 --- a/src/main/java/xyz/nikitacartes/easyauth/commands/LoginCommand.java +++ b/src/main/java/xyz/nikitacartes/easyauth/commands/LoginCommand.java @@ -57,20 +57,16 @@ private static int login(ServerCommandSource source, String pass) throws Command return 0; } - int maxLoginTries = config.main.maxLoginTries; // ++ the login tries. Maybe it's more threadsafe here than in the thread pool? - if (playerCacheMap.get(uuid).loginTries <= maxLoginTries) { - playerCacheMap.get(uuid).loginTries++; - } + // But if not, you could save the calls to set this back to 0. + playerCacheMap.get(uuid).loginTries++; // Putting rest of the command in different thread to avoid lag spikes THREADPOOL.submit(() -> { + int maxLoginTries = config.main.maxLoginTries; AuthHelper.PasswordOptions passwordResult = AuthHelper.checkPassword(uuid, pass.toCharArray()); - if (playerCacheMap.get(uuid).loginTries > maxLoginTries && maxLoginTries != -1) { - player.networkHandler.disconnect(TranslationHelper.getLoginTriesExceeded()); - return; - } else if (passwordResult == AuthHelper.PasswordOptions.CORRECT) { + if (passwordResult == AuthHelper.PasswordOptions.CORRECT) { player.sendMessage(TranslationHelper.getSuccessfullyAuthenticated(), false); ((PlayerAuth) player).setAuthenticated(true); @@ -89,6 +85,9 @@ private static int login(ServerCommandSource source, String pass) throws Command } // Kicking the player out else if (maxLoginTries == 1) { + // Reset their login tries + playerCacheMap.get(uuid).loginTries = 0; + player.networkHandler.disconnect(TranslationHelper.getWrongPassword()); return; } else if(playerCacheMap.get(uuid).loginTries == maxLoginTries) {