mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2025-01-18 08:40:53 +00:00
add cmd/q3rcon-proxy
This commit is contained in:
parent
2d21e400d8
commit
270f993cbc
39
cmd/q3rcon-proxy/main.go
Normal file
39
cmd/q3rcon-proxy/main.go
Normal file
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user