mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-20 05:53:32 +00:00
Compare commits
10 Commits
f6ea67b88c
...
v1.8.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a83fd6573 | |||
| b494e6cf8f | |||
| 9be4344144 | |||
| 775979bfc8 | |||
| 6bffa14240 | |||
| 74493e6f61 | |||
| 51a0065e79 | |||
| f07a45c81b | |||
| a70fdecdbb | |||
| fc6ac8fa4e |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -26,3 +26,6 @@ go.work
|
||||
|
||||
# Added by goreleaser init:
|
||||
dist/
|
||||
|
||||
# env files
|
||||
.envrc
|
||||
@@ -6,7 +6,7 @@ run:
|
||||
go: '1.24'
|
||||
|
||||
linters:
|
||||
disable: [errcheck, godot, misspell]
|
||||
disable: [errcheck]
|
||||
enable:
|
||||
# Default enabled linters
|
||||
- errcheck # Check for unchecked errors
|
||||
|
||||
@@ -22,6 +22,7 @@ builds:
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
|
||||
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -11,6 +11,23 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
|
||||
- [x]
|
||||
|
||||
## [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
|
||||
|
||||
- *--version/-v* flag for printing the version of the CLI.
|
||||
|
||||
### Changed
|
||||
|
||||
- now using [charmbracelet/log][charmlog] package for logging.
|
||||
|
||||
## [1.7.0] - 2025-06-05
|
||||
|
||||
### Added
|
||||
@@ -99,3 +116,4 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
||||
- All source files for lilproxy including full commit history.
|
||||
|
||||
[logrus]: https://github.com/sirupsen/logrus
|
||||
[charmlog]: https://github.com/charmbracelet/log
|
||||
|
||||
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@ BIN_DIR := bin
|
||||
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
||||
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
||||
MACOS=$(BIN_DIR)/$(PROGRAM)_darwin_amd64
|
||||
VERSION=$(shell git log -n 1 --format=%h)
|
||||
VERSION=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
|
||||
21
README.md
21
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`.
|
||||
@@ -55,6 +64,8 @@ Acceptable values are:
|
||||
|
||||
If not set it will default to `info`.
|
||||
|
||||
---
|
||||
|
||||
### Special Thanks
|
||||
|
||||
[Dylan][user_link] For writing [lilproxy][lilproxy_url].
|
||||
|
||||
12
Taskfile.yml
12
Taskfile.yml
@@ -11,8 +11,8 @@ vars:
|
||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
||||
GIT_COMMIT:
|
||||
sh: git log -n 1 --format=%h
|
||||
VERSION:
|
||||
sh: 'git describe --tags $(git rev-list --tags --max-count=1)'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
@@ -42,19 +42,19 @@ tasks:
|
||||
build-windows:
|
||||
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}}/
|
||||
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./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}}/
|
||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||
internal: true
|
||||
|
||||
build-macos:
|
||||
desc: Build the q3rcon-proxy project for macOS
|
||||
cmds:
|
||||
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.Version={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
|
||||
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||
internal: true
|
||||
|
||||
test:
|
||||
@@ -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
|
||||
|
||||
@@ -5,16 +5,32 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
udpproxy "github.com/onyx-and-iris/q3rcon-proxy"
|
||||
)
|
||||
|
||||
var version string // Version holds the application version, set at build time using ldflags.
|
||||
|
||||
// versionFromBuild retrieves the version information from the build metadata.
|
||||
func versionFromBuild() string {
|
||||
if version != "" {
|
||||
return version
|
||||
}
|
||||
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "(unable to read version)"
|
||||
}
|
||||
return strings.Split(info.Main.Version, "-")[0]
|
||||
}
|
||||
|
||||
// proxyConfig holds the configuration for a single UDP proxy server.
|
||||
type proxyConfig struct {
|
||||
proxyHost string
|
||||
@@ -24,9 +40,14 @@ type proxyConfig struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
cli.VersionPrinter = func(cmd *cli.Command) {
|
||||
fmt.Printf("q3rcon-proxy version: %s\n", cmd.Root().Version)
|
||||
}
|
||||
|
||||
cmd := &cli.Command{
|
||||
Name: "q3rcon-proxy",
|
||||
Usage: "A Quake 3 RCON proxy server",
|
||||
Version: versionFromBuild(),
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "proxy-host",
|
||||
@@ -40,32 +61,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
|
||||
},
|
||||
@@ -94,7 +130,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"),
|
||||
@@ -111,10 +147,12 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
log.Fatal(cmd.Run(context.Background(), os.Args))
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// launchProxy initializes the UDP proxy server with the given configuration.
|
||||
// launchProxy initialises the UDP proxy server with the given configuration.
|
||||
// It listens on the specified proxy host and port, and forwards traffic to the target host and port.
|
||||
// server.ListenAndServe blocks until the server is stopped or an error occurs.
|
||||
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
||||
@@ -131,7 +169,7 @@ func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("q3rcon-proxy initialized: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
||||
log.Infof("q3rcon-proxy initialised: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
||||
|
||||
errChan <- server.ListenAndServe()
|
||||
}
|
||||
|
||||
20
go.mod
20
go.mod
@@ -5,8 +5,24 @@ go 1.24.0
|
||||
toolchain go1.24.1
|
||||
|
||||
require (
|
||||
github.com/sirupsen/logrus v1.9.4
|
||||
github.com/charmbracelet/log v0.4.2
|
||||
github.com/urfave/cli/v3 v3.6.2
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.41.0 // indirect
|
||||
require (
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/muesli/termenv v0.16.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/sys v0.41.0 // indirect
|
||||
)
|
||||
|
||||
34
go.sum
34
go.sum
@@ -1,13 +1,43 @@
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig=
|
||||
github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw=
|
||||
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
||||
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
|
||||
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8=
|
||||
github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
@@ -3,13 +3,13 @@ package udpproxy
|
||||
import (
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
// Option is a functional option type that allows us to configure the Client.
|
||||
type Option func(*Client)
|
||||
|
||||
// WithSessionTimeout is a functional option to set the session timeout
|
||||
// WithSessionTimeout is a functional option to set the session timeout.
|
||||
func WithSessionTimeout(timeout time.Duration) Option {
|
||||
return func(c *Client) {
|
||||
if timeout < time.Minute {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
type session struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package udpproxy
|
||||
|
||||
import "sync"
|
||||
|
||||
// sessionCache tracks connection sessions
|
||||
// sessionCache tracks connection sessions.
|
||||
type sessionCache struct {
|
||||
mu sync.RWMutex
|
||||
data map[string]*session
|
||||
@@ -15,7 +15,7 @@ func newSessionCache() sessionCache {
|
||||
}
|
||||
}
|
||||
|
||||
// read returns the associated session for an addr
|
||||
// read returns the associated session for an addr.
|
||||
func (sc *sessionCache) read(addr string) (*session, bool) {
|
||||
sc.mu.RLock()
|
||||
defer sc.mu.RUnlock()
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
// Client represents a UDP proxy server that forwards rcon and query packets between clients and a target server.
|
||||
@@ -87,7 +87,7 @@ func (c *Client) pruneSessions() {
|
||||
for _, session := range c.sessionCache.data {
|
||||
if time.Since(session.updateTime) > c.sessionTimeout {
|
||||
c.sessionCache.delete(session.caddr.String())
|
||||
log.Tracef("session for %s deleted", session.caddr)
|
||||
log.Debugf("session for %s deleted", session.caddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user