From c42df03858790ef92057e9949c15a340273d5bb5 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 19 Oct 2024 21:19:33 +0100 Subject: [PATCH] read from env var Q3RCON_STALE_SESSION_TIMEOUT --- cmd/q3rcon-proxy/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go index ada33be..09a4515 100644 --- a/cmd/q3rcon-proxy/main.go +++ b/cmd/q3rcon-proxy/main.go @@ -5,6 +5,7 @@ import ( "os" "slices" "strings" + "time" log "github.com/sirupsen/logrus" @@ -30,20 +31,28 @@ func main() { host = "0.0.0.0" } + staleTimeout, err := getEnvInt("Q3RCON_STALE_SESSION_TIMEOUT") + if err != nil { + log.Fatalf("unable to parse Q3RCON_STALE_SESSION_TIMEOUT: %s", err.Error()) + } + for _, proxy := range strings.Split(proxies, ";") { - go start(host, proxy) + go start(host, proxy, staleTimeout) } <-make(chan int) } -func start(host, proxy string) { +func start(host, proxy string, staleTimeout int) { port, target := func() (string, string) { x := strings.Split(proxy, ":") return x[0], x[1] }() - c, err := udpproxy.New(fmt.Sprintf("%s:%s", host, port), fmt.Sprintf("127.0.0.1:%s", target)) + c, err := udpproxy.New( + fmt.Sprintf("%s:%s", host, port), + fmt.Sprintf("127.0.0.1:%s", target), + udpproxy.WithStaleTimeout(time.Duration(staleTimeout)*time.Minute)) if err != nil { log.Fatal(err) }