Compare commits
2 Commits
6ef8f280a8
...
9e7bd21602
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e7bd21602 | |||
| e051d2d6f6 |
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func backUp(cmd string, c GoConfig) {
|
||||
func backUp(cmd string, c UsrConfig) {
|
||||
switch cmd {
|
||||
case "full":
|
||||
fmt.Println("Starting full server backup")
|
||||
|
||||
4
cli.go
4
cli.go
@@ -19,9 +19,7 @@ func cliToolMode() {
|
||||
startStopServer("stop", c)
|
||||
}
|
||||
case "help", "h", "--help", "-h":
|
||||
fmt.Printf("Start Server: %s start\nStop Server: %s stop\n", os.Args[0], os.Args[0])
|
||||
fmt.Printf("Run backup\n\tFull backup: %s backup full", os.Args[0])
|
||||
fmt.Printf("\n\tBackup saves: %s backup saves\n", os.Args[0])
|
||||
fmt.Printf("Start Server: %s start\nStop Server: %s stop\nRun backup\n\tFull backup: %s backup full\n\tBackup saves: %s backup saves\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0])
|
||||
case "download":
|
||||
if len(os.Args) > 2 {
|
||||
switch os.Args[2] {
|
||||
|
||||
24
config.go
24
config.go
@@ -9,14 +9,30 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func readCfg(factCfg string) GoConfig {
|
||||
func DefCfg() *DefConfig {
|
||||
c := &DefConfig{}
|
||||
// server settings
|
||||
c.Server.ServDir = "factorio"
|
||||
c.Server.ServPort = 34197
|
||||
c.Server.ServCfg = "factorio/data/server-settings.json"
|
||||
c.Server.ServExec = "factorio/bin/x64/factorio"
|
||||
c.Server.WorldFile = "factorio/saves/newworld.zip"
|
||||
c.Factoryman.UseScreen = true
|
||||
c.Factoryman.ScreenName = "factorio"
|
||||
c.Factoryman.BackupDir = "factorio/backups"
|
||||
c.Factoryman.UserName = ""
|
||||
c.Factoryman.ApiToken = ""
|
||||
return c
|
||||
}
|
||||
func readCfg(factCfg string) UsrConfig {
|
||||
//read config file (YAML)
|
||||
fileBytes, err := os.ReadFile(factCfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading config file: %v", err)
|
||||
fmt.Printf("Error reading config.yml file, using defaults\n")
|
||||
return UsrConfig(*DefCfg())
|
||||
}
|
||||
// return Struct
|
||||
var config GoConfig
|
||||
var config UsrConfig
|
||||
err = yaml.Unmarshal(fileBytes, &config)
|
||||
if err != nil {
|
||||
log.Fatalf("Error unmarshalling YAML file: %v", err)
|
||||
@@ -32,7 +48,7 @@ func isItReal(path string) bool { //check if path exists
|
||||
return false
|
||||
}
|
||||
}
|
||||
func verifyConfig(config GoConfig) bool { // check each file/dir to see if it exists
|
||||
func verifyConfig(config UsrConfig) bool { // check each file/dir to see if it exists
|
||||
if !isItReal(config.Server.ServDir) { //check for Server directory
|
||||
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
|
||||
return false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
server:
|
||||
serverFolder: "factorio"
|
||||
worldFile: ""
|
||||
worldFile: "factorio/saves/newworld.zip"
|
||||
serverSettings: "factorio/data/server-settings.json"
|
||||
serverExec: "factorio/bin/x64/factorio"
|
||||
port: 34197
|
||||
|
||||
BIN
factoryman
BIN
factoryman
Binary file not shown.
@@ -7,7 +7,7 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func startStopServer(cmd string, con GoConfig) {
|
||||
func startStopServer(cmd string, con UsrConfig) {
|
||||
switch cmd {
|
||||
case "start":
|
||||
x := fmt.Sprintf("%s --port %d --server-settings %s --start-server %s", con.Server.ServExec, con.Server.ServPort, con.Server.ServCfg, con.Server.WorldFile)
|
||||
|
||||
20
structs.go
20
structs.go
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
// config struct
|
||||
type GoConfig struct {
|
||||
type UsrConfig struct {
|
||||
Server struct { // server specific settings
|
||||
ServDir string `yaml:"serverFolder"`
|
||||
WorldFile string `yaml:"worldFile"`
|
||||
@@ -19,6 +19,24 @@ type GoConfig struct {
|
||||
} `yaml:"factoryman"`
|
||||
}
|
||||
|
||||
type DefConfig struct {
|
||||
Server struct { // server specific settings
|
||||
ServDir string
|
||||
WorldFile string
|
||||
ServCfg string
|
||||
ServExec string
|
||||
ServPort int
|
||||
}
|
||||
|
||||
Factoryman struct { // factoryman settings
|
||||
BackupDir string
|
||||
UseScreen bool
|
||||
ScreenName string
|
||||
UserName string
|
||||
ApiToken string
|
||||
}
|
||||
}
|
||||
|
||||
// JSON file from config
|
||||
type Mod struct {
|
||||
Name string `json:"name"`
|
||||
|
||||
Reference in New Issue
Block a user