From 270f993cbc578793eb7dfe79acad75f5ad30bde6 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 27 Jan 2024 14:48:09 +0000 Subject: [PATCH] add cmd/q3rcon-proxy --- cmd/q3rcon-proxy/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cmd/q3rcon-proxy/main.go diff --git a/cmd/q3rcon-proxy/main.go b/cmd/q3rcon-proxy/main.go new file mode 100644 index 0000000..8559fb3 --- /dev/null +++ b/cmd/q3rcon-proxy/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "log" + "os" + "strings" + + "github.com/onyx-and-iris/q3rcon-proxy/pkg/udpproxy" +) + +func start(proxy string) { + port, target := func() (string, string) { + x := strings.Split(proxy, ":") + 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)) + 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.Fatal(c.ListenAndServe()) +} + +func main() { + proxies := os.Getenv("Q3RCON_PROXY") + if proxies == "" { + log.Fatal("env Q3RCON_PROXY required") + } + + for _, proxy := range strings.Split(proxies, ";") { + go start(proxy) + } + + <-make(chan int) +}