Compare commits

...

2 Commits

Author SHA1 Message Date
cbc8ee5543 add section 0.0.3 to CHANGELOG 2024-11-24 13:18:49 +00:00
3e1088d625 {Rcon}.login no longer exported.
split the cmd from its args when checking timeout map.

remove final TrimPrefix, it's already handled in {Rcon}.listen()
2024-11-24 13:13:07 +00:00
3 changed files with 22 additions and 6 deletions

2
.gitignore vendored
View File

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

View File

@ -11,6 +11,17 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [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
### Added

View File

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