diff --git a/bootstrap/bukkit/src/main/java/org/dragonet/proxy/init/bukkit/ProxyBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/dragonet/proxy/init/bukkit/ProxyBukkitPlugin.java index b4547e71f..c22e2572d 100644 --- a/bootstrap/bukkit/src/main/java/org/dragonet/proxy/init/bukkit/ProxyBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/dragonet/proxy/init/bukkit/ProxyBukkitPlugin.java @@ -36,7 +36,7 @@ public void onEnable() { getDataFolder().mkdir(); // Initialize the main proxy class - proxy = new DragonProxy(PlatformType.BUKKIT, getDataFolder(), -1); + proxy = new DragonProxy(PlatformType.BUKKIT, getDataFolder()); } @Override diff --git a/bootstrap/standalone/src/main/java/org/dragonet/proxy/init/Bootstrap.java b/bootstrap/standalone/src/main/java/org/dragonet/proxy/init/Bootstrap.java index 32ada1fa4..258f04a22 100644 --- a/bootstrap/standalone/src/main/java/org/dragonet/proxy/init/Bootstrap.java +++ b/bootstrap/standalone/src/main/java/org/dragonet/proxy/init/Bootstrap.java @@ -43,6 +43,8 @@ public static void main(String[] args) { OptionParser optionParser = new OptionParser(); optionParser.accepts("version", "Displays the proxy version"); OptionSpec bedrockPortOption = optionParser.accepts("bedrockPort", "Overrides the bedrock UDP bind port").withRequiredArg(); + OptionSpec remoteAddressOption = optionParser.accepts("remoteAddress", "Overrides the remote address in the config").withRequiredArg(); + OptionSpec remotePortOption = optionParser.accepts("remotePort", "Overrides the remote port in the config").withRequiredArg(); optionParser.accepts("help", "Display help/usage information").forHelp(); // Handle command-line options @@ -53,8 +55,10 @@ public static void main(String[] args) { } int bedrockPort = options.has(bedrockPortOption) ? Integer.parseInt(options.valueOf(bedrockPortOption)) : -1; + String remoteAddress = options.has(remoteAddressOption) ? options.valueOf(remoteAddressOption) : null; + int remotePort = options.has(remotePortOption) ? Integer.parseInt(options.valueOf(remotePortOption)) : -1; - DragonProxy proxy = new DragonProxy(PlatformType.STANDALONE, new File("."), bedrockPort); + DragonProxy proxy = new DragonProxy(PlatformType.STANDALONE, new File("."), bedrockPort, remoteAddress, remotePort); Runtime.getRuntime().addShutdownHook(new Thread(proxy::shutdown, "Shutdown thread")); } diff --git a/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java b/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java index ecec88a3a..b90ff75c8 100644 --- a/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java +++ b/proxy/src/main/java/org/dragonet/proxy/DragonProxy.java @@ -103,11 +103,22 @@ public class DragonProxy { private long startTime; private int bindPort; + private String remoteAddress; + private int remotePort; + @Getter private File dataFolder; @Getter private PlatformType platformType; + /** + * Constructs a new instance of the DragonProxy class. + * This is the main class for the proxy (although the command line option parsing is in the `bootstrap` module) + */ + public DragonProxy(PlatformType type, File dataPath) { + this(type, dataPath, -1, null, -1); + } + /** * Constructs a new instance of the DragonProxy class. * This is the main class for the proxy (although the command line option parsing is in the `bootstrap` module) @@ -115,13 +126,15 @@ public class DragonProxy { * @param bedrockPort a custom port provided from a command line option * to override the bind port in the config */ - public DragonProxy(PlatformType type, File dataPath, int bedrockPort) { + public DragonProxy(PlatformType type, File dataPath, int bedrockPort, String remoteAddress, int remotePort) { INSTANCE = this; startTime = System.currentTimeMillis(); platformType = type; dataFolder = dataPath; bindPort = bedrockPort; + this.remoteAddress = remoteAddress; + this.remotePort = remotePort; log.info("Welcome to DragonProxy version " + getVersion()); @@ -162,6 +175,8 @@ private void initialize() throws IOException { return; } + handleConfigOverrides(); + if(!RELEASE) { log.warn("This is a development build. It may contain bugs. Do not use in production."); } @@ -223,6 +238,18 @@ private void initialize() throws IOException { } } + private void handleConfigOverrides() { + if(bindPort != -1) { + configuration.setBindPort(bindPort); + } + if(remoteAddress != null) { + configuration.setRemoteAddress(remoteAddress); + } + if(remotePort != -1) { + configuration.setRemotePort(remotePort); + } + } + public void shutdown() { if (!shutdownInProgress.compareAndSet(false, true)) { return; diff --git a/proxy/src/main/java/org/dragonet/proxy/configuration/DragonConfiguration.java b/proxy/src/main/java/org/dragonet/proxy/configuration/DragonConfiguration.java index fbeea146b..b93049ee5 100644 --- a/proxy/src/main/java/org/dragonet/proxy/configuration/DragonConfiguration.java +++ b/proxy/src/main/java/org/dragonet/proxy/configuration/DragonConfiguration.java @@ -25,6 +25,7 @@ import org.dragonet.proxy.remote.RemoteAuthType; @Getter +@Setter @JsonIgnoreProperties(ignoreUnknown = true) public class DragonConfiguration { @JsonProperty("config-version")