Added internet check and warning when offline

This commit is contained in:
2026-05-21 10:10:18 -06:00
parent 283ffb66eb
commit 93c4825ff7
4 changed files with 117 additions and 94 deletions

View File

@@ -8,6 +8,9 @@ import (
)
func startStopServer(cmd string, con UsrConfig) {
if hasInternet() != true {
fmt.Printf("WARNING!\n\tNot connected to internet, LAN access only\n")
}
switch cmd {
case "start":
x := fmt.Sprintf("%s --port %d --server-settings %s --start-server %s", con.Server.ServExec, con.Server.ServPort, con.Server.ServCfg, con.Server.WorldFile)

View File

@@ -9,6 +9,8 @@ import (
)
func downloadMods(c UsrConfig) {
if hasInternet() == true {
//var c = readCfg("config.yml")
modlist := string(c.Server.ServDir) + "/mods/mod-list.json"
@@ -80,5 +82,7 @@ func downloadMods(c UsrConfig) {
}
}
} else {
fmt.Println("Unable to access internet, please check connection.")
}
}

View File

@@ -2,6 +2,7 @@ package main
import (
"archive/tar"
"fmt"
"io"
"log"
"net/http"
@@ -13,7 +14,7 @@ import (
)
func downloadHeadless(c UsrConfig) {
//var c = readCfg("config.yml")
if hasInternet() == true {
headlessQuery := "https://www.factorio.com/get-download/latest/headless/linux64"
url := headlessQuery
@@ -46,4 +47,7 @@ func downloadHeadless(c UsrConfig) {
}
// zip does not preserve permissions correctly so i have to do this
exec.Command("chmod", "+x", c.Server.ServExec)
} else {
fmt.Println("Unable to access internet, please check connection.")
}
}

View File

@@ -4,10 +4,12 @@ import (
"archive/zip"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"strings"
"time"
)
//Utilities
@@ -91,3 +93,13 @@ func unzip(src, dest string) ([]string, error) {
return filenames, nil
}
func hasInternet() bool {
timeout := 2 * time.Second
conn, err := net.DialTimeout("tcp", "8.8.8.8:53", timeout)
if err != nil {
return false
}
conn.Close()
return true
}