Skip to content

Commit d84bc35

Browse files
committed
fixed bug where UI did not report successful start
1 parent ff2faaa commit d84bc35

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/handlers.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path/filepath"
1212
"strconv"
13+
"time"
1314

1415
"github.com/gorilla/mux"
1516
)
@@ -588,29 +589,28 @@ func StartServer(w http.ResponseWriter, r *http.Request) {
588589
err = FactorioServ.Run()
589590
if err != nil {
590591
log.Printf("Error starting Factorio server: %s", err)
591-
resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err)
592-
if err := json.NewEncoder(w).Encode(resp); err != nil {
593-
log.Printf("Error encoding start server JSON response: ", err)
594-
}
595592
return
596593
}
597594
}()
598595

599-
if FactorioServ.Running {
600-
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
601-
resp.Data = fmt.Sprintf("Factorio server with save: %s started on port: %d", FactorioServ.Savefile, FactorioServ.Port)
602-
resp.Success = true
603-
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
604-
if err := json.NewEncoder(w).Encode(resp); err != nil {
605-
log.Printf("Error encoding config file JSON reponse: ", err)
606-
}
607-
} else {
608-
log.Printf("Error starting Factorio server: %s", err)
609-
resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err)
610-
if err := json.NewEncoder(w).Encode(resp); err != nil {
611-
log.Printf("Error encoding start server JSON response: ", err)
596+
timeout := 0
597+
for timeout <= 3 {
598+
time.Sleep(1 * time.Second)
599+
if FactorioServ.Running {
600+
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
601+
resp.Data = fmt.Sprintf("Factorio server with save: %s started on port: %d", FactorioServ.Savefile, FactorioServ.Port)
602+
resp.Success = true
603+
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
604+
if err := json.NewEncoder(w).Encode(resp); err != nil {
605+
log.Printf("Error encoding config file JSON reponse: ", err)
606+
}
607+
break
608+
} else {
609+
log.Printf("Did not detect running Factorio server attempt: %s", timeout)
612610
}
611+
timeout++
613612
}
613+
614614
}
615615
}
616616

0 commit comments

Comments
 (0)