mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-30 22:49:06 +07:00
Allow Custom input handling in servers (#6452)
* enable input redirection * oops
This commit is contained in:
@ -45,6 +45,14 @@ public class ServerControl implements ApplicationListener{
|
||||
public final CommandHandler handler = new CommandHandler("");
|
||||
public final Fi logFolder = Core.settings.getDataDirectory().child("logs/");
|
||||
|
||||
public Runnable serverInput = () -> {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
while(scan.hasNext()){
|
||||
String line = scan.nextLine();
|
||||
Core.app.post(() -> handleCommandString(line));
|
||||
}
|
||||
};
|
||||
|
||||
private Fi currentLogFile;
|
||||
private boolean inExtraRound;
|
||||
private Task lastTask;
|
||||
@ -147,10 +155,6 @@ public class ServerControl implements ApplicationListener{
|
||||
|
||||
customMapDirectory.mkdirs();
|
||||
|
||||
Thread thread = new Thread(this::readCommands, "Server Controls");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
|
||||
if(Version.build == -1){
|
||||
warn("&lyYour server is running a custom build, which means that client checking is disabled.");
|
||||
warn("&lyIt is highly advised to specify which version you're using by building with gradle args &lb&fb-Pbuildversion=&lr<build>");
|
||||
@ -258,7 +262,13 @@ public class ServerControl implements ApplicationListener{
|
||||
|
||||
toggleSocket(Config.socketInput.bool());
|
||||
|
||||
info("Server loaded. Type @ for help.", "'help'");
|
||||
Events.on(ServerLoadEvent.class, e -> {
|
||||
Thread thread = new Thread(serverInput, "Server Controls");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
|
||||
info("Server loaded. Type @ for help.", "'help'");
|
||||
});
|
||||
}
|
||||
|
||||
protected void registerCommands(){
|
||||
@ -963,15 +973,7 @@ public class ServerControl implements ApplicationListener{
|
||||
mods.eachClass(p -> p.registerServerCommands(handler));
|
||||
}
|
||||
|
||||
private void readCommands(){
|
||||
Scanner scan = new Scanner(System.in);
|
||||
while(scan.hasNext()){
|
||||
String line = scan.nextLine();
|
||||
Core.app.post(() -> handleCommandString(line));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCommandString(String line){
|
||||
public void handleCommandString(String line){
|
||||
CommandResponse response = handler.handleMessage(line);
|
||||
|
||||
if(response.type == ResponseType.unknownCommand){
|
||||
|
Reference in New Issue
Block a user