Skip to content

Commit 0480a36

Browse files
authored
Merge pull request #178 from jannaahs/fix-console
Fix console
2 parents 122cf1d + a7b133b commit 0480a36

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/factorio_server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func initFactorio() (f *FactorioServer, err error) {
139139
f.BaseModVersion = modInfo.Version
140140

141141
// load admins from additional file
142-
if(f.Version.Greater(Version{0,17,0})) {
142+
if (f.Version.Greater(Version{0, 17, 0})) {
143143
if _, err := os.Stat(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile)); os.IsNotExist(err) {
144144
//save empty admins-file
145145
ioutil.WriteFile(filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile), []byte("[]"), 0664)
@@ -190,7 +190,7 @@ func (f *FactorioServer) Run() error {
190190
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
191191
"--rcon-password", config.FactorioRconPass)
192192

193-
if(f.Version.Greater(Version{0,17,0})) {
193+
if (f.Version.Greater(Version{0, 17, 0})) {
194194
args = append(args, "--server-adminlist", filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile))
195195
}
196196

@@ -265,11 +265,11 @@ func (f *FactorioServer) parseRunningCommand(std io.ReadCloser) (err error) {
265265
}
266266
}
267267
// If rcon port opens indicated in log connect to rcon
268-
rconLog := "Starting RCON interface at port " + strconv.Itoa(config.FactorioRconPort)
268+
rconLog := "Starting RCON interface at IP"
269269
// check if slice index is greater than 2 to prevent panic
270270
if len(line) > 2 {
271271
// log line for opened rcon connection
272-
if strings.Join(line[3:], " ") == rconLog {
272+
if strings.Contains(strings.Join(line, " "), rconLog) {
273273
log.Printf("Rcon running on Factorio Server")
274274
err = connectRC()
275275
if err != nil {

src/wsroutes.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,32 @@ import (
77
"github.com/hpcloud/tail"
88
)
99

10+
func IsClosed(ch <-chan Message) bool {
11+
select {
12+
case <-ch:
13+
return true
14+
default:
15+
}
16+
17+
return false
18+
}
19+
1020
func logSubscribe(client *Client, data interface{}) {
1121
go func() {
1222
logfile := filepath.Join(config.FactorioDir, "factorio-server-console.log")
13-
t, err := tail.TailFile(logfile, tail.Config{Follow: true})
23+
t, err := tail.TailFile(logfile, tail.Config{Follow: true, Poll: true})
1424
if err != nil {
1525
log.Printf("Error subscribing to tail log %s", err)
1626
return
1727
}
1828

1929
for line := range t.Lines {
20-
client.send <- Message{"log update", line.Text}
30+
if !IsClosed(client.send) {
31+
client.send <- Message{"log update", line.Text}
32+
} else {
33+
log.Printf("Channel was closed")
34+
return
35+
}
2136
}
2237
}()
2338
}
@@ -35,7 +50,12 @@ func commandSend(client *Client, data interface{}) {
3550

3651
log.Printf("Command send to Factorio: %s, with rcon request id: %v", data, reqId)
3752

38-
client.send <- Message{"receive command", data}
53+
if !IsClosed(client.send) {
54+
client.send <- Message{"receive command", data}
55+
} else {
56+
log.Printf("Channel was closed")
57+
return
58+
}
3959
}()
4060
}
4161
}

0 commit comments

Comments
 (0)