factorio-server-manager/main.go

58 lines
1.7 KiB
Go
Raw Normal View History

2016-04-17 22:58:14 +02:00
package main
import (
"flag"
"log"
2016-04-18 00:20:06 +02:00
"net/http"
2016-04-17 22:58:14 +02:00
)
type Config struct {
FactorioDir string
FactorioSavesDir string
FactorioModsDir string
FactorioConfigFile string
FactorioLog string
FactorioBinary string
ServerIP string
ServerPort string
MaxUploadSize int64
2016-04-17 22:58:14 +02:00
}
var (
config Config
FactorioServ *FactorioServer
)
2016-04-17 22:58:14 +02:00
2016-04-20 03:45:49 +02:00
func loadFlags() {
factorioDir := flag.String("dir", "./", "Specify location of Factorio directory.")
2016-04-20 03:45:49 +02:00
factorioIP := flag.String("host", "0.0.0.0", "Specify IP for webserver 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")
2016-04-17 22:58:14 +02:00
flag.Parse()
config.FactorioDir = *factorioDir
2016-04-20 03:45:49 +02:00
config.FactorioSavesDir = config.FactorioDir + "/saves"
config.FactorioModsDir = config.FactorioDir + "/mods"
config.FactorioConfigFile = config.FactorioDir + "/" + *factorioConfigFile
2016-04-25 03:38:06 +02:00
config.FactorioBinary = config.FactorioDir + "/" + *factorioBinary
config.ServerIP = *factorioIP
2016-04-20 03:45:49 +02:00
config.ServerPort = *factorioPort
config.FactorioLog = config.FactorioDir + "/factorio-current.log"
config.MaxUploadSize = *factorioMaxUpload
2016-04-20 03:45:49 +02:00
}
func main() {
loadFlags()
2016-04-17 22:58:14 +02:00
FactorioServ = initFactorio()
FactorioServ.Port = 12345
FactorioServ.Savefile = "testingsaves"
2016-04-18 00:20:06 +02:00
router := NewRouter()
2016-04-20 03:45:49 +02:00
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
2016-04-17 22:58:14 +02:00
}