mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-28 05:36:33 +02:00
changed package to read flags and fixed tests
This commit is contained in:
parent
ad477db424
commit
7126b62fe5
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mroote/factorio-server-manager/bootstrap"
|
||||
"github.com/mroote/factorio-server-manager/factorio"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
@ -19,20 +20,22 @@ import (
|
||||
func SetupModPacks(t *testing.T, empty bool, emptyMods bool) {
|
||||
var err error
|
||||
|
||||
config := bootstrap.GetConfig()
|
||||
|
||||
// check if dev directory exists and create it
|
||||
if _, err = os.Stat("dev_packs"); os.IsNotExist(err) {
|
||||
err = os.Mkdir("dev_packs", 0775)
|
||||
if _, err = os.Stat(config.FactorioModPackDir); os.IsNotExist(err) {
|
||||
err = os.Mkdir(config.FactorioModPackDir, 0775)
|
||||
}
|
||||
assert.NoError(t, err, `Error creating "dev_packs" directory`)
|
||||
assert.NoError(t, err, `Error creating %s directory`, config.FactorioModPackDir)
|
||||
|
||||
if !empty {
|
||||
// check if dev directory exists and create it
|
||||
if _, err = os.Stat("dev_packs/test"); os.IsNotExist(err) {
|
||||
err = os.Mkdir("dev_packs/test", 0775)
|
||||
if _, err = os.Stat(config.FactorioModPackDir + "/test"); os.IsNotExist(err) {
|
||||
err = os.Mkdir(config.FactorioModPackDir+"/test", 0775)
|
||||
}
|
||||
assert.NoError(t, err, `Error creating "dev_packs/test" directory`)
|
||||
assert.NoError(t, err, `Error creating "%s/test" directory`, config.FactorioModPackDir)
|
||||
|
||||
modList, err := factorio.NewMods("dev_packs/test")
|
||||
modList, err := factorio.NewMods(config.FactorioModPackDir + "/test")
|
||||
assert.NoError(t, err, "error creating mods")
|
||||
|
||||
if !emptyMods {
|
||||
@ -46,8 +49,9 @@ func SetupModPacks(t *testing.T, empty bool, emptyMods bool) {
|
||||
}
|
||||
|
||||
func CleanupModPacks(t *testing.T) {
|
||||
err := os.RemoveAll("dev_packs")
|
||||
assert.NoError(t, err, `Error removing directory "dev_packs"`)
|
||||
config := bootstrap.GetConfig()
|
||||
err := os.RemoveAll(config.FactorioModPackDir)
|
||||
assert.NoError(t, err, `Error removing directory %s`, config.FactorioModPackDir)
|
||||
}
|
||||
|
||||
func UnknownModpackTest(t *testing.T, method string, baseRoute string, route string, handlerFunc http.HandlerFunc) {
|
||||
@ -173,6 +177,7 @@ func TestModPackLoadHandler(t *testing.T) {
|
||||
handlerFunc := ModPackLoadHandler
|
||||
|
||||
t.Run("load mods", func(t *testing.T) {
|
||||
config := bootstrap.GetConfig()
|
||||
SetupModPacks(t, false, false)
|
||||
defer CleanupModPacks(t)
|
||||
SetupMods(t, true)
|
||||
@ -186,7 +191,7 @@ func TestModPackLoadHandler(t *testing.T) {
|
||||
packMap, err := factorio.NewModPackMap()
|
||||
assert.NoError(t, err, "Error creating modPackMap")
|
||||
|
||||
modList, err := factorio.NewMods("dev")
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
assert.NoError(t, err, "Error creating mods object")
|
||||
|
||||
packModsJson, err := json.Marshal(packMap["test"].Mods)
|
||||
@ -204,7 +209,7 @@ func TestModPackLoadHandler(t *testing.T) {
|
||||
SetupMods(t, false)
|
||||
defer CleanupMods(t)
|
||||
|
||||
expected := `{"mods":null}`
|
||||
expected := `{"mods":[]}`
|
||||
|
||||
CallRoute(t, method, baseRoute, route, nil, handlerFunc, http.StatusOK, expected)
|
||||
|
||||
@ -212,7 +217,9 @@ func TestModPackLoadHandler(t *testing.T) {
|
||||
packMap, err := factorio.NewModPackMap()
|
||||
assert.NoError(t, err, "Error creating modPackMap")
|
||||
|
||||
modList, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
assert.NoError(t, err, "Error creating mods object")
|
||||
|
||||
packModsJson, err := json.Marshal(packMap["test"].Mods)
|
||||
@ -517,7 +524,7 @@ func TestModPackModUploadHandler(t *testing.T) {
|
||||
SetupModPacks(t, false, true)
|
||||
defer CleanupModPacks(t)
|
||||
|
||||
recorder := ModPackModUploadRequest(t, true, "factorio_testfiles/belt-balancer_2.1.3.zip")
|
||||
recorder := ModPackModUploadRequest(t, true, "../factorio_testfiles/belt-balancer_2.1.3.zip")
|
||||
|
||||
// status has to be 200
|
||||
if recorder.Code != http.StatusOK {
|
||||
@ -564,7 +571,7 @@ func TestModPackModUploadHandler(t *testing.T) {
|
||||
SetupModPacks(t, false, true)
|
||||
defer CleanupModPacks(t)
|
||||
|
||||
recorder := ModPackModUploadRequest(t, false, "factorio_testfiles/file_usage.txt")
|
||||
recorder := ModPackModUploadRequest(t, false, "../factorio_testfiles/file_usage.txt")
|
||||
assert.Equal(t, http.StatusBadRequest, recorder.Code, "wrong response code.")
|
||||
})
|
||||
|
||||
@ -572,7 +579,7 @@ func TestModPackModUploadHandler(t *testing.T) {
|
||||
SetupModPacks(t, false, true)
|
||||
defer CleanupModPacks(t)
|
||||
|
||||
recorder := ModPackModUploadRequest(t, true, "factorio_testfiles/invalid_mod.zip")
|
||||
recorder := ModPackModUploadRequest(t, true, "../factorio_testfiles/invalid_mod.zip")
|
||||
assert.Equal(t, http.StatusInternalServerError, recorder.Code, "wrong response code.")
|
||||
})
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ func TestMain(m *testing.M) {
|
||||
var err error
|
||||
|
||||
// basic setup stuff
|
||||
bootstrap.SetFlags(bootstrap.Flags{
|
||||
|
||||
config := bootstrap.NewConfig([]string{
|
||||
"--dir", os.Getenv("dir"),
|
||||
"--conf", os.Getenv("conf"),
|
||||
"--mod-pack-dir", "dev_packs",
|
||||
})
|
||||
|
||||
config := bootstrap.GetConfig()
|
||||
config.FactorioModsDir = "dev"
|
||||
config.FactorioModPackDir = "dev_packs"
|
||||
//config.FactorioModPackDir = "dev_packs"
|
||||
FactorioServ := new(factorio.Server)
|
||||
FactorioServ.Version = factorio.Version{1, 0, 0, 0}
|
||||
FactorioServ.BaseModVersion = "1.0.0"
|
||||
@ -61,9 +61,11 @@ func CheckShort(t *testing.T) {
|
||||
func SetupMods(t *testing.T, empty bool) {
|
||||
var err error
|
||||
|
||||
config := bootstrap.GetConfig()
|
||||
|
||||
// check if dev directory exists and create it
|
||||
if _, err = os.Stat("dev"); os.IsNotExist(err) {
|
||||
err = os.Mkdir("dev", 0775)
|
||||
if _, err = os.Stat(config.FactorioModsDir); os.IsNotExist(err) {
|
||||
err = os.Mkdir(config.FactorioModsDir, 0775)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf(`Error creating "dev" directory: %s`, err)
|
||||
@ -89,7 +91,8 @@ func SetupMods(t *testing.T, empty bool) {
|
||||
}
|
||||
|
||||
func CleanupMods(t *testing.T) {
|
||||
err := os.RemoveAll("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
err := os.RemoveAll(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error removing dev directory: %s", err)
|
||||
}
|
||||
@ -185,7 +188,8 @@ func TestModToggleHandler(t *testing.T) {
|
||||
CallRoute(t, method, route, route, requestBody, handlerFunc, http.StatusOK, expected)
|
||||
|
||||
// check if changes happenes
|
||||
modList, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating Mods object: %s", err)
|
||||
}
|
||||
@ -213,7 +217,7 @@ func TestModToggleHandler(t *testing.T) {
|
||||
|
||||
CallRoute(t, method, route, route, requestBody, handlerFunc, http.StatusOK, expected)
|
||||
|
||||
modList, err = factorio.NewMods("dev")
|
||||
modList, err = factorio.NewMods(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating Mods object: %s", err)
|
||||
}
|
||||
@ -256,11 +260,12 @@ func TestModDeleteHandler(t *testing.T) {
|
||||
CallRoute(t, method, route, route, requestBody, handlerFunc, http.StatusOK, `"belt-balancer"`)
|
||||
|
||||
// check if mod is really not installed anymore
|
||||
_, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating Mods object: %s", err)
|
||||
}
|
||||
if factorio.ModSimpleList.CheckModExists("belt-balancer")) {
|
||||
if modList.ModSimpleList.CheckModExists("belt-balancer") {
|
||||
t.Fatalf("Mod is still installed, it should be gone by now")
|
||||
}
|
||||
})
|
||||
@ -286,7 +291,8 @@ func TestModDeleteAllHandler(t *testing.T) {
|
||||
CallRoute(t, method, route, route, nil, handlerFunc, http.StatusOK, "null")
|
||||
|
||||
// check if no mods are there
|
||||
modList, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating mods object: %s", err)
|
||||
}
|
||||
@ -319,7 +325,8 @@ func TestModUpdateHandler(t *testing.T) {
|
||||
defer CleanupMods(t)
|
||||
|
||||
// disable "belt-balancer" mod, so we can test, if it is still deactivated after
|
||||
modList, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating mods object: %s", err)
|
||||
}
|
||||
@ -414,7 +421,7 @@ func TestModUploadHandler(t *testing.T) {
|
||||
SetupMods(t, true)
|
||||
defer CleanupMods(t)
|
||||
|
||||
recorder := ModUploadRequest(t, true, "factorio_testfiles/belt-balancer_2.1.3.zip")
|
||||
recorder := ModUploadRequest(t, true, "../factorio_testfiles/belt-balancer_2.1.3.zip")
|
||||
|
||||
// status has to be 200
|
||||
if recorder.Code != http.StatusOK {
|
||||
@ -422,7 +429,8 @@ func TestModUploadHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
// check if mod is uploaded correctly
|
||||
modList, err := factorio.NewMods("dev")
|
||||
config := bootstrap.GetConfig()
|
||||
modList, err := factorio.NewMods(config.FactorioModsDir)
|
||||
assert.NoError(t, err, "error creating mods object")
|
||||
|
||||
expected := factorio.ModsResultList{
|
||||
@ -461,7 +469,7 @@ func TestModUploadHandler(t *testing.T) {
|
||||
SetupMods(t, true)
|
||||
defer CleanupMods(t)
|
||||
|
||||
recorder := ModUploadRequest(t, false, "factorio_testfiles/file_usage.txt")
|
||||
recorder := ModUploadRequest(t, false, "../factorio_testfiles/file_usage.txt")
|
||||
assert.Equal(t, http.StatusBadRequest, recorder.Code, "wrong response code.")
|
||||
})
|
||||
|
||||
@ -469,7 +477,7 @@ func TestModUploadHandler(t *testing.T) {
|
||||
SetupMods(t, true)
|
||||
defer CleanupMods(t)
|
||||
|
||||
recorder := ModUploadRequest(t, true, "factorio_testfiles/invalid_mod.zip")
|
||||
recorder := ModUploadRequest(t, true, "../factorio_testfiles/invalid_mod.zip")
|
||||
assert.Equal(t, http.StatusInternalServerError, recorder.Code, "wrong response code.")
|
||||
})
|
||||
}
|
||||
|
@ -3,27 +3,28 @@ package bootstrap
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/jessevdk/go-flags"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Flags struct {
|
||||
ConfFile *string
|
||||
FactorioDir *string
|
||||
ServerIP *string
|
||||
FactorioIP *string
|
||||
FactorioPort *string
|
||||
FactorioConfigFile *string
|
||||
FactorioMaxUpload *int64
|
||||
FactorioBinary *string
|
||||
GlibcCustom *string
|
||||
GlibcLocation *string
|
||||
GlibcLibLoc *string
|
||||
Autostart *string
|
||||
ConfFile string `long:"conf" default:"./conf.json" description:"Specify location of Factorio Server Manager config file."`
|
||||
FactorioDir string `long:"dir" default:"./" description:"Specify location of Factorio directory."`
|
||||
ServerIP string `long:"host" default:"0.0.0.0" description:"Specify IP for webserver to listen on."`
|
||||
FactorioIP string `long:"game-bind-address" default:"0.0.0.0" description:"Specify IP for Fcatorio gamer server to listen on."`
|
||||
FactorioPort string `long:"port" default:"8080" description:"Specify a port for the server."`
|
||||
FactorioConfigFile string `long:"config" default:"config/config.ini" description:"Specify location of Factorio config.ini file"`
|
||||
FactorioMaxUpload int64 `long:"max-upload" default:"20.971.520" description:"Maximum filesize for uploaded files (default 20MB)."`
|
||||
FactorioBinary string `long:"bin" default:"bin/x64/factorio" description:"Location of Factorio Server binary file"`
|
||||
GlibcCustom string `long:"glibc-custom" default:"false" description:"By default false, if custom glibc is required set this to true and add glibc-loc and glibc-lib-loc parameters"`
|
||||
GlibcLocation string `long:"glibc-loc" default:"/opt/glibc-2.18/lib/ld-2.18.so" description:"Location glibc ld.so file if needed (ex. /opt/glibc-2.18/lib/ld-2.18.so)"`
|
||||
GlibcLibLoc string `long:"glibc-lib-loc" default:"/opt/glibc-2.18/lib" description:"Location of glibc lib folder (ex. /opt/glibc-2.18/lib)"`
|
||||
Autostart string `long:"autostart" default:"false" description:"Autostart factorio server on bootup of FSM, default false [true/false]"`
|
||||
ModPackDir string `long:"mod-pack-dir" default:"./mod_packs" description:"Directory to store mod packs."`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -57,19 +58,24 @@ type Config struct {
|
||||
}
|
||||
|
||||
var instantiated Config
|
||||
var flags Flags
|
||||
var once sync.Once
|
||||
|
||||
func GetConfig() Config {
|
||||
once.Do(func() {
|
||||
instantiated = mapFlags()
|
||||
instantiated.loadServerConfig()
|
||||
})
|
||||
func NewConfig(args []string) Config {
|
||||
var opts Flags
|
||||
_, err := flags.NewParser(&opts, flags.IgnoreUnknown).ParseArgs(args)
|
||||
if err != nil {
|
||||
failOnError(err, "Failed to parse arguments")
|
||||
}
|
||||
instantiated = mapFlags(opts)
|
||||
instantiated.loadServerConfig()
|
||||
|
||||
abs, err := filepath.Abs(instantiated.FactorioModPackDir)
|
||||
println(abs)
|
||||
|
||||
return instantiated
|
||||
}
|
||||
|
||||
func SetFlags(parsedFlags Flags) {
|
||||
flags = parsedFlags
|
||||
func GetConfig() Config {
|
||||
return instantiated
|
||||
}
|
||||
|
||||
// Loads server configuration files
|
||||
@ -91,26 +97,26 @@ func randomPort() int {
|
||||
return rand.Intn(45000-40000) + 40000
|
||||
}
|
||||
|
||||
func mapFlags() Config {
|
||||
func mapFlags(flags Flags) Config {
|
||||
var config = Config{
|
||||
Autostart: *flags.Autostart,
|
||||
GlibcCustom: *flags.GlibcCustom,
|
||||
GlibcLocation: *flags.GlibcLocation,
|
||||
GlibcLibLoc: *flags.GlibcLibLoc,
|
||||
ConfFile: *flags.ConfFile,
|
||||
FactorioDir: *flags.FactorioDir,
|
||||
ServerIP: *flags.ServerIP,
|
||||
ServerPort: *flags.FactorioPort,
|
||||
FactorioIP: *flags.FactorioIP,
|
||||
FactorioSavesDir: filepath.Join(*flags.FactorioDir, "saves"),
|
||||
FactorioModsDir: filepath.Join(*flags.FactorioDir, "mods"),
|
||||
FactorioModPackDir: "./mod_packs",
|
||||
FactorioConfigDir: filepath.Join(*flags.FactorioDir, "config"),
|
||||
FactorioConfigFile: filepath.Join(*flags.FactorioDir, *flags.FactorioConfigFile),
|
||||
FactorioBinary: filepath.Join(*flags.FactorioDir, *flags.FactorioBinary),
|
||||
Autostart: flags.Autostart,
|
||||
GlibcCustom: flags.GlibcCustom,
|
||||
GlibcLocation: flags.GlibcLocation,
|
||||
GlibcLibLoc: flags.GlibcLibLoc,
|
||||
ConfFile: flags.ConfFile,
|
||||
FactorioDir: flags.FactorioDir,
|
||||
ServerIP: flags.ServerIP,
|
||||
ServerPort: flags.FactorioPort,
|
||||
FactorioIP: flags.FactorioIP,
|
||||
FactorioSavesDir: filepath.Join(flags.FactorioDir, "saves"),
|
||||
FactorioModsDir: filepath.Join(flags.FactorioDir, "mods"),
|
||||
FactorioModPackDir: flags.ModPackDir,
|
||||
FactorioConfigDir: filepath.Join(flags.FactorioDir, "config"),
|
||||
FactorioConfigFile: filepath.Join(flags.FactorioDir, flags.FactorioConfigFile),
|
||||
FactorioBinary: filepath.Join(flags.FactorioDir, flags.FactorioBinary),
|
||||
FactorioCredentialsFile: "./factorio.auth",
|
||||
FactorioAdminFile: "server-adminlist.json",
|
||||
MaxUploadSize: *flags.FactorioMaxUpload,
|
||||
MaxUploadSize: flags.FactorioMaxUpload,
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
|
@ -53,7 +53,8 @@ func (modPackMap *ModPackMap) reload() error {
|
||||
var err error
|
||||
newModPackMap := make(ModPackMap)
|
||||
config := bootstrap.GetConfig()
|
||||
|
||||
abs, err := filepath.Abs(config.FactorioModPackDir)
|
||||
println(abs)
|
||||
err = filepath.Walk(config.FactorioModPackDir, func(path string, info os.FileInfo, err error) error {
|
||||
if path == config.FactorioModPackDir || !info.IsDir() {
|
||||
return nil
|
||||
|
@ -18,11 +18,12 @@ type ModPortalStruct struct {
|
||||
DownloadURL string `json:"download_url"`
|
||||
FileName string `json:"file_name"`
|
||||
InfoJSON struct {
|
||||
FactorioVersion string `json:"factorio_version"`
|
||||
FactorioVersion Version `json:"factorio_version"`
|
||||
} `json:"info_json"`
|
||||
ReleasedAt time.Time `json:"released_at"`
|
||||
Sha1 string `json:"sha1"`
|
||||
Version Version `json:"version"`
|
||||
ReleasedAt time.Time `json:"released_at"`
|
||||
Sha1 string `json:"sha1"`
|
||||
Version Version `json:"version"`
|
||||
Compatibility bool
|
||||
} `json:"releases"`
|
||||
Summary string `json:"summary"`
|
||||
Title string `json:"title"`
|
||||
@ -54,27 +55,44 @@ func ModPortalList() (interface{}, error, int) {
|
||||
|
||||
// get the details (mod-info, releases, etc.) from a specific mod from the modPortal
|
||||
func ModPortalModDetails(modId string) (ModPortalStruct, error, int) {
|
||||
var jsonVal ModPortalStruct
|
||||
var mod ModPortalStruct
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "https://mods.factorio.com/api/mods/"+modId, nil)
|
||||
if err != nil {
|
||||
return jsonVal, err, 500
|
||||
return mod, err, 500
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return jsonVal, err, 500
|
||||
return mod, err, 500
|
||||
}
|
||||
|
||||
text, err := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if err != nil {
|
||||
return jsonVal, err, 500
|
||||
return mod, err, 500
|
||||
}
|
||||
|
||||
json.Unmarshal(text, &jsonVal)
|
||||
json.Unmarshal(text, &mod)
|
||||
|
||||
return jsonVal, nil, resp.StatusCode
|
||||
server, err := GetFactorioServer()
|
||||
if err != nil {
|
||||
return mod, err, resp.StatusCode
|
||||
}
|
||||
|
||||
installedBaseVersion := Version{}
|
||||
_ = installedBaseVersion.UnmarshalText([]byte(server.BaseModVersion))
|
||||
requiredVersion := NilVersion
|
||||
|
||||
for key, release := range mod.Releases {
|
||||
requiredVersion = release.InfoJSON.FactorioVersion
|
||||
areVersionIdentical := requiredVersion.Equals(installedBaseVersion)
|
||||
isException := installedBaseVersion.Equals(Version{1, 0, 0, 0}) && requiredVersion.Equals(Version{0, 18, 0, 0})
|
||||
release.Compatibility = areVersionIdentical || isException
|
||||
mod.Releases[key] = release
|
||||
}
|
||||
|
||||
return mod, nil, resp.StatusCode
|
||||
}
|
||||
|
||||
//Log the user into factorio, so mods can be downloaded
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 0.18 Binary seems equal to 0.17 binary, just the default values changed
|
||||
func Test0_18(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_18.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_18.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
@ -54,7 +54,7 @@ func Test0_18(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test0_17(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_17.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_17.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
@ -98,7 +98,7 @@ func Test0_17(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test0_16(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_16.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_16.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
@ -142,7 +142,7 @@ func Test0_16(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test0_15(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_15.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_15.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
@ -185,7 +185,7 @@ func Test0_15(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test0_14(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_14.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_14.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
@ -228,7 +228,7 @@ func Test0_14(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test0_13(t *testing.T) {
|
||||
file, err := OpenArchiveFile("factorio_testfiles/test_0_13.zip", "level.dat")
|
||||
file, err := OpenArchiveFile("../factorio_testfiles/test_0_13.zip", "level.dat")
|
||||
if err != nil {
|
||||
t.Fatalf("Error opening level.dat: %s", err)
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ require (
|
||||
github.com/gorilla/sessions v1.2.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
github.com/hpcloud/tail v1.0.0
|
||||
github.com/jessevdk/go-flags v1.4.0
|
||||
github.com/lib/pq v1.2.0 // indirect
|
||||
github.com/majormjr/rcon v0.0.0-20120923215419-8fbb8268b60a
|
||||
github.com/mattn/go-sqlite3 v1.11.0 // indirect
|
||||
|
@ -26,6 +26,8 @@ github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvK
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
|
||||
|
39
src/main.go
39
src/main.go
@ -1,21 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/mroote/factorio-server-manager/api"
|
||||
"github.com/mroote/factorio-server-manager/bootstrap"
|
||||
"github.com/mroote/factorio-server-manager/factorio"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// parse command flags and pass them to bootstrap
|
||||
flags := parseFlags()
|
||||
bootstrap.SetFlags(flags)
|
||||
|
||||
// get the all configs based on the flags
|
||||
config := bootstrap.GetConfig()
|
||||
config := bootstrap.NewConfig(os.Args)
|
||||
|
||||
// setup the required files for the mods
|
||||
factorio.ModStartUp()
|
||||
@ -36,34 +32,3 @@ func main() {
|
||||
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
|
||||
|
||||
}
|
||||
|
||||
func parseFlags() bootstrap.Flags {
|
||||
confFile := flag.String("conf", "./conf.json", "Specify location of Factorio Server Manager config file.")
|
||||
factorioDir := flag.String("dir", "./", "Specify location of Factorio directory.")
|
||||
serverIP := flag.String("host", "0.0.0.0", "Specify IP for webserver to listen on.")
|
||||
factorioIP := flag.String("game-bind-address", "0.0.0.0", "Specify IP for Fcatorio gamer server to listen on.")
|
||||
factorioPort := flag.String("port", "8080", "Specify a port for the server.")
|
||||
factorioConfigFile := flag.String("config", "config/config.ini", "Specify location of Factorio config.ini file")
|
||||
factorioMaxUpload := flag.Int64("max-upload", 1024*1024*20, "Maximum filesize for uploaded files (default 20MB).")
|
||||
factorioBinary := flag.String("bin", "bin/x64/factorio", "Location of Factorio Server binary file")
|
||||
glibcCustom := flag.String("glibc-custom", "false", "By default false, if custom glibc is required set this to true and add glibc-loc and glibc-lib-loc parameters")
|
||||
glibcLocation := flag.String("glibc-loc", "/opt/glibc-2.18/lib/ld-2.18.so", "Location glibc ld.so file if needed (ex. /opt/glibc-2.18/lib/ld-2.18.so)")
|
||||
glibcLibLoc := flag.String("glibc-lib-loc", "/opt/glibc-2.18/lib", "Location of glibc lib folder (ex. /opt/glibc-2.18/lib)")
|
||||
autostart := flag.String("autostart", "false", "Autostart factorio server on bootup of FSM, default false [true/false]")
|
||||
flag.Parse()
|
||||
|
||||
return bootstrap.Flags{
|
||||
ConfFile: confFile,
|
||||
FactorioDir: factorioDir,
|
||||
ServerIP: serverIP,
|
||||
FactorioIP: factorioIP,
|
||||
FactorioPort: factorioPort,
|
||||
FactorioConfigFile: factorioConfigFile,
|
||||
FactorioMaxUpload: factorioMaxUpload,
|
||||
FactorioBinary: factorioBinary,
|
||||
GlibcCustom: glibcCustom,
|
||||
GlibcLocation: glibcLocation,
|
||||
GlibcLibLoc: glibcLibLoc,
|
||||
Autostart: autostart,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user