From 3e1088d625c60837276d107e33f25006422625e6 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 24 Nov 2024 13:13:07 +0000 Subject: [PATCH] {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() --- .gitignore | 2 +- q3rcon.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index c7ba0b7..cea079f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,4 @@ go.work.sum # env file .env -cmd/aeiou \ No newline at end of file +cmd/codrcon \ No newline at end of file diff --git a/q3rcon.go b/q3rcon.go index 3593842..6023392 100644 --- a/q3rcon.go +++ b/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 } }