Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
were491 authored Feb 6, 2022
1 parent 7ca850f commit 75101fa
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 75101fa

Please sign in to comment.