Compare commits

..

No commits in common. "cbc8ee5543e3923128aac1ea82e174c36d215341" and "65ab17b9c9bc50e4fc7bf1db56457b79a215e232" have entirely different histories.

3 changed files with 6 additions and 22 deletions

2
.gitignore vendored
View File

@ -25,4 +25,4 @@ go.work.sum
# env file # env file
.env .env
cmd/codrcon cmd/aeiou

View File

@ -11,17 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x] - [x]
# [0.0.3] - 2024-11-24
### Changed
- {Rcon}.login is no longer exported since it's called internally by the constructor.
- When checking the timeouts map the cmd is split from its arguments. This allows setting a timeout value for all `map mp_` for example.
### Added
- Timeout values for commands in the timeouts map are now logged at Debug level.
# [0.0.1] - 2024-11-04 # [0.0.1] - 2024-11-04
### Added ### Added

View File

@ -7,8 +7,6 @@ import (
"strings" "strings"
"time" "time"
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/q3rcon/internal/conn" "github.com/onyx-and-iris/q3rcon/internal/conn"
"github.com/onyx-and-iris/q3rcon/internal/packet" "github.com/onyx-and-iris/q3rcon/internal/packet"
) )
@ -49,14 +47,14 @@ func New(host string, port int, password string, options ...Option) (*Rcon, erro
o(r) o(r)
} }
if err = r.login(); err != nil { if err = r.Login(); err != nil {
return nil, err return nil, err
} }
return r, nil return r, nil
} }
func (r Rcon) login() error { func (r Rcon) Login() error {
timeout := time.After(r.loginTimeout) timeout := time.After(r.loginTimeout)
for { for {
select { select {
@ -80,13 +78,10 @@ func (r Rcon) login() error {
} }
} }
func (r Rcon) Send(cmdWithArgs string) (string, error) { func (r Rcon) Send(cmd string) (string, error) {
cmd, _, _ := strings.Cut(string(cmdWithArgs), " ")
timeout, ok := r.timeouts[cmd] timeout, ok := r.timeouts[cmd]
if !ok { if !ok {
timeout = r.defaultTimeout timeout = r.defaultTimeout
} else {
log.Debugf("%s in timeouts map, using timeout %v", cmd, timeout)
} }
respChan := make(chan string) respChan := make(chan string)
@ -94,7 +89,7 @@ func (r Rcon) Send(cmdWithArgs string) (string, error) {
go r.listen(timeout, respChan, errChan) go r.listen(timeout, respChan, errChan)
_, err := r.conn.Write(r.request.Encode(cmdWithArgs)) _, err := r.conn.Write(r.request.Encode(cmd))
if err != nil { if err != nil {
return "", err return "", err
} }
@ -103,7 +98,7 @@ func (r Rcon) Send(cmdWithArgs string) (string, error) {
case err := <-errChan: case err := <-errChan:
return "", err return "", err
case resp := <-respChan: case resp := <-respChan:
return resp, nil return strings.TrimPrefix(resp, string(r.response.Header())), nil
} }
} }