Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/factorio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ func initFactorio() (f *FactorioServer, err error) {

f.BaseModVersion = modInfo.Version

// load admins from additional file
if(f.Version.Greater(Version{0,17,0})) {
if _, err := os.Stat(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile)); os.IsNotExist(err) {
//save empty admins-file
ioutil.WriteFile(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile), []byte("[]"), 0664)
} else {
data, err := ioutil.ReadFile(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile))
if err != nil {
log.Printf("Error loading FactorioAdminFile: %s", err)
return f, err
}

var jsonData interface{}
err = json.Unmarshal(data, &jsonData)
if err != nil {
log.Printf("Error unmarshalling FactorioAdminFile: %s", err)
return f, err
}

f.Settings["admins"] = jsonData
}
}

return
}

Expand All @@ -143,11 +166,15 @@ func (f *FactorioServer) Run() error {
args := []string{
"--bind", (f.BindIP),
"--port", strconv.Itoa(f.Port),
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
"--server-settings", filepath.Join(config.FactorioConfigDir, config.SettingsFile),
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
"--rcon-password", config.FactorioRconPass,
}

if(f.Version.Greater(Version{0,17,0})) {
args = append(args, "--server-adminlist", filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile))
}

if f.Savefile == "Load Latest" {
args = append(args, "--start-server-load-latest")
} else {
Expand Down
14 changes: 14 additions & 0 deletions src/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,20 @@ func UpdateServerSettings(w http.ResponseWriter, r *http.Request) {
log.Printf("Saved Factorio server settings in server-settings.json")
}

if(FactorioServ.Version.Greater(Version{0,17,0})) {
// save admins to adminJson
admins, err := json.MarshalIndent(FactorioServ.Settings["admins"], "", " ")
if err != nil {
log.Printf("Failed to marshal admins-Setting: %s", err)
return
}
err = ioutil.WriteFile(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile), admins, 0664)
if err != nil {
log.Printf("Failed to save admins: %s", err)
return
}
}

resp.Success = true
resp.Data = fmt.Sprintf("Settings successfully saved")
if err := json.NewEncoder(w).Encode(resp); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
FactorioRconPass string `json:"rcon_pass"`
FactorioCredentialsFile string `json:"factorio_credentials_file"`
FactorioIP string `json:"factorio_ip"`
FactorioAdminFile string `json:"-"`
ServerIP string `json:"server_ip"`
ServerPort string `json:"server_port"`
MaxUploadSize int64 `json:"max_upload_size"`
Expand Down Expand Up @@ -87,6 +88,7 @@ func parseFlags() {
config.FactorioConfigFile = filepath.Join(config.FactorioDir, *factorioConfigFile)
config.FactorioBinary = filepath.Join(config.FactorioDir, *factorioBinary)
config.FactorioCredentialsFile = "./factorio.auth"
config.FactorioAdminFile = "server-adminlist.json"
config.MaxUploadSize = *factorioMaxUpload

if runtime.GOOS == "windows" {
Expand Down