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

Alts registration per server #243

Closed
Closed
Show file tree
Hide file tree
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 @@ -19,6 +19,7 @@

package space.arim.libertybans.core.selector;

import java.util.List;
import java.util.Set;

import space.arim.dazzleconf.annote.ConfComments;
Expand Down Expand Up @@ -138,4 +139,30 @@ interface AltAccountExpiration {
long expirationTimeDays();

}

@SubSection
AltsRegistry altsRegistry();

@ConfHeader({"Controls if all servers should register the IP address of the player connecting."})
interface AltsRegistry {

@ConfComments("If true, all servers will register alts.")
@ConfKey("enable-all")
@ConfDefault.DefaultBoolean(true)
boolean enableAll();

@ConfComments({"If enableAll is false, this list will be used ",
"to determine which servers will register alts.",
"Please note that the server's name of the list should be the same as the ones in your proxy config",
"This is intended to be used by LibertyBans proxy installations.",
"If this is a backend server, please skip this option."})
@ConfKey("servers")
@DefaultStrings("")
List<String> servers();

@ConfComments({"If true, this backend server will register alts"})
@ConfKey("should-register")
@ConfDefault.DefaultBoolean(true)
boolean shouldRegister();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import net.kyori.adventure.text.Component;
import org.jooq.DSLContext;
import space.arim.libertybans.api.NetworkAddress;
import space.arim.libertybans.api.PunishmentType;
import space.arim.libertybans.api.punish.Punishment;
Expand Down Expand Up @@ -75,9 +76,21 @@ CentralisedFuture<Component> executeAndCheckConnection(UUID uuid, String name, N
return queryExecutor.get().queryWithRetry((context, transaction) -> {
Instant currentTime = time.currentTimestamp();

Association association = new Association(uuid, context);
association.associateCurrentName(name, currentTime);
association.associateCurrentAddress(address, currentTime);
EnforcementConfig config = configs.getMainConfig().enforcement();

if (config.altsRegistry().enableAll()) {
doAssociation(uuid, name, address, currentTime, context);

} else if (config.altsRegistry().shouldRegister()) {
doAssociation(uuid, name, address, currentTime, context);

} else {
List<String> servers = config.altsRegistry().servers();
String serverName = configs.getScopeConfig().serverName().overrideValue();
if (!servers.isEmpty() && servers.contains(serverName)) {
doAssociation(uuid, name, address, currentTime, context);
}
}

Punishment ban = selector.selectionByApplicabilityBuilder(uuid, address)
.type(PunishmentType.BAN)
Expand Down Expand Up @@ -113,4 +126,11 @@ CentralisedFuture<Component> executeAndCheckConnection(UUID uuid, String name, N
return futuresFactory.completedFuture(null);
});
}

private void doAssociation(UUID uuid, String name, NetworkAddress address,
Instant currentTime, DSLContext context) {
Association association = new Association(uuid, context);
association.associateCurrentName(name, currentTime);
association.associateCurrentAddress(address, currentTime);
}
}
Loading