mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2026-04-09 16:43:30 +00:00
Compare commits
3 Commits
v1.3.0
...
b0a6ba8180
| Author | SHA1 | Date | |
|---|---|---|---|
| b0a6ba8180 | |||
| 9b4a05c0f4 | |||
| bfe31c28c8 |
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
*
|
||||
!cmd/
|
||||
!pkg/
|
||||
|
||||
!go.mod
|
||||
!go.sum
|
||||
10
README.md
10
README.md
@@ -8,12 +8,12 @@ Unfortunately the Q3Rcon engine ties the rcon port to the game servers public po
|
||||
|
||||
### Use
|
||||
|
||||
Run one or multiple rcon proxies by setting an environment variable `Q3RCON_PROXY`
|
||||
Run one or multiple rcon proxies by setting an environment variable `Q3RCON_TARGET_PORTS`
|
||||
|
||||
for example:
|
||||
|
||||
```bash
|
||||
export Q3RCON_PROXY="20000:28960;20001:28961;20002:28962"
|
||||
export Q3RCON_TARGET_PORTS="20000:28960;20001:28961;20002:28962"
|
||||
```
|
||||
|
||||
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.
|
||||
@@ -32,3 +32,9 @@ Set the log level with environment variable `Q3RCON_LOGLEVEL`:
|
||||
|
||||
[lilproxy_url]: https://github.com/dgparker/lilproxy
|
||||
[user_link]: https://github.com/dgparker
|
||||
|
||||
### Further Notes
|
||||
|
||||
For a compatible rcon client also written in Go consider checking out the [Q3 Rcon][q3rcon] package.
|
||||
|
||||
[q3rcon]: https://github.com/onyx-and-iris/q3rcon
|
||||
@@ -15,8 +15,8 @@ func newSessionCache() sessionCache {
|
||||
}
|
||||
}
|
||||
|
||||
// Read returns the associated session for an addr
|
||||
func (sc *sessionCache) Read(addr string) (*session, bool) {
|
||||
// read returns the associated session for an addr
|
||||
func (sc *sessionCache) read(addr string) (*session, bool) {
|
||||
sc.mu.RLock()
|
||||
defer sc.mu.RUnlock()
|
||||
|
||||
@@ -24,16 +24,16 @@ func (sc *sessionCache) Read(addr string) (*session, bool) {
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// Upsert overrides the session for a given addr.
|
||||
func (sc *sessionCache) Upsert(addr string, session *session) {
|
||||
// insert adds a session for a given addr.
|
||||
func (sc *sessionCache) insert(addr string, session *session) {
|
||||
sc.mu.Lock()
|
||||
defer sc.mu.Unlock()
|
||||
|
||||
sc.data[addr] = session
|
||||
}
|
||||
|
||||
// Delete removes the session for the given addr.
|
||||
func (sc *sessionCache) Delete(addr string) {
|
||||
// delete removes the session for the given addr.
|
||||
func (sc *sessionCache) delete(addr string) {
|
||||
sc.mu.Lock()
|
||||
defer sc.mu.Unlock()
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func (c *Client) ListenAndServe() error {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
session, ok := c.sessionCache.Read(caddr.String())
|
||||
session, ok := c.sessionCache.read(caddr.String())
|
||||
if !ok {
|
||||
session, err = newSession(caddr, c.raddr, c.proxyConn)
|
||||
if err != nil {
|
||||
@@ -81,7 +81,7 @@ func (c *Client) ListenAndServe() error {
|
||||
continue
|
||||
}
|
||||
|
||||
c.sessionCache.Upsert(caddr.String(), session)
|
||||
c.sessionCache.insert(caddr.String(), session)
|
||||
}
|
||||
|
||||
go session.proxyTo(buf[:n])
|
||||
@@ -94,7 +94,7 @@ func (c *Client) pruneSessions() {
|
||||
for range ticker.C {
|
||||
for _, session := range c.sessionCache.data {
|
||||
if time.Since(session.updateTime) > c.sessionTimeout {
|
||||
c.sessionCache.Delete(session.caddr.String())
|
||||
c.sessionCache.delete(session.caddr.String())
|
||||
log.Tracef("session for %s deleted", session.caddr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user