From a513c7ecc6c5037e24a43bd4bf081df97cda2253 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 8 Mar 2024 02:29:27 +0000 Subject: [PATCH] add new env var Q3RCON_HOST --- cmd/q3rcon-proxy/main.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go index 8559fb3..5cc260e 100644 --- a/cmd/q3rcon-proxy/main.go +++ b/cmd/q3rcon-proxy/main.go @@ -15,22 +15,33 @@ func start(proxy string) { return x[0], x[1] }() - c, err := udpproxy.New(fmt.Sprintf("0.0.0.0:%s", 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)) if err != nil { log.Fatal(err) } - log.Printf("q3rcon-proxy initialized: [proxy] (0.0.0.0:%s) [target] (127.0.0.1:%s)", port, target) + log.Printf("q3rcon-proxy initialized: [proxy] (%s:%s) [target] (127.0.0.1:%s)", host, port, target) log.Fatal(c.ListenAndServe()) } -func main() { - proxies := os.Getenv("Q3RCON_PROXY") +var ( + proxies, host string +) + +func init() { + proxies = os.Getenv("Q3RCON_PROXY") if proxies == "" { log.Fatal("env Q3RCON_PROXY required") } + host = os.Getenv("Q3RCON_HOST") + if host == "" { + host = "0.0.0.0" + } +} + +func main() { for _, proxy := range strings.Split(proxies, ";") { go start(proxy) }