mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2025-04-11 08:33:49 +01:00
Compare commits
2 Commits
65ab17b9c9
...
cbc8ee5543
Author | SHA1 | Date | |
---|---|---|---|
cbc8ee5543 | |||
3e1088d625 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,4 +25,4 @@ go.work.sum
|
||||
# env file
|
||||
.env
|
||||
|
||||
cmd/aeiou
|
||||
cmd/codrcon
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -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
|
||||
|
15
q3rcon.go
15
q3rcon.go
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user