mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-03-03 07:39:11 +00:00
Compare commits
6 Commits
6bffa14240
...
225188bb70
| Author | SHA1 | Date | |
|---|---|---|---|
| 225188bb70 | |||
| 63cf99b217 | |||
| 7a83fd6573 | |||
| b494e6cf8f | |||
| 9be4344144 | |||
| 775979bfc8 |
@ -11,7 +11,14 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
|
||||
- [x]
|
||||
|
||||
## [1.7.3] - 2026-02-26
|
||||
## [1.8.0] - 2026-02-18
|
||||
|
||||
### Changed
|
||||
|
||||
- *--ports-mapping* flag has been replaced with *--port-map*, which may be called several times. See [Flags](https://github.com/onyx-and-iris/q3rcon-proxy?tab=readme-ov-file#flags).
|
||||
- This also affects the env variable which is now `Q3RCON_PORT_MAP`, see [Environment Variables](https://github.com/onyx-and-iris/q3rcon-proxy?tab=readme-ov-file#environment-variables)
|
||||
|
||||
## [1.7.3] - 2026-02-16
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
23
README.md
23
README.md
@ -6,6 +6,8 @@ A modification of [lilproxy][lilproxy_url] that forwards only Q3 rcon/query pack
|
||||
|
||||
Unfortunately the Q3Rcon engine ties the rcon port to the game servers public port used for client connections. This proxy will allow you to run rcon through a separate whitelisted port.
|
||||
|
||||
---
|
||||
|
||||
### Use
|
||||
|
||||
#### Flags
|
||||
@ -16,7 +18,7 @@ Unfortunately the Q3Rcon engine ties the rcon port to the game servers public po
|
||||
/usr/local/bin/q3rcon-proxy \
|
||||
--proxy-host=0.0.0.0 \
|
||||
--target-host=localhost \
|
||||
--ports-mapping=28961:28960 \
|
||||
--port-map=20000:28960 --port-map=20001:28961 --port-map=20002:28962 \
|
||||
--session-timeout=20 \
|
||||
--loglevel=debug
|
||||
```
|
||||
@ -27,18 +29,25 @@ 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_PORT_MAP`: 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:
|
||||
example .envrc:
|
||||
|
||||
```console
|
||||
export Q3RCON_PORTS_MAPPING="20000:28960;20001:28961;20002:28962"
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export Q3RCON_PROXY_HOST="0.0.0.0"
|
||||
export Q3RCON_TARGET_HOST="localhost"
|
||||
export Q3RCON_PORT_MAP="20000:28960,20001:28961,20002:28962"
|
||||
export Q3RCON_SESSION_TIMEOUT=20
|
||||
```
|
||||
|
||||
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`.
|
||||
@ -53,7 +62,9 @@ Acceptable values are:
|
||||
- `fatal`
|
||||
- `panic`
|
||||
|
||||
If not set it will default to `info`.
|
||||
It defaults to `info`.
|
||||
|
||||
---
|
||||
|
||||
### Special Thanks
|
||||
|
||||
|
||||
@ -74,6 +74,6 @@ tasks:
|
||||
go run ./cmd/{{.PROGRAM}} \
|
||||
--proxy-host=0.0.0.0 \
|
||||
--target-host=localhost \
|
||||
--ports-mapping=28961:28960 \
|
||||
--port-map=28961:28960 \
|
||||
--session-timeout=20 \
|
||||
--loglevel=debug
|
||||
|
||||
@ -4,6 +4,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
@ -61,32 +62,47 @@ func main() {
|
||||
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"),
|
||||
&cli.StringSliceFlag{
|
||||
Name: "port-map",
|
||||
Usage: "Ports mapping in the format proxyPort:targetPort (e.g., 27950:27960)",
|
||||
Sources: cli.EnvVars("Q3RCON_PORT_MAP"),
|
||||
Required: true,
|
||||
Action: func(_ context.Context, _ *cli.Command, v string) error {
|
||||
// Validate the ports mapping
|
||||
for mapping := range strings.SplitSeq(v, ";") {
|
||||
ports := strings.Split(mapping, ":")
|
||||
if len(ports) != 2 {
|
||||
return fmt.Errorf("invalid ports mapping: %s", mapping)
|
||||
Action: func(_ context.Context, cmd *cli.Command, v []string) error {
|
||||
// Validate the ports mapping format and values
|
||||
for _, mapping := range v {
|
||||
src, dst := func(m string) (string, string) {
|
||||
parts := strings.Split(m, ":")
|
||||
if len(parts) != 2 {
|
||||
return "", ""
|
||||
}
|
||||
proxyPort, err := strconv.Atoi(ports[0])
|
||||
if err != nil || proxyPort < 1 || proxyPort > 65535 {
|
||||
return fmt.Errorf("invalid proxy port: %s", ports[0])
|
||||
}
|
||||
targetPort, err := strconv.Atoi(ports[1])
|
||||
if err != nil || targetPort < 1 || targetPort > 65535 {
|
||||
return fmt.Errorf("invalid target port: %s", ports[1])
|
||||
}
|
||||
if proxyPort == targetPort {
|
||||
return parts[0], parts[1]
|
||||
}(mapping)
|
||||
|
||||
if src == "" || dst == "" {
|
||||
return fmt.Errorf(
|
||||
"proxy and target ports cannot be the same: %s",
|
||||
"invalid ports mapping: %s (expected format: proxyPort:targetPort)",
|
||||
mapping,
|
||||
)
|
||||
}
|
||||
n, err := strconv.Atoi(src)
|
||||
if err != nil || n <= 0 || n > 65535 {
|
||||
return fmt.Errorf("invalid proxy port: %s", src)
|
||||
}
|
||||
n, err = strconv.Atoi(dst)
|
||||
if err != nil || n <= 0 || n > 65535 {
|
||||
return fmt.Errorf("invalid target port: %s", dst)
|
||||
}
|
||||
if src == dst {
|
||||
return fmt.Errorf(
|
||||
"proxy port and target port cannot be the same: %s",
|
||||
src,
|
||||
)
|
||||
}
|
||||
log.Debugf(
|
||||
"Validated ports mapping: proxy port %s -> target port %s",
|
||||
src,
|
||||
dst,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@ -115,7 +131,7 @@ func main() {
|
||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||
errChan := make(chan error)
|
||||
|
||||
for mapping := range strings.SplitSeq(cmd.String("ports-mapping"), ";") {
|
||||
for _, mapping := range cmd.StringSlice("port-map") {
|
||||
cfg := proxyConfig{
|
||||
proxyHost: cmd.String("proxy-host"),
|
||||
targetHost: cmd.String("target-host"),
|
||||
@ -143,18 +159,18 @@ func main() {
|
||||
func launchProxy(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)
|
||||
proxyAddr := net.JoinHostPort(cfg.proxyHost, proxyPort)
|
||||
targetAddr := net.JoinHostPort(cfg.targetHost, targetPort)
|
||||
|
||||
server, err := udpproxy.New(
|
||||
hostAddr, proxyAddr,
|
||||
proxyAddr, targetAddr,
|
||||
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
||||
if err != nil {
|
||||
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("q3rcon-proxy initialised: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
||||
log.Infof("q3rcon-proxy initialised: [proxy] (%s) [target] (%s)", proxyAddr, targetAddr)
|
||||
|
||||
errChan <- server.ListenAndServe()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user