Merge pull request #242 from OpenFactorioServerManager/no-existing-save

Display error if server started without save created
This commit is contained in:
knoxfighter 2021-01-31 05:10:17 +01:00 committed by GitHub
commit 29fe0650d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package factorio
import (
"bufio"
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
@ -229,6 +230,15 @@ func (server *Server) Run() error {
ioutil.WriteFile(config.SettingsFile, data, 0644)
}
saves, err := ListSaves(config.FactorioSavesDir)
if err != nil {
log.Println("Failed to get saves list: ", err)
}
if len(saves) == 0 {
return errors.New("No savefile exists on the server")
}
args := []string{}
//The factorio server refenences its executable-path, since we execute the ld.so file and pass the factorio binary as a parameter

View File

@ -17,6 +17,10 @@ const Controls = ({serverStatus, updateServerStatus}) => {
const { handleSubmit, register, errors } = useForm();
const startServer = async (data) => {
if(saves.length === 1 && saves[0].name === "Load Latest") {
window.flash("Save must be created before starting server", "red");
return;
}
await server.start(data.ip, parseInt(data.port), data.save);
await updateServerStatus();
}