From d396149521f6a488c02b8e5d63e78a8299fe3ea9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 16 Apr 2018 20:28:47 -0400 Subject: [PATCH] Implemented passing of commands as arguments --- .../mindustry/server/MindustryServer.java | 7 ++++++- .../anuke/mindustry/server/ServerControl.java | 19 ++++++++++++++++++- .../mindustry/server/ServerLauncher.java | 5 ++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/server/src/io/anuke/mindustry/server/MindustryServer.java b/server/src/io/anuke/mindustry/server/MindustryServer.java index 8ab8e82e0c..945683f14a 100644 --- a/server/src/io/anuke/mindustry/server/MindustryServer.java +++ b/server/src/io/anuke/mindustry/server/MindustryServer.java @@ -11,6 +11,11 @@ import io.anuke.ucore.modules.ModuleCore; import static io.anuke.mindustry.Vars.*; public class MindustryServer extends ModuleCore { + private String[] args; + + public MindustryServer(String[] args){ + this.args = args; + } @Override public void init(){ @@ -23,6 +28,6 @@ public class MindustryServer extends ModuleCore { module(world = new World()); module(netServer = new NetServer()); module(netCommon = new NetCommon()); - module(new ServerControl()); + module(new ServerControl(args)); } } diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index e93565c507..afb2e32963 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -41,7 +41,7 @@ public class ServerControl extends Module { private final CommandHandler handler = new CommandHandler(""); private ShuffleMode mode; - public ServerControl(){ + public ServerControl(String[] args){ Settings.defaultList( "shufflemode", "normal", "bans", "", @@ -69,7 +69,24 @@ public class ServerControl extends Module { @Override public void debug(String tag, String message, Throwable exception) { } }); + String[] commands = {}; + + if(args.length > 0){ + commands = String.join(" ", args).split(","); + Log.info("&lmFound {0} command-line arguments to parse. {1}", commands.length); + } + registerCommands(); + + for(String s : commands){ + Response response = handler.handleMessage(s); + if(response.type != ResponseType.valid){ + Log.err("Invalid command argument sent: '{0}': {1}", s, response.type.name()); + Log.err("Argument usage: &lc , "); + System.exit(1); + } + } + Thread thread = new Thread(this::readCommands, "Server Controls"); thread.setDaemon(true); thread.start(); diff --git a/server/src/io/anuke/mindustry/server/ServerLauncher.java b/server/src/io/anuke/mindustry/server/ServerLauncher.java index 16a7e9ea0c..1abd040a47 100644 --- a/server/src/io/anuke/mindustry/server/ServerLauncher.java +++ b/server/src/io/anuke/mindustry/server/ServerLauncher.java @@ -7,12 +7,12 @@ import io.anuke.mindustry.net.Net; public class ServerLauncher{ - public static void main(String[] args) throws Exception{ + public static void main(String[] args){ Net.setClientProvider(new KryoClient()); Net.setServerProvider(new KryoServer()); - new HeadlessApplication(new MindustryServer()); + new HeadlessApplication(new MindustryServer(args)); //find and handle uncaught exceptions in libGDX thread for(Thread thread : Thread.getAllStackTraces().keySet()){ @@ -24,6 +24,5 @@ public class ServerLauncher{ break; } } - } } \ No newline at end of file