mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-15 15:20:57 -08: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:
parent
fbdfef625a
commit
ef1413beab
1 changed files with 31 additions and 0 deletions
|
|
@ -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 -> {
|
handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
|
||||||
if(state.isGame()){
|
if(state.isGame()){
|
||||||
err("Already hosting. Type 'stop' to stop hosting first.");
|
err("Already hosting. Type 'stop' to stop hosting first.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue