mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-07 15:53:29 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d85129d31 | |||
| bf7bd4f5b8 | |||
| a13d3d7da3 | |||
| a0c1f15ef0 | |||
| e0dc2c02d9 | |||
| 514688b9ce | |||
| 43183717f6 | |||
|
|
464fbec85f | ||
| fd51761ab5 | |||
| 16e5e9c010 | |||
| 916d2a2d86 | |||
|
|
1bbe3102ce | ||
|
|
f1762cf3ad |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
# Auto-generated .gitignore by gignore: github.com/onyx-and-iris/gignore
|
||||
### Go ###
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
@@ -20,10 +22,7 @@ bin/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
# End of gignore: github.com/onyx-and-iris/gignore
|
||||
|
||||
# Added by goreleaser init:
|
||||
dist/
|
||||
|
||||
# testing
|
||||
run.sh
|
||||
server.yaml
|
||||
dist/
|
||||
12
CHANGELOG.md
12
CHANGELOG.md
@@ -11,6 +11,18 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
|
||||
- [x]
|
||||
|
||||
## [1.7.0] - 2025-06-05
|
||||
|
||||
### Added
|
||||
|
||||
- Taskfile added for running and building project.
|
||||
- The binary may be passed CLI flags as well as environment variables.
|
||||
|
||||
### Changed
|
||||
|
||||
- CLI component rewritten with urfave/cli.
|
||||
- env var `Q3RCON_TARGET_PORTS` renamed to `Q3RCON_PORTS_MAPPING`
|
||||
|
||||
## [1.4.0] - 2024-11-29
|
||||
|
||||
### Added
|
||||
|
||||
48
README.md
48
README.md
@@ -8,23 +8,52 @@ Unfortunately the Q3Rcon engine ties the rcon port to the game servers public po
|
||||
|
||||
### Use
|
||||
|
||||
Run one or multiple rcon proxies by setting an environment variable `Q3RCON_TARGET_PORTS`
|
||||
|
||||
for example:
|
||||
#### Flags
|
||||
|
||||
```bash
|
||||
export Q3RCON_TARGET_PORTS="20000:28960;20001:28961;20002:28962"
|
||||
#!/usr/bin/env bash
|
||||
|
||||
/usr/local/bin/q3rcon-proxy \
|
||||
--proxy-host=0.0.0.0 \
|
||||
--target-host=localhost \
|
||||
--ports-mapping=28961:28960 \
|
||||
--session-timeout=20 \
|
||||
--loglevel=debug
|
||||
```
|
||||
|
||||
This would configure q3rcon-proxy to run 3 proxy servers listening on ports `20000`, `20001` and `20002` that redirect rcon requests to game servers on ports `28960`, `28961` and `28962` respectively.
|
||||
#### Environment Variables
|
||||
|
||||
Then just run the binary which you can compile yourself, download from `Releases` or use the included Dockerfile.
|
||||
Each of the flags has a corresponding environment variable:
|
||||
|
||||
- `Q3RCON_PROXY_HOST`: The host the proxy server sits on.
|
||||
- `Q3RCON_TARGET_HOST`: The host the game servers sit on.
|
||||
- `Q3RCON_PORTS_MAPPING`: A mapping as a string with `source:target` pairs delimited by `;`.
|
||||
- `Q3RCON_SESSION_TIMEOUT`: Timeout in seconds for each udp session.
|
||||
- `Q3RCON_LOGLEVEL`: The application's logging level (see [Logging][logging]).
|
||||
|
||||
Multiple rcon proxies may be configured by setting *--ports-mapping/Q3RCON_PORTS_MAPPING* like so:
|
||||
|
||||
```console
|
||||
export Q3RCON_PORTS_MAPPING="20000:28960;20001:28961;20002:28962"
|
||||
```
|
||||
|
||||
This would configure q3rcon-proxy to run 3 proxy servers listening on ports 20000, 20001 and 20002 that redirect rcon requests to game servers on ports 28960, 28961 and 28962 respectively.
|
||||
|
||||
### Logging
|
||||
|
||||
Set the log level with environment variable `Q3RCON_LOGLEVEL`:
|
||||
Set the log level with environment variable `Q3RCON_LOGLEVEL`.
|
||||
|
||||
`0 = Panic, 1 = Fatal, 2 = Error, 3 = Warning, 4 = Info, 5 = Debug, 6 = Trace`
|
||||
Acceptable values are:
|
||||
|
||||
- `trace`
|
||||
- `debug`
|
||||
- `info`
|
||||
- `warn`
|
||||
- `error`
|
||||
- `fatal`
|
||||
- `panic`
|
||||
|
||||
If not set it will default to `info`.
|
||||
|
||||
### Special Thanks
|
||||
|
||||
@@ -37,4 +66,5 @@ Set the log level with environment variable `Q3RCON_LOGLEVEL`:
|
||||
|
||||
For a compatible rcon client also written in Go consider checking out the [Q3 Rcon][q3rcon] package.
|
||||
|
||||
[q3rcon]: https://github.com/onyx-and-iris/q3rcon
|
||||
[q3rcon]: https://github.com/onyx-and-iris/q3rcon
|
||||
[logging]: https://github.com/onyx-and-iris/q3rcon-proxy/tree/dev?tab=readme-ov-file#logging
|
||||
16
Taskfile.yml
16
Taskfile.yml
@@ -1,5 +1,8 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
docker: ./docker/Taskfile.docker.yml
|
||||
|
||||
vars:
|
||||
PROGRAM: q3rcon-proxy
|
||||
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
|
||||
@@ -38,11 +41,13 @@ tasks:
|
||||
desc: Build the q3rcon-proxy project for Windows
|
||||
cmds:
|
||||
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.Version={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
|
||||
internal: true
|
||||
|
||||
build-linux:
|
||||
desc: Build the q3rcon-proxy project for Linux
|
||||
cmds:
|
||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.Version={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
|
||||
internal: true
|
||||
|
||||
test:
|
||||
desc: Run tests
|
||||
@@ -53,3 +58,14 @@ tasks:
|
||||
desc: Clean the build artifacts
|
||||
cmds:
|
||||
- '{{.SHELL}} rm -r {{.BIN_DIR}}'
|
||||
|
||||
run:
|
||||
desc: Run the q3rcon-proxy project
|
||||
cmds:
|
||||
- |
|
||||
go run ./cmd/{{.PROGRAM}} \
|
||||
--proxy-host=0.0.0.0 \
|
||||
--target-host=localhost \
|
||||
--ports-mapping=28961:28960 \
|
||||
--session-timeout=20 \
|
||||
--loglevel=debug
|
||||
|
||||
@@ -1,73 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/onyx-and-iris/q3rcon-proxy/pkg/udpproxy"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logLevel, err := getEnvInt("Q3RCON_LOGLEVEL")
|
||||
if err != nil {
|
||||
log.Fatalf("unable to parse Q3RCON_LEVEL: %s", err.Error())
|
||||
}
|
||||
if slices.Contains(log.AllLevels, log.Level(logLevel)) {
|
||||
log.SetLevel(log.Level(logLevel))
|
||||
}
|
||||
|
||||
proxyHost := os.Getenv("Q3RCON_PROXY_HOST")
|
||||
if proxyHost == "" {
|
||||
proxyHost = "0.0.0.0"
|
||||
}
|
||||
|
||||
targetHost := os.Getenv("Q3RCON_TARGET_HOST")
|
||||
if targetHost == "" {
|
||||
targetHost = "127.0.0.1"
|
||||
}
|
||||
|
||||
proxies := os.Getenv("Q3RCON_TARGET_PORTS")
|
||||
if proxies == "" {
|
||||
log.Fatal("env Q3RCON_TARGET_PORTS required")
|
||||
}
|
||||
|
||||
sessionTimeout, err := getEnvInt("Q3RCON_SESSION_TIMEOUT")
|
||||
if err != nil {
|
||||
log.Fatalf("unable to parse Q3RCON_SESSION_TIMEOUT: %s", err.Error())
|
||||
}
|
||||
if sessionTimeout == 0 {
|
||||
sessionTimeout = 20
|
||||
}
|
||||
|
||||
for _, proxy := range strings.Split(proxies, ";") {
|
||||
go start(proxyHost, targetHost, proxy, sessionTimeout)
|
||||
}
|
||||
|
||||
<-make(chan struct{})
|
||||
type proxyConfig struct {
|
||||
proxyHost string
|
||||
targetHost string
|
||||
portsMapping []string
|
||||
sessionTimeout int
|
||||
}
|
||||
|
||||
func start(proxyHost, targetHost, ports string, sessionTimeout int) {
|
||||
proxyPort, targetPort := func() (string, string) {
|
||||
x := strings.Split(ports, ":")
|
||||
return x[0], x[1]
|
||||
}()
|
||||
func main() {
|
||||
cmd := &cli.Command{
|
||||
Name: "q3rcon-proxy",
|
||||
Usage: "A Quake 3 RCON proxy server",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "proxy-host",
|
||||
Value: "0.0.0.0",
|
||||
Usage: "Proxy host address",
|
||||
Sources: cli.EnvVars("Q3RCON_PROXY_HOST"),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "target-host",
|
||||
Value: "127.0.0.1",
|
||||
Usage: "Target host address",
|
||||
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "ports-mapping",
|
||||
Usage: "Proxy and target ports (proxy:target)",
|
||||
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
||||
Required: true,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "session-timeout",
|
||||
Value: 20,
|
||||
Usage: "Session timeout in minutes",
|
||||
Sources: cli.EnvVars("Q3RCON_SESSION_TIMEOUT"),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "loglevel",
|
||||
Value: "info",
|
||||
Usage: "Log level (trace, debug, info, warn, error, fatal, panic)",
|
||||
Sources: cli.EnvVars("Q3RCON_LOGLEVEL"),
|
||||
},
|
||||
},
|
||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||
errChan := make(chan error)
|
||||
|
||||
hostAddr := fmt.Sprintf("%s:%s", proxyHost, proxyPort)
|
||||
proxyAddr := fmt.Sprintf("%s:%s", targetHost, targetPort)
|
||||
for mapping := range strings.SplitSeq(cmd.String("ports-mapping"), ";") {
|
||||
cfg := proxyConfig{
|
||||
proxyHost: cmd.String("proxy-host"),
|
||||
targetHost: cmd.String("target-host"),
|
||||
portsMapping: strings.Split(mapping, ":"),
|
||||
sessionTimeout: cmd.Int("session-timeout"),
|
||||
}
|
||||
|
||||
go initProxy(cfg, errChan)
|
||||
}
|
||||
|
||||
// We don't expect to receive any errors from the channels, but if we do, we log and return early.
|
||||
for err := range errChan {
|
||||
if err != nil {
|
||||
log.Errorf("Error: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initProxy(cfg proxyConfig, errChan chan error) {
|
||||
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
||||
|
||||
hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)
|
||||
proxyAddr := fmt.Sprintf("%s:%s", cfg.targetHost, targetPort)
|
||||
|
||||
c, err := udpproxy.New(
|
||||
hostAddr, proxyAddr,
|
||||
udpproxy.WithSessionTimeout(time.Duration(sessionTimeout)*time.Minute))
|
||||
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("q3rcon-proxy initialized: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
||||
|
||||
log.Fatal(c.ListenAndServe())
|
||||
errChan <- c.ListenAndServe()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.21 AS build_image
|
||||
FROM golang:1.24 AS build_image
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
26
docker/Taskfile.docker.yml
Normal file
26
docker/Taskfile.docker.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
IMAGE: q3rcon-proxy
|
||||
|
||||
tasks:
|
||||
build:
|
||||
desc: Build the Docker image
|
||||
cmds:
|
||||
- docker build -t {{.IMAGE}} -f docker/Dockerfile .
|
||||
dir: .
|
||||
|
||||
login:
|
||||
desc: Login to Github Container Registry
|
||||
cmds:
|
||||
- docker login ghcr.io -u {{.GHCR_USER}} --password-stdin <<< {{.GHCR_TOKEN}}
|
||||
internal: true
|
||||
|
||||
push:
|
||||
desc: Push the Docker image to Github Container Registry
|
||||
deps:
|
||||
- task: build
|
||||
- task: login
|
||||
cmds:
|
||||
- docker tag {{.IMAGE}} ghcr.io/{{.GHCR_USER}}/{{.IMAGE}}:latest
|
||||
- docker push ghcr.io/{{.GHCR_USER}}/{{.IMAGE}}:latest
|
||||
11
go.mod
11
go.mod
@@ -1,7 +1,12 @@
|
||||
module github.com/onyx-and-iris/q3rcon-proxy
|
||||
|
||||
go 1.18
|
||||
go 1.24.0
|
||||
|
||||
require github.com/sirupsen/logrus v1.9.3
|
||||
toolchain go1.24.1
|
||||
|
||||
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
require (
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/urfave/cli/v3 v3.3.2
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.32.0 // indirect
|
||||
|
||||
11
go.sum
11
go.sum
@@ -6,10 +6,15 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o=
|
||||
github.com/urfave/cli/v3 v3.3.2/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
Reference in New Issue
Block a user