Skip to content

Commit 881cf32

Browse files
authored
Merge pull request #179 from Psychomantis71/master
Autostart feature
2 parents e0b42de + f1cff02 commit 881cf32

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ Usage of ./factorio-server-manager:
6666
Path to the glibc ld.so file (default "/opt/glibc-2.18/lib/ld-2.18.so")
6767
-glibc-lib-loc
6868
Path to the glibc lib folder (default "/opt/glibc-2.18/lib")
69-
69+
-autostart
70+
Autostarts Factorio Server when FSM is starting. Default false [true/false]
71+
(If no IP and/or port provided at startup, it will bind the factorio server to all interfaces
72+
and set the server port to the default 34197, always loads latest save)
7073
Example:
7174
7275
./factorio-server-manager --dir /home/user/.factorio --host 10.0.0.1

src/factorio_server.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ func randomPort() int {
4343
return rand.Intn(45000-40000) + 40000
4444
}
4545

46+
func autostart() {
47+
48+
var err error
49+
if FactorioServ.BindIP == "" {
50+
FactorioServ.BindIP = "0.0.0.0"
51+
52+
}
53+
if FactorioServ.Port == 0 {
54+
FactorioServ.Port = 34197
55+
}
56+
FactorioServ.Savefile = "Load Latest"
57+
58+
err = FactorioServ.Run()
59+
60+
if err != nil {
61+
log.Printf("Error starting Factorio server: %+v", err)
62+
return
63+
}
64+
65+
}
66+
4667
func initFactorio() (f *FactorioServer, err error) {
4768
f = new(FactorioServer)
4869
f.Settings = make(map[string]interface{})
@@ -161,6 +182,10 @@ func initFactorio() (f *FactorioServer, err error) {
161182
}
162183
}
163184

185+
if config.autostart == "true" {
186+
go autostart()
187+
}
188+
164189
return
165190
}
166191

src/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Config struct {
3838
glibcCustom string
3939
glibcLocation string
4040
glibcLibLoc string
41+
autostart string
4142
}
4243

4344
var (
@@ -79,8 +80,10 @@ func parseFlags() {
7980
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")
8081
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)")
8182
glibcLibLoc := flag.String("glibc-lib-loc", "/opt/glibc-2.18/lib", "Location of glibc lib folder (ex. /opt/glibc-2.18/lib)")
83+
autostart := flag.String("autostart", "false", "Autostart factorio server on bootup of FSM, default false [true/false]")
8284

8385
flag.Parse()
86+
config.autostart = *autostart
8487
config.glibcCustom = *glibcCustom
8588
config.glibcLocation = *glibcLocation
8689
config.glibcLibLoc = *glibcLibLoc

0 commit comments

Comments
 (0)