Skip to content

Commit

Permalink
force quit if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Distortions81 committed Nov 9, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
1 parent b4d1a7b commit 0f8e1d2
Showing 4 changed files with 27 additions and 39 deletions.
31 changes: 0 additions & 31 deletions fact/factUpdater.go

This file was deleted.

2 changes: 2 additions & 0 deletions glob/glob.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"encoding/base64"
"math"
"os"
"os/exec"
"sync"
"time"

@@ -130,6 +131,7 @@ var (
BootMessage *discordgo.Message
UpdateMessage *discordgo.Message

FactorioCmd *exec.Cmd
FactorioContext context.Context
FactorioCancel context.CancelFunc

18 changes: 13 additions & 5 deletions support/factLauncher.go
Original file line number Diff line number Diff line change
@@ -473,14 +473,22 @@ func launchFactorio() {
glob.BootMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.BootMessage, "Status", "Loading mods...", glob.COLOR_GREEN)
}

if glob.FactorioCmd != nil {
cwlog.DoLogCW("Killing previous factorio process!!!")
glob.FactorioCmd.Process.Kill()
glob.FactorioCmd = nil
return
}
if glob.FactorioCancel != nil {
cwlog.DoLogCW("Killing previous factorio context!!!")
glob.FactorioCancel()
glob.FactorioCancel = nil
return
}
glob.FactorioContext, glob.FactorioCancel = context.WithCancel(context.Background())

/* Run Factorio */
cmd := exec.Command(fact.GetFactorioBinary(), tempargs...)
glob.FactorioCmd = exec.Command(fact.GetFactorioBinary(), tempargs...)

/* Hide RCON password and port */
for i, targ := range tempargs {
@@ -503,13 +511,13 @@ func launchFactorio() {

/* Launch Factorio */
cwlog.DoLogCW("Executing: " + fact.GetFactorioBinary() + " " + strings.Join(tempargs, " "))
LinuxSetProcessGroup(cmd)
LinuxSetProcessGroup(glob.FactorioCmd)
/* Connect Factorio stdout to a buffer for processing */
fact.GameBuffer = new(bytes.Buffer)
logwriter := io.MultiWriter(fact.GameBuffer)
cmd.Stdout = logwriter
glob.FactorioCmd.Stdout = logwriter
/* Stdin */
tpipe, errp := cmd.StdinPipe()
tpipe, errp := glob.FactorioCmd.StdinPipe()

/* Factorio is not happy. */
if errp != nil {
@@ -529,7 +537,7 @@ func launchFactorio() {
}

/* Handle launch errors */
err = cmd.Start()
err = glob.FactorioCmd.Start()
if err != nil {
fact.LogCMS(cfg.Local.Channel.ChatChannel, fmt.Sprintf("An error occurred when attempting to start the game. Details: %s", err))
glob.BootMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.BootMessage, "ERROR", "Launching Factorio failed!", glob.COLOR_RED)
15 changes: 12 additions & 3 deletions support/mainLoops.go
Original file line number Diff line number Diff line change
@@ -76,13 +76,22 @@ func MainLoops() {
/* Just in case factorio hangs, bogs down or is flooded */
if nores == 120 {
msg := "Factorio unresponsive for over two minutes... rebooting."
fact.LogCMS(cfg.Local.Channel.ChatChannel, msg)
cwlog.DoLogCW(msg)
glob.RelaunchThrottle = 0
fact.QuitFactorio(msg)

fact.WaitFactQuit(false)
fact.FactorioBooted = false
fact.SetFactRunning(false)

if glob.FactorioCmd != nil {
cwlog.DoLogCW("Killing previous factorio process!!!")
glob.FactorioCmd.Process.Kill()
glob.FactorioCmd = nil
}
if glob.FactorioCancel != nil {
cwlog.DoLogCW("Killing previous factorio context!!!")
glob.FactorioCancel()
glob.FactorioCancel = nil
}
}
}
}

0 comments on commit 0f8e1d2

Please sign in to comment.