Added path checks and updated config

- Cleaned up func main()
- Separated config into two sections server and factoryman
- Updated backup.go to reflect changes to config file
- Updated config.go to reflect changes to config.yml as well as added a check to paths in config.yml
- Updated launch.go to reflect changes to config
move cli handler from main to cli.go
This commit is contained in:
2026-04-29 11:39:55 -06:00
parent bdf636b0d3
commit aef97fe613
7 changed files with 103 additions and 53 deletions

View File

@@ -1,6 +1,8 @@
package main
import (
"errors"
"fmt"
"log"
"os"
@@ -10,16 +12,19 @@ import (
const fmConfig = "config.yml"
type GoConfig struct {
Config struct {
ServDir string `yaml:"serverFolder"`
Server struct {
ServDir string `yaml:"serverFolder"`
WorldFile string `yaml:"worldFile"`
ServCfg string `yaml:"serverSettings"`
ServExec string `yaml:"serverExec"`
} `yaml:"server"`
Factoryman struct {
ServPort int `yaml:"port"`
WorldFile string `yaml:"worldFile"`
ServCfg string `yaml:"serverSettings"`
ServExec string `yaml:"serverExec"`
BackupDir string `yaml:"backupDir"`
UseScreen bool `yaml:"screen"`
ScreenName string `yaml:"screenName"`
} `yaml:"server"`
} `yaml:"factoryman"`
}
func readCfg(factCfg string) GoConfig {
@@ -36,3 +41,36 @@ func readCfg(factCfg string) GoConfig {
}
return config
}
func isItReal(path string) bool {
if _, err := os.Stat(path); err == nil {
return true
} else if errors.Is(err, os.ErrNotExist) {
return false
} else {
return false
}
}
func verifyConfig(config GoConfig) bool {
if !isItReal(config.Server.ServDir) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
return false
}
if !isItReal(config.Server.WorldFile) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.WorldFile)
return false
}
if !isItReal(config.Server.ServCfg) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServCfg)
return false
}
if !isItReal(config.Server.ServExec) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServExec)
return false
}
if !isItReal(config.Factoryman.BackupDir) {
fmt.Printf("PATH NOT FOUND: %s", config.Factoryman.BackupDir)
return false
}
return true
}