1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-10-06 04:47:14 +03:00

Add "loadautosave" server command. (#9169)

* Add "loadautosave" server command.

A command that loads the last auto-save. This command can be placed inside `config startcommands` to automatically load the last save when the server starts.

* autosaves config is actually autosave. use first() not get(0)

* Get most recent autosave w/o sorting

* Remove left over debug

oops....
This commit is contained in:
Atomic-Laboratory 2023-10-14 22:18:13 -04:00 committed by GitHub
parent fbdfef625a
commit ef1413beab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -910,6 +910,37 @@ public class ServerControl implements ApplicationListener{
}
});
handler.register("loadautosave", "Loads the last auto-save.", arg -> {
if(state.isGame()){
err("Already hosting. Type 'stop' to stop hosting first.");
return;
}
Fi newestSave = saveDirectory.findAll(f -> f.name().startsWith("auto_")).min(Fi::lastModified);
if(newestSave == null){
err("No auto-saves found! Type `config autosave true` to enable auto-saves.");
return;
}
if(!SaveIO.isSaveValid(newestSave)){
err("No (valid) save data found for slot.");
return;
}
Core.app.post(() -> {
try{
SaveIO.load(newestSave);
state.rules.sector = null;
info("Save loaded.");
state.set(State.playing);
netServer.openServer();
}catch(Throwable t){
err("Failed to load save. Outdated or corrupt file.");
}
});
});
handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
if(state.isGame()){
err("Already hosting. Type 'stop' to stop hosting first.");