mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Implemented passing of commands as arguments
This commit is contained in:
parent
e21d92cf4d
commit
d396149521
@ -11,6 +11,11 @@ import io.anuke.ucore.modules.ModuleCore;
|
|||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class MindustryServer extends ModuleCore {
|
public class MindustryServer extends ModuleCore {
|
||||||
|
private String[] args;
|
||||||
|
|
||||||
|
public MindustryServer(String[] args){
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
@ -23,6 +28,6 @@ public class MindustryServer extends ModuleCore {
|
|||||||
module(world = new World());
|
module(world = new World());
|
||||||
module(netServer = new NetServer());
|
module(netServer = new NetServer());
|
||||||
module(netCommon = new NetCommon());
|
module(netCommon = new NetCommon());
|
||||||
module(new ServerControl());
|
module(new ServerControl(args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ServerControl extends Module {
|
|||||||
private final CommandHandler handler = new CommandHandler("");
|
private final CommandHandler handler = new CommandHandler("");
|
||||||
private ShuffleMode mode;
|
private ShuffleMode mode;
|
||||||
|
|
||||||
public ServerControl(){
|
public ServerControl(String[] args){
|
||||||
Settings.defaultList(
|
Settings.defaultList(
|
||||||
"shufflemode", "normal",
|
"shufflemode", "normal",
|
||||||
"bans", "",
|
"bans", "",
|
||||||
@ -69,7 +69,24 @@ public class ServerControl extends Module {
|
|||||||
@Override public void debug(String tag, String message, Throwable exception) { }
|
@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();
|
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<command-1> <command1-args...>,<command-2> <command-2-args2...>");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Thread thread = new Thread(this::readCommands, "Server Controls");
|
Thread thread = new Thread(this::readCommands, "Server Controls");
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
@ -7,12 +7,12 @@ import io.anuke.mindustry.net.Net;
|
|||||||
|
|
||||||
public class ServerLauncher{
|
public class ServerLauncher{
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args){
|
||||||
|
|
||||||
Net.setClientProvider(new KryoClient());
|
Net.setClientProvider(new KryoClient());
|
||||||
Net.setServerProvider(new KryoServer());
|
Net.setServerProvider(new KryoServer());
|
||||||
|
|
||||||
new HeadlessApplication(new MindustryServer());
|
new HeadlessApplication(new MindustryServer(args));
|
||||||
|
|
||||||
//find and handle uncaught exceptions in libGDX thread
|
//find and handle uncaught exceptions in libGDX thread
|
||||||
for(Thread thread : Thread.getAllStackTraces().keySet()){
|
for(Thread thread : Thread.getAllStackTraces().keySet()){
|
||||||
@ -24,6 +24,5 @@ public class ServerLauncher{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user