mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-02-16 08:47:49 +00:00
enable revive linter
This commit is contained in:
parent
d18834b290
commit
f6ea67b88c
@ -6,7 +6,7 @@ run:
|
|||||||
go: '1.24'
|
go: '1.24'
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable: [errcheck, godot, misspell, revive]
|
disable: [errcheck, godot, misspell]
|
||||||
enable:
|
enable:
|
||||||
# Default enabled linters
|
# Default enabled linters
|
||||||
- errcheck # Check for unchecked errors
|
- errcheck # Check for unchecked errors
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// Package main implements a command-line application for a Quake 3 RCON proxy server.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -44,7 +45,7 @@ func main() {
|
|||||||
Usage: "Proxy and target ports (proxy:target)",
|
Usage: "Proxy and target ports (proxy:target)",
|
||||||
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
||||||
Required: true,
|
Required: true,
|
||||||
Action: func(ctx context.Context, cmd *cli.Command, v string) error {
|
Action: func(_ context.Context, _ *cli.Command, v string) error {
|
||||||
// Validate the ports mapping
|
// Validate the ports mapping
|
||||||
for mapping := range strings.SplitSeq(v, ";") {
|
for mapping := range strings.SplitSeq(v, ";") {
|
||||||
ports := strings.Split(mapping, ":")
|
ports := strings.Split(mapping, ":")
|
||||||
|
|||||||
13
udpproxy.go
13
udpproxy.go
@ -1,12 +1,16 @@
|
|||||||
|
// Package udpproxy implements a simple UDP proxy server that forwards rcon and query packets between clients and a target server.
|
||||||
package udpproxy
|
package udpproxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Client represents a UDP proxy server that forwards rcon and query packets between clients and a target server.
|
||||||
|
// It maintains a session cache to manage client sessions and handles packet forwarding between clients and the target server.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
laddr *net.UDPAddr
|
laddr *net.UDPAddr
|
||||||
raddr *net.UDPAddr
|
raddr *net.UDPAddr
|
||||||
@ -17,15 +21,16 @@ type Client struct {
|
|||||||
sessionTimeout time.Duration
|
sessionTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new Client with the specified proxy and target addresses, and applies any provided options.
|
||||||
func New(proxy, target string, options ...Option) (*Client, error) {
|
func New(proxy, target string, options ...Option) (*Client, error) {
|
||||||
laddr, err := net.ResolveUDPAddr("udp", proxy)
|
laddr, err := net.ResolveUDPAddr("udp", proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("invalid proxy address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
raddr, err := net.ResolveUDPAddr("udp", target)
|
raddr, err := net.ResolveUDPAddr("udp", target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("invalid target address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &Client{
|
c := &Client{
|
||||||
@ -42,11 +47,13 @@ func New(proxy, target string, options ...Option) (*Client, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListenAndServe starts the UDP proxy server and listens for incoming packets from clients.
|
||||||
|
// It reads packets from the proxy connection, checks for existing sessions, and forwards packets to the target server.
|
||||||
func (c *Client) ListenAndServe() error {
|
func (c *Client) ListenAndServe() error {
|
||||||
var err error
|
var err error
|
||||||
c.proxyConn, err = net.ListenUDP("udp", c.laddr)
|
c.proxyConn, err = net.ListenUDP("udp", c.laddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to listen on proxy address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go c.pruneSessions()
|
go c.pruneSessions()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user