5 Commits

Author SHA1 Message Date
35ffa55fb9 -loglevel now of string type
Some checks failed
Auto-Update Go Modules / update-go-modules (push) Has been cancelled
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
7782e7f8bf add update and release actions
Some checks failed
Auto-Update Go Modules / update-go-modules (push) Has been cancelled
2025-02-17 13:31:09 +00:00
09f316e5f4 run through formatter 2025-02-07 23:25:29 +00:00
11 changed files with 182 additions and 26 deletions

31
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: goreleaser
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

30
.github/workflows/update-go-modules.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Auto-Update Go Modules
on:
schedule:
- cron: "0 0 * * 1" # Runs every Monday at midnight
jobs:
update-go-modules:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Update Dependencies
run: |
go get -u ./...
go mod tidy
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add go.mod go.sum
git commit -m "chore: auto-update Go modules"
git push

3
.gitignore vendored
View File

@@ -25,4 +25,7 @@ go.work.sum
# env file # env file
.env .env
# Added by goreleaser init:
dist/
cmd/codrcon cmd/codrcon

55
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,55 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- main: ./cmd/q3rcon/
env:
- CGO_ENABLED=0
goos:
- linux
- windows
goarch:
- amd64
archives:
- formats: ['tar.gz']
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
formats: ['zip']
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
footer: >-
---
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

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

@@ -12,40 +12,44 @@ vars:
tasks: tasks:
default: default:
desc: "Build the q3rcon project" desc: Build the q3rcon project
deps: [build] cmds:
- task: build
build: build:
desc: "Build the q3rcon project" desc: Build the q3rcon project
deps: [vet, build-windows, build-linux] deps: [vet]
cmds:
- task: build-windows
- task: build-linux
vet: vet:
desc: "Vet the code" desc: Vet the code
deps: [fmt] deps: [fmt]
cmds: cmds:
- go vet ./... - go vet ./...
fmt: fmt:
desc: "Fmt the code" desc: Fmt the code
cmds: cmds:
- go fmt ./... - go fmt ./...
build-windows: build-windows:
desc: "Build the q3rcon project for Windows" desc: Build the q3rcon project for Windows
cmds: 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={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
build-linux: build-linux:
desc: "Build the q3rcon project for Linux" desc: Build the q3rcon project for Linux
cmds: 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={{.GIT_COMMIT}}" ./cmd/{{.PROGRAM}}/
test: test:
desc: "Run tests" desc: Run tests
cmds: cmds:
- go test ./... - go test ./...
clean: clean:
desc: "Clean the build artifacts" desc: Clean the build artifacts
cmds: cmds:
- '{{.SHELL}} rm -r {{.BIN_DIR}}' - '{{.SHELL}} rm -r {{.BIN_DIR}}'

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.31.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.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.31.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()
} }