Read from mod-list.json in mod dir and download each mod in list. This requires reading from factorio mod portal api, and extracting download url and calling it with username and api token. new field in config.yml username and apitoken, is needed to download mod files from mod.factorio.com
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
func startStopServer(cmd string, con GoConfig) {
|
|
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)
|
|
if con.Factoryman.UseScreen { // if screen enabled in config.yml
|
|
fmt.Println("Starting factorio server in screen session")
|
|
startScreenCmd := exec.Command("screen", "-dmS", con.Factoryman.ScreenName, "bash", "-c", x, "; exec sh")
|
|
startScreenCmd.Stdout = os.Stdout
|
|
startScreenCmd.Stderr = os.Stderr
|
|
err := startScreenCmd.Run()
|
|
if err != nil {
|
|
log.Fatalf("Failed to start server: %s", err)
|
|
}
|
|
} else {
|
|
startSrvCmd := exec.Command("bash", "-c", x)
|
|
startSrvCmd.Stdout = os.Stdout
|
|
startSrvCmd.Stderr = os.Stdout
|
|
startSrvCmd.Stdin = os.Stdin
|
|
err := startSrvCmd.Run()
|
|
if err != nil {
|
|
log.Fatalf("Failed to start server: %s", err)
|
|
}
|
|
}
|
|
case "stop":
|
|
quitServerCmd := exec.Command("screen", "-S", con.Factoryman.ScreenName, "-p", "0", "-X", "stuff", "/quit\n")
|
|
err := quitServerCmd.Run()
|
|
if err != nil {
|
|
log.Fatalf("Command failed: %s, Error: %v", quitServerCmd.Args, err)
|
|
} else {
|
|
fmt.Println("Server Stopped")
|
|
}
|
|
}
|
|
}
|