Changed configuration format from hocon to toml
This commit is contained in:
parent
47c7e157c9
commit
e871d555d6
@ -34,11 +34,6 @@
|
|||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>configurate-hocon</artifactId>
|
|
||||||
<version>4.1.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.games647</groupId>
|
<groupId>com.github.games647</groupId>
|
||||||
<artifactId>fastlogin.velocity</artifactId>
|
<artifactId>fastlogin.velocity</artifactId>
|
||||||
@ -54,42 +49,6 @@
|
|||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.2.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.3.1-SNAPSHOT</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.spongepowered</pattern>
|
|
||||||
<shadedPattern>com.glyart.authmevelocity.libs.configurate</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/maven/</exclude>
|
|
||||||
<exclude>META-INF/*.MF</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.glyart.authmevelocity.proxy;
|
package com.glyart.authmevelocity.proxy;
|
||||||
|
|
||||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
|
|
||||||
import com.glyart.authmevelocity.proxy.listener.FastLoginListener;
|
import com.glyart.authmevelocity.proxy.listener.FastLoginListener;
|
||||||
import com.glyart.authmevelocity.proxy.listener.PluginMessageListener;
|
import com.glyart.authmevelocity.proxy.listener.PluginMessageListener;
|
||||||
import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.moandjiezana.toml.Toml;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
@ -14,6 +14,9 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -25,8 +28,7 @@ public class AuthMeVelocityPlugin {
|
|||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Path pluginDirectory;
|
private final Path pluginDirectory;
|
||||||
private final AuthmeVelocityAPI api;
|
private AuthmeVelocityAPI api;
|
||||||
Config config = null;
|
|
||||||
|
|
||||||
protected final Set<UUID> loggedPlayers = Collections.<UUID>synchronizedSet(new HashSet<>());
|
protected final Set<UUID> loggedPlayers = Collections.<UUID>synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
@ -35,13 +37,17 @@ public class AuthMeVelocityPlugin {
|
|||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.pluginDirectory = dataDirectory;
|
this.pluginDirectory = dataDirectory;
|
||||||
this.api = new AuthmeVelocityAPI(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
this.config = Objects.requireNonNull(new AuthMeConfig().loadConfig(pluginDirectory, logger), "configuration cannot be null");
|
Toml toml = this.loadConfig(pluginDirectory, logger);
|
||||||
|
if(toml == null){
|
||||||
|
logger.warn("Failed to load config.toml. Shutting down.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AuthMeConfig config = Objects.requireNonNull(new AuthMeConfig(toml), "configuration cannot be null");
|
||||||
|
this.api = new AuthmeVelocityAPI(this, config);
|
||||||
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
||||||
proxy.getEventManager().register(this, new ProxyListener(config, api));
|
proxy.getEventManager().register(this, new ProxyListener(config, api));
|
||||||
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api));
|
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api));
|
||||||
@ -64,4 +70,25 @@ public class AuthMeVelocityPlugin {
|
|||||||
public AuthmeVelocityAPI getAPI(){
|
public AuthmeVelocityAPI getAPI(){
|
||||||
return this.api;
|
return this.api;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Toml loadConfig(Path path, Logger logger){
|
||||||
|
if(!Files.exists(path)){
|
||||||
|
try {
|
||||||
|
Files.createDirectory(path);
|
||||||
|
} catch(IOException e){
|
||||||
|
logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Path configPath = path.resolve("config.toml");
|
||||||
|
if(!Files.exists(configPath)){
|
||||||
|
try(InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.toml")){
|
||||||
|
Files.copy(in, configPath);
|
||||||
|
} catch(IOException e){
|
||||||
|
logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Toml().read(configPath.toFile());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
@ -15,8 +16,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public final class AuthmeVelocityAPI {
|
public final class AuthmeVelocityAPI {
|
||||||
private final AuthMeVelocityPlugin plugin;
|
private final AuthMeVelocityPlugin plugin;
|
||||||
AuthmeVelocityAPI(AuthMeVelocityPlugin plugin){
|
private final AuthMeConfig config;
|
||||||
|
AuthmeVelocityAPI(AuthMeVelocityPlugin plugin, AuthMeConfig config){
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Check if the player is logged in or not
|
* Check if the player is logged in or not
|
||||||
@ -72,7 +75,7 @@ public final class AuthmeVelocityAPI {
|
|||||||
* @return if the server is a login server
|
* @return if the server is a login server
|
||||||
*/
|
*/
|
||||||
public boolean isAuthServer(@NotNull RegisteredServer server){
|
public boolean isAuthServer(@NotNull RegisteredServer server){
|
||||||
return plugin.config.getAuthServers().contains(server.getServerInfo().getName());
|
return config.getAuthServers().contains(server.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,6 +84,6 @@ public final class AuthmeVelocityAPI {
|
|||||||
* @return if the connection is made from a login server
|
* @return if the connection is made from a login server
|
||||||
*/
|
*/
|
||||||
public boolean isAuthServer(@NotNull ServerConnection connection){
|
public boolean isAuthServer(@NotNull ServerConnection connection){
|
||||||
return plugin.config.getAuthServers().contains(connection.getServerInfo().getName());
|
return config.getAuthServers().contains(connection.getServerInfo().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,76 +1,24 @@
|
|||||||
package com.glyart.authmevelocity.proxy.config;
|
package com.glyart.authmevelocity.proxy.config;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import com.moandjiezana.toml.Toml;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
|
||||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
|
||||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
|
||||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
|
||||||
|
|
||||||
public class AuthMeConfig {
|
public final class AuthMeConfig {
|
||||||
public Config loadConfig(@NotNull Path path, @NotNull Logger logger){
|
private final List<String> authServers;
|
||||||
Path configPath = Objects.requireNonNull(path).resolve("config.conf");
|
private final ServerOnLogin serverOnLogin;
|
||||||
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
private final Commands commands;
|
||||||
.defaultOptions(opts -> opts
|
|
||||||
.shouldCopyDefaults(true)
|
|
||||||
.header("AuthmeVelocity Proxy\n\nOriginal Developer: xQuickGlare\nCurrent Developer: 4drian3d")
|
|
||||||
)
|
|
||||||
.path(configPath)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
public AuthMeConfig(Toml toml){
|
||||||
final CommentedConfigurationNode node = loader.load();
|
this.authServers = toml.getList("authServers");
|
||||||
config = node.get(Config.class);
|
this.serverOnLogin = toml.getTable("SendOnLogin").to(ServerOnLogin.class);
|
||||||
node.set(Config.class, config);
|
this.commands = toml.getTable("Commands").to(Commands.class);
|
||||||
loader.save(node);
|
|
||||||
return config;
|
|
||||||
} catch (ConfigurateException exception){
|
|
||||||
logger.error("Could not load configuration: {}", exception.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigSerializable
|
|
||||||
public static class Config {
|
|
||||||
|
|
||||||
@Comment("List of login/registration servers")
|
|
||||||
private Set<String> authservers = Set.of(
|
|
||||||
"auth1",
|
|
||||||
"auth2"
|
|
||||||
);
|
|
||||||
|
|
||||||
private Commands commands = new Commands();
|
|
||||||
|
|
||||||
private ServerOnLogin send = new ServerOnLogin();
|
|
||||||
|
|
||||||
public Set<String> getAuthServers(){
|
|
||||||
return this.authservers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Commands getCommandsConfig(){
|
|
||||||
return this.commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerOnLogin getToServerOptions(){
|
|
||||||
return this.send;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ConfigSerializable
|
|
||||||
public static class ServerOnLogin {
|
public static class ServerOnLogin {
|
||||||
@Comment("Send logged in players to another server?")
|
private boolean sendToServerOnLogin;
|
||||||
private boolean sendToServerOnLogin = false;
|
private List<String> teleportServers;
|
||||||
|
|
||||||
@Comment("List of servers to send\nOne of these servers will be chosen at random")
|
|
||||||
private List<String> teleportServers = List.of(
|
|
||||||
"lobby1",
|
|
||||||
"lobby2"
|
|
||||||
);
|
|
||||||
|
|
||||||
public boolean sendToServer(){
|
public boolean sendToServer(){
|
||||||
return this.sendToServerOnLogin;
|
return this.sendToServerOnLogin;
|
||||||
@ -81,20 +29,9 @@ public class AuthMeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigSerializable
|
|
||||||
public static class Commands{
|
public static class Commands{
|
||||||
@Comment("Sets the commands that users who have not yet logged in can execute")
|
private Set<String> allowedCommands;
|
||||||
private Set<String> allowedCommands = Set.of(
|
private String blockedCommandMessage;
|
||||||
"login",
|
|
||||||
"register",
|
|
||||||
"l",
|
|
||||||
"reg",
|
|
||||||
"email",
|
|
||||||
"captcha"
|
|
||||||
);
|
|
||||||
|
|
||||||
@Comment("Sets the message to send in case a non-logged-in player executes an unauthorized command\nTo deactivate the message, leave it empty")
|
|
||||||
private String blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet";
|
|
||||||
|
|
||||||
public Set<String> getAllowedCommands(){
|
public Set<String> getAllowedCommands(){
|
||||||
return this.allowedCommands;
|
return this.allowedCommands;
|
||||||
@ -104,8 +41,16 @@ public class AuthMeConfig {
|
|||||||
return this.blockedCommandMessage;
|
return this.blockedCommandMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Config config = null;
|
|
||||||
public Config getConfig(){
|
public Commands getCommandsConfig(){
|
||||||
return config;
|
return this.commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerOnLogin getToServerOptions(){
|
||||||
|
return this.serverOnLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAuthServers(){
|
||||||
|
return this.authServers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package com.glyart.authmevelocity.proxy.config;
|
package com.glyart.authmevelocity.proxy.config;
|
||||||
|
|
||||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
public class ConfigUtils {
|
public final class ConfigUtils {
|
||||||
public static void sendBlockedMessage(Player player, Config config){
|
public static void sendBlockedMessage(Player player, AuthMeConfig config){
|
||||||
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
|
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
|
||||||
if(!blockedMessage.isBlank()){
|
if(!blockedMessage.isBlank()){
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
|
@ -25,10 +25,10 @@ public class PluginMessageListener {
|
|||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Random rm;
|
private final Random rm;
|
||||||
private final AuthMeConfig.Config config;
|
private final AuthMeConfig config;
|
||||||
private final AuthmeVelocityAPI api;
|
private final AuthmeVelocityAPI api;
|
||||||
|
|
||||||
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
|
public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.rm = new Random();
|
this.rm = new Random();
|
||||||
@ -52,7 +52,7 @@ public class PluginMessageListener {
|
|||||||
switch(sChannel){
|
switch(sChannel){
|
||||||
case "LOGIN" :
|
case "LOGIN" :
|
||||||
if (api.addPlayer(loggedPlayer)){
|
if (api.addPlayer(loggedPlayer)){
|
||||||
createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection);
|
createServerConnectionRequest(loggedPlayer, proxy, logger, connection);
|
||||||
}
|
}
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
break;
|
break;
|
||||||
@ -71,7 +71,7 @@ public class PluginMessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){
|
private void createServerConnectionRequest(Player loggedPlayer, ProxyServer proxy, Logger logger, ServerConnection connection){
|
||||||
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
|
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
|
||||||
if(config.getToServerOptions().sendToServer()){
|
if(config.getToServerOptions().sendToServer()){
|
||||||
|
@ -16,11 +16,11 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ProxyListener {
|
public final class ProxyListener {
|
||||||
private AuthMeConfig.Config config;
|
private final AuthMeConfig config;
|
||||||
private final AuthmeVelocityAPI api;
|
private final AuthmeVelocityAPI api;
|
||||||
|
|
||||||
public ProxyListener(@NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
|
public ProxyListener(@NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
22
proxy/src/main/resources/config.toml
Normal file
22
proxy/src/main/resources/config.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# AuthmeVelocity Proxy
|
||||||
|
# Original Developer: xQuickGlare
|
||||||
|
# Actual Developer: 4drian3d
|
||||||
|
|
||||||
|
# List of login/registration servers
|
||||||
|
authServers = ["auth1", "auth2"]
|
||||||
|
|
||||||
|
[SendOnLogin]
|
||||||
|
# Send logged in players to another server?
|
||||||
|
sendToServerOnLogin = false
|
||||||
|
|
||||||
|
# List of servers to send
|
||||||
|
# One of these servers will be chosen at random
|
||||||
|
teleportServers = ["lobby1", "lobby2"]
|
||||||
|
|
||||||
|
[Commands]
|
||||||
|
# Sets the commands that users who have not yet logged in can execute
|
||||||
|
allowedCommands = ["login", "register", "l", "reg", "email", "captcha"]
|
||||||
|
|
||||||
|
# Sets the message to send in case a non-logged-in player executes an unauthorized command
|
||||||
|
# To deactivate the message, leave it empty
|
||||||
|
blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet"
|
Loading…
x
Reference in New Issue
Block a user