Fix issues with config handling
This commit is contained in:
10
config.go
10
config.go
@@ -12,15 +12,15 @@ import (
|
|||||||
const fmConfig = "config.yml"
|
const fmConfig = "config.yml"
|
||||||
|
|
||||||
type GoConfig struct {
|
type GoConfig struct {
|
||||||
Server struct {
|
Server struct { // server specific settings
|
||||||
ServDir string `yaml:"serverFolder"`
|
ServDir string `yaml:"serverFolder"`
|
||||||
WorldFile string `yaml:"worldFile"`
|
WorldFile string `yaml:"worldFile"`
|
||||||
ServCfg string `yaml:"serverSettings"`
|
ServCfg string `yaml:"serverSettings"`
|
||||||
ServExec string `yaml:"serverExec"`
|
ServExec string `yaml:"serverExec"`
|
||||||
|
ServPort int `yaml:"port"`
|
||||||
} `yaml:"server"`
|
} `yaml:"server"`
|
||||||
|
|
||||||
Factoryman struct {
|
Factoryman struct { // factoryman settings
|
||||||
ServPort int `yaml:"port"`
|
|
||||||
BackupDir string `yaml:"backupDir"`
|
BackupDir string `yaml:"backupDir"`
|
||||||
UseScreen bool `yaml:"screen"`
|
UseScreen bool `yaml:"screen"`
|
||||||
ScreenName string `yaml:"screenName"`
|
ScreenName string `yaml:"screenName"`
|
||||||
@@ -41,7 +41,7 @@ func readCfg(factCfg string) GoConfig {
|
|||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
func isItReal(path string) bool {
|
func isItReal(path string) bool { //check if path exists
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
return true
|
return true
|
||||||
} else if errors.Is(err, os.ErrNotExist) {
|
} else if errors.Is(err, os.ErrNotExist) {
|
||||||
@@ -50,7 +50,7 @@ func isItReal(path string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func verifyConfig(config GoConfig) bool {
|
func verifyConfig(config GoConfig) bool { // check each file/dir to see if it exists
|
||||||
if !isItReal(config.Server.ServDir) {
|
if !isItReal(config.Server.ServDir) {
|
||||||
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
|
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ server:
|
|||||||
worldFile: "factorio/data/saves/newworld.zip"
|
worldFile: "factorio/data/saves/newworld.zip"
|
||||||
serverSettings: "factorio/data/server-settings.json"
|
serverSettings: "factorio/data/server-settings.json"
|
||||||
serverExec: "factorio/bin/x64/factorio"
|
serverExec: "factorio/bin/x64/factorio"
|
||||||
|
port: 34197
|
||||||
|
|
||||||
factoryman:
|
factoryman:
|
||||||
port: 34197
|
|
||||||
screen: True
|
screen: True
|
||||||
screenName: "Factorio"
|
screenName: "Factorio"
|
||||||
backupDir: "factorio/backups"
|
backupDir: "factorio/backups"
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
func startStopServer(cmd string, con GoConfig) {
|
func startStopServer(cmd string, con GoConfig) {
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "start":
|
case "start":
|
||||||
x := fmt.Sprintf("%s --port %d --server-settings %s --start-server %s", con.Server.ServExec, con.Factoryman.ServPort, con.Server.ServCfg, con.Server.WorldFile)
|
x := fmt.Sprintf("%s --port %d --server-settings %s --start-server %s", con.Server.ServExec, con.Server.ServPort, con.Server.ServCfg, con.Server.WorldFile)
|
||||||
if con.Factoryman.UseScreen { // if screen enabled in confing.yml
|
if con.Factoryman.UseScreen { // if screen enabled in confing.yml
|
||||||
fmt.Println("Starting factorio server in screen session")
|
fmt.Println("Starting factorio server in screen session")
|
||||||
startScreenCmd := exec.Command("screen", "-dmS", con.Factoryman.ScreenName, "bash", "-c", x, "; exec sh")
|
startScreenCmd := exec.Command("screen", "-dmS", con.Factoryman.ScreenName, "bash", "-c", x, "; exec sh")
|
||||||
|
|||||||
Reference in New Issue
Block a user