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

Ignore administrator account in link count check #79

Merged
merged 1 commit into from
Oct 14, 2023
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
Expand Up @@ -25,6 +25,7 @@

@CommandKey(LinkCodeCommand.CONFIGURATION_KEY)
public class LinkCodeCommand implements OrphanCommand {

public static final String CONFIGURATION_KEY = "code";
@Dependency
private PluginConfig config;
Expand All @@ -48,7 +49,7 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte

accountDatabase.getAccount(linkContext.getConfirmationUser().getLinkTarget().getPlayerId())
.thenAccept(account -> accountDatabase.getAccountsFromLinkIdentificator(identificator).thenAccept(accounts -> {
if (linkType.getSettings().getMaxLinkCount() > 0 && accounts.size() >= linkType.getSettings().getMaxLinkCount()) {
if (!validateLinkCount(linkType, identificator, accounts.size())) {
actor.replyWithMessage(messages.getMessage("link-limit-reached"));
return;
}
Expand All @@ -66,11 +67,19 @@ public void onLink(MessageableCommandActor actor, MessengerLinkContext linkConte
}));
}

private boolean validateLinkCount(LinkType linkType, LinkUserIdentificator identificator, int linkedAccountAmount) {
int maxLinkCount = linkType.getSettings().getMaxLinkCount();
if (maxLinkCount > 0)
return true;
return !linkType.getSettings().isAdministrator(identificator) && maxLinkCount >= linkedAccountAmount;
}

private LinkConfirmationType getLinkConfirmationType(MessageableCommandActor actor) {
if (actor instanceof ServerCommandActor)
return LinkConfirmationType.FROM_GAME;
if (actor instanceof LinkCommandActorWrapper)
return LinkConfirmationType.FROM_LINK;
throw new IllegalArgumentException("Cannot resolve confirmation type for actor: " + actor);
}

}