Compare commits

...

4 Commits
v0.2.0 ... main

Author SHA1 Message Date
github-actions[bot]
8f252951ff chore: auto-update Go modules 2025-04-07 00:19:10 +00:00
35ffa55fb9 -loglevel now of string type
update Logging section in README.

upd CHANGELOG
2025-04-05 22:46:58 +01:00
github-actions[bot]
19f5ec4a76 chore: auto-update Go modules
Some checks failed
Auto-Update Go Modules / update-go-modules (push) Has been cancelled
2025-03-10 00:15:16 +00:00
github-actions[bot]
5173f32fde chore: auto-update Go modules
Some checks failed
Auto-Update Go Modules / update-go-modules (push) Has been cancelled
2025-02-24 00:17:41 +00:00
6 changed files with 47 additions and 14 deletions

View File

@ -11,6 +11,19 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x] - [x]
# [0.3.0] - 2025-04-05
### Changed
- `-loglevel` flag is now of type string. It accepts any one of trace, debug, info, warn, error, fatal or panic.
- It defaults to warn.
# [0.2.0] - 2025-02-03
### Added
- If neither the interactive flag is passed or any command line arguments then a *rcon status* command will be run.
# [0.1.0] - 2024-11-29 # [0.1.0] - 2024-11-29
### Changed ### Changed

View File

@ -109,7 +109,7 @@ Arguments following the flags will be sent as rcon commands. You may send multip
Pass `interactive (-i shorthand)` flag to enable interactive mode, for example: Pass `interactive (-i shorthand)` flag to enable interactive mode, for example:
``` ```bash
q3rcon -h=localhost -p=30000 -r="rconpassword" -i q3rcon -h=localhost -p=30000 -r="rconpassword" -i
``` ```
@ -123,16 +123,31 @@ Since you can include the q3rcon package into your own package you can easily ma
## Logging ## Logging
Log level may be set by passing the `-l` flag with a number from 0 up to 6 where The `-loglevel` flag allows you to control the verbosity of the application's logging output.
0 = Panic, 1 = Fatal, 2 = Error, 3 = Warning, 4 = Info, 5 = Debug, 6 = Trace Acceptable values for this flag are:
[status]: ./img/status.png - `trace`
[mapname]: ./img/mapname.png - `debug`
- `info`
- `warn`
- `error`
- `fatal`
- `panic`
For example, to set the log level to `debug`, you can use:
```bash
q3rcon -p=28960 -r="rconpassword" -loglevel=debug -i
```
The default log level is `warn` if the flag is not specified.
## Further Notes ## Further Notes
This rcon client is fully compatible with the [Q3 Rcon Proxy][q3rcon-proxy] package. This rcon client is fully compatible with the [Q3 Rcon Proxy][q3rcon-proxy] package.
[status]: ./img/status.png
[mapname]: ./img/mapname.png
[q3rcon-proxy]: https://github.com/onyx-and-iris/q3rcon-proxy/tree/dev [q3rcon-proxy]: https://github.com/onyx-and-iris/q3rcon-proxy/tree/dev

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"slices"
"strings" "strings"
"github.com/onyx-and-iris/q3rcon" "github.com/onyx-and-iris/q3rcon"
@ -25,7 +24,7 @@ func main() {
port int port int
rconpass string rconpass string
interactive bool interactive bool
loglevel int loglevel string
) )
flag.StringVar(&host, "host", "localhost", "hostname of the gameserver") flag.StringVar(&host, "host", "localhost", "hostname of the gameserver")
@ -38,13 +37,16 @@ func main() {
flag.BoolVar(&interactive, "interactive", false, "run in interactive mode") flag.BoolVar(&interactive, "interactive", false, "run in interactive mode")
flag.BoolVar(&interactive, "i", false, "run in interactive mode") flag.BoolVar(&interactive, "i", false, "run in interactive mode")
flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "log level") flag.StringVar(&loglevel, "loglevel", "warn", "log level")
flag.IntVar(&loglevel, "l", int(log.WarnLevel), "log level (shorthand)") flag.StringVar(&loglevel, "l", "warn", "log level (shorthand)")
flag.Parse() flag.Parse()
if slices.Contains(log.AllLevels, log.Level(loglevel)) { level, err := log.ParseLevel(loglevel)
log.SetLevel(log.Level(loglevel)) if err != nil {
exitOnError(fmt.Errorf("invalid log level: %s", loglevel))
} }
log.SetLevel(level)
if port < 1024 || port > 65535 { if port < 1024 || port > 65535 {
exitOnError(fmt.Errorf("invalid port value, got: (%d) expected: in range 1024-65535", port)) exitOnError(fmt.Errorf("invalid port value, got: (%d) expected: in range 1024-65535", port))

2
go.mod
View File

@ -4,4 +4,4 @@ go 1.23.0
require github.com/sirupsen/logrus v1.9.3 require github.com/sirupsen/logrus v1.9.3
require golang.org/x/sys v0.25.0 // indirect require golang.org/x/sys v0.32.0 // indirect

4
go.sum
View File

@ -9,8 +9,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -3,6 +3,8 @@ package packet
import ( import (
"bytes" "bytes"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
) )
const bufSz = 512 const bufSz = 512
@ -29,5 +31,6 @@ func (r Request) Encode(cmd string) []byte {
r.buf.Reset() r.buf.Reset()
r.buf.Write(r.Header()) r.buf.Write(r.Header())
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd)) r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
log.Tracef("Encoded request: %s", r.buf.String())
return r.buf.Bytes() return r.buf.Bytes()
} }