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 CommandHandler handler = new CommandHandler("");
|
||||||
public final Fi logFolder = Core.settings.getDataDirectory().child("logs/");
|
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 Fi currentLogFile;
|
||||||
private boolean inExtraRound;
|
private boolean inExtraRound;
|
||||||
private Task lastTask;
|
private Task lastTask;
|
||||||
@@ -147,10 +155,6 @@ public class ServerControl implements ApplicationListener{
|
|||||||
|
|
||||||
customMapDirectory.mkdirs();
|
customMapDirectory.mkdirs();
|
||||||
|
|
||||||
Thread thread = new Thread(this::readCommands, "Server Controls");
|
|
||||||
thread.setDaemon(true);
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
if(Version.build == -1){
|
if(Version.build == -1){
|
||||||
warn("&lyYour server is running a custom build, which means that client checking is disabled.");
|
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>");
|
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());
|
toggleSocket(Config.socketInput.bool());
|
||||||
|
|
||||||
|
Events.on(ServerLoadEvent.class, e -> {
|
||||||
|
Thread thread = new Thread(serverInput, "Server Controls");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
|
|
||||||
info("Server loaded. Type @ for help.", "'help'");
|
info("Server loaded. Type @ for help.", "'help'");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerCommands(){
|
protected void registerCommands(){
|
||||||
@@ -963,15 +973,7 @@ public class ServerControl implements ApplicationListener{
|
|||||||
mods.eachClass(p -> p.registerServerCommands(handler));
|
mods.eachClass(p -> p.registerServerCommands(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCommands(){
|
public void handleCommandString(String line){
|
||||||
Scanner scan = new Scanner(System.in);
|
|
||||||
while(scan.hasNext()){
|
|
||||||
String line = scan.nextLine();
|
|
||||||
Core.app.post(() -> handleCommandString(line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleCommandString(String line){
|
|
||||||
CommandResponse response = handler.handleMessage(line);
|
CommandResponse response = handler.handleMessage(line);
|
||||||
|
|
||||||
if(response.type == ResponseType.unknownCommand){
|
if(response.type == ResponseType.unknownCommand){
|
||||||
|
|||||||
Reference in New Issue
Block a user