Added BE auto-updater / Server config / Fixed #1266
This commit is contained in:
@@ -40,7 +40,6 @@ import static mindustry.Vars.*;
|
||||
public class ServerControl implements ApplicationListener{
|
||||
private static final int roundExtraTime = 12;
|
||||
private static final int maxLogLength = 1024 * 512;
|
||||
private static final int commandSocketPort = 6859;
|
||||
|
||||
protected static String[] tags = {"&lc&fb[D]", "&lg&fb[I]", "&ly&fb[W]", "&lr&fb[E]", ""};
|
||||
protected static DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("MM-dd-yyyy | HH:mm:ss");
|
||||
@@ -64,10 +63,6 @@ public class ServerControl implements ApplicationListener{
|
||||
"bans", "",
|
||||
"admins", "",
|
||||
"shufflemode", "custom",
|
||||
"crashreport", false,
|
||||
"port", port,
|
||||
"logging", true,
|
||||
"socket", false,
|
||||
"globalrules", "{reactorExplosions: false}"
|
||||
);
|
||||
|
||||
@@ -75,7 +70,7 @@ public class ServerControl implements ApplicationListener{
|
||||
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr", args1);
|
||||
System.out.println(result);
|
||||
|
||||
if(Core.settings.getBool("logging")){
|
||||
if(Config.logging.bool()){
|
||||
logToFile("[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr", false, args1));
|
||||
}
|
||||
|
||||
@@ -158,16 +153,19 @@ public class ServerControl implements ApplicationListener{
|
||||
}
|
||||
});
|
||||
|
||||
Events.on(Trigger.socketConfigChanged, () -> {
|
||||
toggleSocket(false);
|
||||
toggleSocket(Config.socketInput.bool());
|
||||
});
|
||||
|
||||
if(!mods.list().isEmpty()){
|
||||
info("&lc{0} mods loaded.", mods.list().size);
|
||||
}
|
||||
|
||||
toggleSocket(Config.socketInput.bool());
|
||||
|
||||
info("&lcServer loaded. Type &ly'help'&lc for help.");
|
||||
System.out.print("> ");
|
||||
|
||||
if(Core.settings.getBool("socket")){
|
||||
toggleSocket(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands(){
|
||||
@@ -247,21 +245,6 @@ public class ServerControl implements ApplicationListener{
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("port", "[port]", "Sets or displays the port for hosting the server.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("&lyPort: &lc{0}", Core.settings.getInt("port"));
|
||||
}else{
|
||||
int port = Strings.parseInt(arg[0]);
|
||||
if(port < 0 || port > 65535){
|
||||
err("Port must be a number between 0 and 65535.");
|
||||
return;
|
||||
}
|
||||
info("&lyPort set to {0}.", port);
|
||||
Core.settings.put("port", port);
|
||||
Core.settings.save();
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("maps", "Display all available maps.", arg -> {
|
||||
if(!maps.all().isEmpty()){
|
||||
info("Maps:");
|
||||
@@ -440,16 +423,6 @@ public class ServerControl implements ApplicationListener{
|
||||
|
||||
});
|
||||
|
||||
handler.register("name", "[name...]", "Change the server display name.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Server name is currently &lc'{0}'.", Core.settings.getString("servername"));
|
||||
return;
|
||||
}
|
||||
Core.settings.put("servername", arg[0]);
|
||||
Core.settings.save();
|
||||
info("Server name is now &lc'{0}'.", arg[0]);
|
||||
});
|
||||
|
||||
handler.register("playerlimit", "[off/somenumber]", "Set the server player limit.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Player limit is currently &lc{0}.", netServer.admins.getPlayerLimit() == 0 ? "off" : netServer.admins.getPlayerLimit());
|
||||
@@ -470,14 +443,40 @@ public class ServerControl implements ApplicationListener{
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("whitelist", "[on/off...]", "Enable/disable whitelisting.", arg -> {
|
||||
handler.register("config", "[name] [value]", "Configure server settings.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Whitelist is currently &lc{0}.", netServer.admins.isWhitelistEnabled() ? "on" : "off");
|
||||
info("&lyAll config values:");
|
||||
for(Config c : Config.all){
|
||||
Log.info("&ly| &lc{0}:&lm {1}", c.name(), c.get());
|
||||
Log.info("&ly| | {0}", c.description);
|
||||
Log.info("&ly|");
|
||||
}
|
||||
return;
|
||||
}
|
||||
boolean on = arg[0].equalsIgnoreCase("on");
|
||||
netServer.admins.setWhitelist(on);
|
||||
info("Whitelist is now &lc{0}.", on ? "on" : "off");
|
||||
|
||||
try{
|
||||
Config c = Config.valueOf(arg[0]);
|
||||
if(arg.length == 1){
|
||||
Log.info("&lc'{0}'&lg is currently &lc{0}.", c.name(), c.get());
|
||||
}else{
|
||||
if(c.isBool()){
|
||||
c.set(arg[1].equals("on") || arg[1].equals("true"));
|
||||
}else if(c.isNum()){
|
||||
try{
|
||||
c.set(Integer.parseInt(arg[1]));
|
||||
}catch(NumberFormatException e){
|
||||
Log.err("Not a valid number: {0}", arg[1]);
|
||||
return;
|
||||
}
|
||||
}else if(c.isString()){
|
||||
c.set(arg[1]);
|
||||
}
|
||||
|
||||
Log.info("&lc{0}&lg set to &lc{1}.", c.name(), c.get());
|
||||
}
|
||||
}catch(IllegalArgumentException e){
|
||||
err("Unknown config: '{0}'. Run the command with no arguments to get a list of valid configs.", arg[0]);
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("whitelisted", "List the entire whitelist.", arg -> {
|
||||
@@ -512,67 +511,6 @@ public class ServerControl implements ApplicationListener{
|
||||
info("Player &ly'{0}'&lg has been un-whitelisted.", info.lastName);
|
||||
});
|
||||
|
||||
handler.register("sync", "[on/off...]", "Enable/disable block sync. Experimental.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Block sync is currently &lc{0}.", Core.settings.getBool("blocksync") ? "enabled" : "disabled");
|
||||
return;
|
||||
}
|
||||
boolean on = arg[0].equalsIgnoreCase("on");
|
||||
Core.settings.putSave("blocksync", on);
|
||||
info("Block syncing is now &lc{0}.", on ? "on" : "off");
|
||||
});
|
||||
|
||||
handler.register("crashreport", "<on/off>", "Disables or enables automatic crash reporting", arg -> {
|
||||
boolean value = arg[0].equalsIgnoreCase("on");
|
||||
Core.settings.put("crashreport", value);
|
||||
Core.settings.save();
|
||||
info("Crash reporting is now {0}.", value ? "on" : "off");
|
||||
});
|
||||
|
||||
handler.register("logging", "<on/off>", "Disables or enables server logs", arg -> {
|
||||
boolean value = arg[0].equalsIgnoreCase("on");
|
||||
Core.settings.put("logging", value);
|
||||
Core.settings.save();
|
||||
info("Logging is now {0}.", value ? "on" : "off");
|
||||
});
|
||||
|
||||
handler.register("strict", "<on/off>", "Disables or enables strict mode", arg -> {
|
||||
boolean value = arg[0].equalsIgnoreCase("on");
|
||||
netServer.admins.setStrict(value);
|
||||
info("Strict mode is now {0}.", netServer.admins.getStrict() ? "on" : "off");
|
||||
});
|
||||
|
||||
handler.register("socketinput", "[on/off]", "Disables or enables a local TCP socket at port "+commandSocketPort+" to recieve commands from other applications", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Socket input is currently &lc{0}.", Core.settings.getBool("socket") ? "on" : "off");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean value = arg[0].equalsIgnoreCase("on");
|
||||
toggleSocket(value);
|
||||
Core.settings.put("socket", value);
|
||||
Core.settings.save();
|
||||
info("Socket input is now &lc{0}.", value ? "on" : "off");
|
||||
});
|
||||
|
||||
handler.register("allow-custom-clients", "[on/off]", "Allow or disallow custom clients.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Custom clients are currently &lc{0}.", netServer.admins.allowsCustomClients() ? "allowed" : "disallowed");
|
||||
return;
|
||||
}
|
||||
|
||||
String s = arg[0];
|
||||
if(s.equalsIgnoreCase("on")){
|
||||
netServer.admins.setCustomClients(true);
|
||||
info("Custom clients enabled.");
|
||||
}else if(s.equalsIgnoreCase("off")){
|
||||
netServer.admins.setCustomClients(false);
|
||||
info("Custom clients disabled.");
|
||||
}else{
|
||||
err("Incorrect command usage.");
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("shuffle", "[none/all/custom/builtin]", "Set map shuffling mode.", arg -> {
|
||||
if(arg.length == 0){
|
||||
info("Shuffle mode current set to &ly'{0}'&lg.", maps.getShuffleMode());
|
||||
@@ -933,8 +871,8 @@ public class ServerControl implements ApplicationListener{
|
||||
|
||||
private void host(){
|
||||
try{
|
||||
net.host(Core.settings.getInt("port"));
|
||||
info("&lcOpened a server on port {0}.", Core.settings.getInt("port"));
|
||||
net.host(Config.port.num());
|
||||
info("&lcOpened a server on port {0}.", Config.port.num());
|
||||
}catch(BindException e){
|
||||
Log.err("Unable to host: Port already in use! Make sure no other servers are running on the same port in your network.");
|
||||
state.set(State.menu);
|
||||
@@ -968,7 +906,7 @@ public class ServerControl implements ApplicationListener{
|
||||
socketThread = new Thread(() -> {
|
||||
try{
|
||||
serverSocket = new ServerSocket();
|
||||
serverSocket.bind(new InetSocketAddress("localhost", commandSocketPort));
|
||||
serverSocket.bind(new InetSocketAddress(Config.socketInputAddress.string(), Config.socketInputPort.num()));
|
||||
while(true){
|
||||
Socket client = serverSocket.accept();
|
||||
info("&lmRecieved command socket connection: &lb{0}", serverSocket.getLocalSocketAddress());
|
||||
|
||||
Reference in New Issue
Block a user