Skip to content

Commit 759aae4

Browse files
author
aperkovic
committed
Optimised GLIBC fix, added autostart feature
1 parent 02ce64d commit 759aae4

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ Usage of ./factorio-server-manager:
6565
Path to the glibc ld.so file (default "/opt/glibc-2.18/lib/ld-2.18.so")
6666
-glibc-lib-loc
6767
Path to the glibc lib folder (default "/opt/glibc-2.18/lib")
68+
-autostart
69+
Autostarts Factorio Server when FSM is starting. Default false [true/false]
70+
(If no IP and/or port provided at startup, it will bind the factorio server to all interfaces
71+
and set the server port to the default 34197, always loads latest save)
72+
6873
Example:
6974
7075
./factorio-server-manager --dir /home/user/.factorio --host 10.0.0.1

src/factorio_server.go

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ func randomPort() int {
4242
// Returns random port to use for rcon connection
4343
return rand.Intn(45000-40000) + 40000
4444
}
45+
func autostart() {
46+
47+
var err error
48+
if FactorioServ.BindIP == "" {
49+
FactorioServ.BindIP = "0.0.0.0"
50+
51+
}
52+
if FactorioServ.Port == 0 {
53+
FactorioServ.Port = 34197
54+
}
55+
FactorioServ.Savefile = "Load Latest"
56+
57+
err = FactorioServ.Run()
58+
59+
if err != nil {
60+
log.Printf("Error starting Factorio server: %+v", err)
61+
return
62+
}
63+
64+
}
4565

4666
func initFactorio() (f *FactorioServer, err error) {
4767
f = new(FactorioServer)
@@ -133,6 +153,10 @@ func initFactorio() (f *FactorioServer, err error) {
133153

134154
f.BaseModVersion = modInfo.Version
135155

156+
if config.autostart == "true" {
157+
go autostart()
158+
}
159+
136160
return
137161
}
138162

@@ -147,28 +171,21 @@ func (f *FactorioServer) Run() error {
147171
}
148172

149173
args := []string{}
174+
175+
//The factorio server refenences its executable-path, since we execute the ld.so file and pass the factorio binary as a parameter
176+
//the game would use the path to the ld.so file as it's executable path and crash, to prevent this the parameter "--executable-path" is added
150177
if config.glibcCustom == "true" {
151178
log.Println("Custom glibc selected, glibc.so location:", config.glibcLocation, " lib location:", config.glibcLibLoc)
152-
args = []string{
153-
"--library-path", config.glibcLibLoc,
154-
config.FactorioBinary,
155-
"--bind", (f.BindIP),
156-
"--port", strconv.Itoa(f.Port),
157-
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
158-
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
159-
"--rcon-password", config.FactorioRconPass,
160-
"--executable-path", config.FactorioBinary,
161-
}
162-
} else {
163-
args = []string{
164-
"--bind", (f.BindIP),
165-
"--port", strconv.Itoa(f.Port),
166-
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
167-
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
168-
"--rcon-password", config.FactorioRconPass,
169-
}
179+
args = append(args, "--library-path", config.glibcLibLoc, config.FactorioBinary, "--executable-path", config.FactorioBinary)
170180
}
171181

182+
args = append(args,
183+
"--bind", (f.BindIP),
184+
"--port", strconv.Itoa(f.Port),
185+
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
186+
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
187+
"--rcon-password", config.FactorioRconPass)
188+
172189
if f.Savefile == "Load Latest" {
173190
args = append(args, "--start-server-load-latest")
174191
} else {

src/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Config struct {
3737
glibcCustom string
3838
glibcLocation string
3939
glibcLibLoc string
40+
autostart string
4041
}
4142

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

8284
flag.Parse()
85+
config.autostart = *autostart
8386
config.glibcCustom = *glibcCustom
8487
config.glibcLocation = *glibcLocation
8588
config.glibcLibLoc = *glibcLibLoc
@@ -129,7 +132,7 @@ func main() {
129132

130133
// Initialize HTTP router
131134
router := NewRouter()
132-
133135
log.Printf("Starting server on: %s:%s", config.ServerIP, config.ServerPort)
134136
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
137+
135138
}

0 commit comments

Comments
 (0)