mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2025-04-19 20:13:49 +01:00
Compare commits
No commits in common. "a1ecf85cbbba45508f57fe9f64bf61aebe2008e7" and "b0a6ba818023186d918abc4b9425d97731b8d61f" have entirely different histories.
a1ecf85cbb
...
b0a6ba8180
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,7 +7,6 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
bin/
|
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
32
CHANGELOG.md
32
CHANGELOG.md
@ -11,38 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
## [1.4.0] - 2024-11-29
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- new environment variable `Q3RCON_TARGET_HOST` for setting the host the gameserver is on.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- environment variable `Q3RCON_HOST` renamed to `Q3RCON_PROXY_HOST`
|
|
||||||
- environment variable `Q3RCON_PROXY` renamed to `Q3RCON_TARGET_PORTS`.
|
|
||||||
- default session timeout changed from 5 to 20 minutes.
|
|
||||||
|
|
||||||
## [1.3.0] - 2024-10-23
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Add sessionCache for tracking sessions.
|
|
||||||
- Functional option `WithStaleTimeout` renamed to `WithSessionTimeout`
|
|
||||||
|
|
||||||
## [1.2.0] - 2024-10-19
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- optional function `WithStaleTimeout`, use it to configure the session timeout value.
|
|
||||||
- it defaults to 5 minutes.
|
|
||||||
|
|
||||||
## [1.1.0] - 2024-09-28
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- connection (challenge) requests are now logged.
|
|
||||||
|
|
||||||
## [0.6.0] - 2024-03-21
|
## [0.6.0] - 2024-03-21
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
42
Makefile
42
Makefile
@ -1,40 +1,2 @@
|
|||||||
program = q3rcon-proxy
|
go-build:
|
||||||
|
go build ./cmd/q3rcon-proxy/
|
||||||
GO = @go
|
|
||||||
BIN_DIR := bin
|
|
||||||
|
|
||||||
WINDOWS=$(BIN_DIR)/$(program)_windows_amd64.exe
|
|
||||||
LINUX=$(BIN_DIR)/$(program)_linux_amd64
|
|
||||||
VERSION=$(shell git describe --tags --always --long --dirty)
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := build
|
|
||||||
|
|
||||||
.PHONY: fmt vet build windows linux test clean
|
|
||||||
fmt:
|
|
||||||
$(GO) fmt ./...
|
|
||||||
|
|
||||||
vet: fmt
|
|
||||||
$(GO) vet ./...
|
|
||||||
|
|
||||||
build: vet windows linux | $(BIN_DIR)
|
|
||||||
@echo version: $(VERSION)
|
|
||||||
|
|
||||||
windows: $(WINDOWS)
|
|
||||||
|
|
||||||
linux: $(LINUX)
|
|
||||||
|
|
||||||
|
|
||||||
$(WINDOWS):
|
|
||||||
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/q3rcon-proxy/
|
|
||||||
|
|
||||||
$(LINUX):
|
|
||||||
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/q3rcon-proxy/
|
|
||||||
|
|
||||||
test:
|
|
||||||
$(GO) test ./...
|
|
||||||
|
|
||||||
$(BIN_DIR):
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -rv $(BIN_DIR)
|
|
@ -21,53 +21,43 @@ func main() {
|
|||||||
log.SetLevel(log.Level(logLevel))
|
log.SetLevel(log.Level(logLevel))
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyHost := os.Getenv("Q3RCON_PROXY_HOST")
|
proxies := os.Getenv("Q3RCON_PROXY")
|
||||||
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 == "" {
|
if proxies == "" {
|
||||||
log.Fatal("env Q3RCON_TARGET_PORTS required")
|
log.Fatal("env Q3RCON_PROXY required")
|
||||||
|
}
|
||||||
|
|
||||||
|
host := os.Getenv("Q3RCON_HOST")
|
||||||
|
if host == "" {
|
||||||
|
host = "0.0.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionTimeout, err := getEnvInt("Q3RCON_SESSION_TIMEOUT")
|
sessionTimeout, err := getEnvInt("Q3RCON_SESSION_TIMEOUT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to parse Q3RCON_SESSION_TIMEOUT: %s", err.Error())
|
log.Fatalf("unable to parse Q3RCON_SESSION_TIMEOUT: %s", err.Error())
|
||||||
}
|
}
|
||||||
if sessionTimeout == 0 {
|
|
||||||
sessionTimeout = 20
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, proxy := range strings.Split(proxies, ";") {
|
for _, proxy := range strings.Split(proxies, ";") {
|
||||||
go start(proxyHost, targetHost, proxy, sessionTimeout)
|
go start(host, proxy, sessionTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-make(chan struct{})
|
<-make(chan int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(proxyHost, targetHost, ports string, sessionTimeout int) {
|
func start(host, proxy string, sessionTimeout int) {
|
||||||
proxyPort, targetPort := func() (string, string) {
|
port, target := func() (string, string) {
|
||||||
x := strings.Split(ports, ":")
|
x := strings.Split(proxy, ":")
|
||||||
return x[0], x[1]
|
return x[0], x[1]
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hostAddr := fmt.Sprintf("%s:%s", proxyHost, proxyPort)
|
|
||||||
proxyAddr := fmt.Sprintf("%s:%s", targetHost, targetPort)
|
|
||||||
|
|
||||||
c, err := udpproxy.New(
|
c, err := udpproxy.New(
|
||||||
hostAddr, proxyAddr,
|
fmt.Sprintf("%s:%s", host, port),
|
||||||
|
fmt.Sprintf("127.0.0.1:%s", target),
|
||||||
udpproxy.WithSessionTimeout(time.Duration(sessionTimeout)*time.Minute))
|
udpproxy.WithSessionTimeout(time.Duration(sessionTimeout)*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("q3rcon-proxy initialized: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
log.Printf("q3rcon-proxy initialized: [proxy] (%s:%s) [target] (127.0.0.1:%s)", host, port, target)
|
||||||
|
|
||||||
log.Fatal(c.ListenAndServe())
|
log.Fatal(c.ListenAndServe())
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ type Option func(*Client)
|
|||||||
func WithSessionTimeout(timeout time.Duration) Option {
|
func WithSessionTimeout(timeout time.Duration) Option {
|
||||||
return func(c *Client) {
|
return func(c *Client) {
|
||||||
if timeout < time.Minute {
|
if timeout < time.Minute {
|
||||||
log.Warnf("cannot set stale session timeout to less than 1 minute.. defaulting to 20 minutes")
|
log.Warnf("cannot set stale session timeout to less than 1 minute.. defaulting to 5 minutes")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +32,8 @@ type Client struct {
|
|||||||
sessionTimeout time.Duration
|
sessionTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(proxy, target string, options ...Option) (*Client, error) {
|
func New(port, target string, options ...Option) (*Client, error) {
|
||||||
laddr, err := net.ResolveUDPAddr("udp", proxy)
|
laddr, err := net.ResolveUDPAddr("udp", port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func New(proxy, target string, options ...Option) (*Client, error) {
|
|||||||
laddr: laddr,
|
laddr: laddr,
|
||||||
raddr: raddr,
|
raddr: raddr,
|
||||||
sessionCache: newSessionCache(),
|
sessionCache: newSessionCache(),
|
||||||
sessionTimeout: 20 * time.Minute,
|
sessionTimeout: 5 * time.Minute,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range options {
|
for _, o := range options {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user