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]
|
- [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
|
### 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.
|
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
|
### Use
|
||||||
|
|
||||||
#### Flags
|
#### Flags
|
||||||
@ -16,7 +18,7 @@ Unfortunately the Q3Rcon engine ties the rcon port to the game servers public po
|
|||||||
/usr/local/bin/q3rcon-proxy \
|
/usr/local/bin/q3rcon-proxy \
|
||||||
--proxy-host=0.0.0.0 \
|
--proxy-host=0.0.0.0 \
|
||||||
--target-host=localhost \
|
--target-host=localhost \
|
||||||
--ports-mapping=28961:28960 \
|
--port-map=20000:28960 --port-map=20001:28961 --port-map=20002:28962 \
|
||||||
--session-timeout=20 \
|
--session-timeout=20 \
|
||||||
--loglevel=debug
|
--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_PROXY_HOST`: The host the proxy server sits on.
|
||||||
- `Q3RCON_TARGET_HOST`: The host the game servers sit 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_SESSION_TIMEOUT`: Timeout in seconds for each udp session.
|
||||||
- `Q3RCON_LOGLEVEL`: The application's logging level (see [Logging][logging]).
|
- `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
|
```bash
|
||||||
export Q3RCON_PORTS_MAPPING="20000:28960;20001:28961;20002:28962"
|
#!/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.
|
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
|
### Logging
|
||||||
|
|
||||||
Set the log level with environment variable `Q3RCON_LOGLEVEL`.
|
Set the log level with environment variable `Q3RCON_LOGLEVEL`.
|
||||||
@ -53,7 +62,9 @@ Acceptable values are:
|
|||||||
- `fatal`
|
- `fatal`
|
||||||
- `panic`
|
- `panic`
|
||||||
|
|
||||||
If not set it will default to `info`.
|
It defaults to `info`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Special Thanks
|
### Special Thanks
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,6 @@ tasks:
|
|||||||
go run ./cmd/{{.PROGRAM}} \
|
go run ./cmd/{{.PROGRAM}} \
|
||||||
--proxy-host=0.0.0.0 \
|
--proxy-host=0.0.0.0 \
|
||||||
--target-host=localhost \
|
--target-host=localhost \
|
||||||
--ports-mapping=28961:28960 \
|
--port-map=28961:28960 \
|
||||||
--session-timeout=20 \
|
--session-timeout=20 \
|
||||||
--loglevel=debug
|
--loglevel=debug
|
||||||
|
|||||||
@ -4,6 +4,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -61,32 +62,47 @@ func main() {
|
|||||||
Usage: "Target host address",
|
Usage: "Target host address",
|
||||||
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "ports-mapping",
|
Name: "port-map",
|
||||||
Usage: "Proxy and target ports (proxy:target)",
|
Usage: "Ports mapping in the format proxyPort:targetPort (e.g., 27950:27960)",
|
||||||
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
Sources: cli.EnvVars("Q3RCON_PORT_MAP"),
|
||||||
Required: true,
|
Required: true,
|
||||||
Action: func(_ context.Context, _ *cli.Command, v string) error {
|
Action: func(_ context.Context, cmd *cli.Command, v []string) error {
|
||||||
// Validate the ports mapping
|
// Validate the ports mapping format and values
|
||||||
for mapping := range strings.SplitSeq(v, ";") {
|
for _, mapping := range v {
|
||||||
ports := strings.Split(mapping, ":")
|
src, dst := func(m string) (string, string) {
|
||||||
if len(ports) != 2 {
|
parts := strings.Split(m, ":")
|
||||||
return fmt.Errorf("invalid ports mapping: %s", mapping)
|
if len(parts) != 2 {
|
||||||
|
return "", ""
|
||||||
}
|
}
|
||||||
proxyPort, err := strconv.Atoi(ports[0])
|
return parts[0], parts[1]
|
||||||
if err != nil || proxyPort < 1 || proxyPort > 65535 {
|
}(mapping)
|
||||||
return fmt.Errorf("invalid proxy port: %s", ports[0])
|
|
||||||
}
|
if src == "" || dst == "" {
|
||||||
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 fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"proxy and target ports cannot be the same: %s",
|
"invalid ports mapping: %s (expected format: proxyPort:targetPort)",
|
||||||
mapping,
|
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
|
return nil
|
||||||
},
|
},
|
||||||
@ -115,7 +131,7 @@ func main() {
|
|||||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
for mapping := range strings.SplitSeq(cmd.String("ports-mapping"), ";") {
|
for _, mapping := range cmd.StringSlice("port-map") {
|
||||||
cfg := proxyConfig{
|
cfg := proxyConfig{
|
||||||
proxyHost: cmd.String("proxy-host"),
|
proxyHost: cmd.String("proxy-host"),
|
||||||
targetHost: cmd.String("target-host"),
|
targetHost: cmd.String("target-host"),
|
||||||
@ -143,18 +159,18 @@ func main() {
|
|||||||
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
||||||
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
||||||
|
|
||||||
hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)
|
proxyAddr := net.JoinHostPort(cfg.proxyHost, proxyPort)
|
||||||
proxyAddr := fmt.Sprintf("%s:%s", cfg.targetHost, targetPort)
|
targetAddr := net.JoinHostPort(cfg.targetHost, targetPort)
|
||||||
|
|
||||||
server, err := udpproxy.New(
|
server, err := udpproxy.New(
|
||||||
hostAddr, proxyAddr,
|
proxyAddr, targetAddr,
|
||||||
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
||||||
return
|
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()
|
errChan <- server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user