Compare commits

..

2 Commits

Author SHA1 Message Date
7aa0793075 Merge pull request 'Added README' (#2) from develop into main
Reviewed-on: #2
2026-05-04 16:05:49 +00:00
783008bfb6 Merge pull request 'Added Mod and server downloader' (#1) from develop into main
Reviewed-on: #1
2026-05-04 13:47:15 +00:00
7 changed files with 11 additions and 43 deletions

View File

@@ -7,7 +7,7 @@ import (
"time" "time"
) )
func backUp(cmd string, c UsrConfig) { func backUp(cmd string, c GoConfig) {
switch cmd { switch cmd {
case "full": case "full":
fmt.Println("Starting full server backup") fmt.Println("Starting full server backup")

4
cli.go
View File

@@ -19,7 +19,9 @@ func cliToolMode() {
startStopServer("stop", c) startStopServer("stop", c)
} }
case "help", "h", "--help", "-h": case "help", "h", "--help", "-h":
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]) 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])
case "download": case "download":
if len(os.Args) > 2 { if len(os.Args) > 2 {
switch os.Args[2] { switch os.Args[2] {

View File

@@ -9,30 +9,14 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
func DefCfg() *DefConfig { func readCfg(factCfg string) GoConfig {
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) //read config file (YAML)
fileBytes, err := os.ReadFile(factCfg) fileBytes, err := os.ReadFile(factCfg)
if err != nil { if err != nil {
fmt.Printf("Error reading config.yml file, using defaults\n") log.Fatalf("Error reading config file: %v", err)
return UsrConfig(*DefCfg())
} }
// return Struct // return Struct
var config UsrConfig var config GoConfig
err = yaml.Unmarshal(fileBytes, &config) err = yaml.Unmarshal(fileBytes, &config)
if err != nil { if err != nil {
log.Fatalf("Error unmarshalling YAML file: %v", err) log.Fatalf("Error unmarshalling YAML file: %v", err)
@@ -48,7 +32,7 @@ func isItReal(path string) bool { //check if path exists
return false return false
} }
} }
func verifyConfig(config UsrConfig) bool { // check each file/dir to see if it exists func verifyConfig(config GoConfig) bool { // check each file/dir to see if it exists
if !isItReal(config.Server.ServDir) { //check for Server directory if !isItReal(config.Server.ServDir) { //check for Server directory
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir) fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
return false return false

View File

@@ -1,6 +1,6 @@
server: server:
serverFolder: "factorio" serverFolder: "factorio"
worldFile: "factorio/saves/newworld.zip" worldFile: ""
serverSettings: "factorio/data/server-settings.json" serverSettings: "factorio/data/server-settings.json"
serverExec: "factorio/bin/x64/factorio" serverExec: "factorio/bin/x64/factorio"
port: 34197 port: 34197

Binary file not shown.

View File

@@ -7,7 +7,7 @@ import (
"os/exec" "os/exec"
) )
func startStopServer(cmd string, con UsrConfig) { 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.Server.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)

View File

@@ -1,7 +1,7 @@
package main package main
// config struct // config struct
type UsrConfig struct { type GoConfig struct {
Server struct { // server specific settings Server struct { // server specific settings
ServDir string `yaml:"serverFolder"` ServDir string `yaml:"serverFolder"`
WorldFile string `yaml:"worldFile"` WorldFile string `yaml:"worldFile"`
@@ -19,24 +19,6 @@ type UsrConfig struct {
} `yaml:"factoryman"` } `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 // JSON file from config
type Mod struct { type Mod struct {
Name string `json:"name"` Name string `json:"name"`