Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Authentication time out kick error on entry #141

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.mastercapexd.auth.task;

import java.util.Iterator;
import java.util.Collection;
import java.util.concurrent.TimeUnit;

import com.bivashy.auth.api.AuthPlugin;
Expand All @@ -20,13 +20,11 @@ public AuthenticationTimeoutTask(AuthPlugin plugin) {
long now = System.currentTimeMillis();
long authTimeoutMillis = plugin.getConfig().getAuthTime();

// Iterator for preventing ConcurrentModificationException, because we are removing element on specific condition
Iterator<String> accountIdIterator = plugin.getAuthenticatingAccountBucket().getAccountIdEntries().iterator();
while (accountIdIterator.hasNext()) {
String accountPlayerId = accountIdIterator.next();
Account account = plugin.getAuthenticatingAccountBucket().getAuthenticatingAccountNullable(PlayerIdSupplier.of(accountPlayerId));
int accountEnterElapsedMillis = (int) (now -
plugin.getAuthenticatingAccountBucket().getEnterTimestampOrZero(PlayerIdSupplier.of(accountPlayerId)));
Collection<String> playerIds = plugin.getAuthenticatingAccountBucket().getAccountIdEntries();
for (String playerId : playerIds) {
PlayerIdSupplier playerIdSupplier = PlayerIdSupplier.of(playerId);
Account account = plugin.getAuthenticatingAccountBucket().getAuthenticatingAccountNullable(playerIdSupplier);
int accountEnterElapsedMillis = (int) (now - plugin.getAuthenticatingAccountBucket().getEnterTimestampOrZero(playerIdSupplier));

for (LinkEntryUser entryUser : plugin.getLinkEntryBucket().find(user -> user.getAccount().getPlayerId().equals(account.getPlayerId())))
if (entryUser != null)
Expand All @@ -35,12 +33,14 @@ public AuthenticationTimeoutTask(AuthPlugin plugin) {
} catch(UnsupportedOperationException ignored) { // If link type has no settings support
}

if(!account.getPlayer().isPresent())
plugin.getAuthenticatingAccountBucket().modifiable().removeIf(state -> state.getPlayerId().equals(playerId));

if (accountEnterElapsedMillis < authTimeoutMillis)
continue;
account.getPlayer()
.ifPresent(
player -> player.disconnect(plugin.getConfig().getServerMessages().getMessage("time-left", new ServerMessageContext(account))));
accountIdIterator.remove();
}
}, 0, 1, TimeUnit.SECONDS);
}
Expand Down
Loading