mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2026-03-02 17:09:19 +00:00
unexport request, response methods
This commit is contained in:
parent
f74fbedacc
commit
b1161e1e97
12
q3rcon.go
12
q3rcon.go
@ -14,12 +14,12 @@ import (
|
||||
const respBufSiz = 2048
|
||||
|
||||
type encoder interface {
|
||||
Encode(cmd string) ([]byte, error)
|
||||
encode(cmd string) ([]byte, error)
|
||||
}
|
||||
|
||||
type decoder interface {
|
||||
IsValid(buf []byte) bool
|
||||
Decode(buf []byte) string
|
||||
isValid(buf []byte) bool
|
||||
decode(buf []byte) string
|
||||
}
|
||||
|
||||
type Rcon struct {
|
||||
@ -101,7 +101,7 @@ func (r Rcon) Send(cmdWithArgs string) (string, error) {
|
||||
|
||||
go r.listen(timeout, respChan, errChan)
|
||||
|
||||
encodedCmd, err := r.request.Encode(cmdWithArgs)
|
||||
encodedCmd, err := r.request.encode(cmdWithArgs)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error encoding command: %w", err)
|
||||
}
|
||||
@ -153,8 +153,8 @@ func (r Rcon) listen(timeout time.Duration, respChan chan<- string, errChan chan
|
||||
}
|
||||
}
|
||||
|
||||
if r.response.IsValid(respBuf[:rlen]) {
|
||||
sb.WriteString(r.response.Decode(respBuf[:rlen]))
|
||||
if r.response.isValid(respBuf[:rlen]) {
|
||||
sb.WriteString(r.response.decode(respBuf[:rlen]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ func newRequest(password string) request {
|
||||
}
|
||||
}
|
||||
|
||||
func (r request) Encode(cmd string) ([]byte, error) {
|
||||
func (r request) encode(cmd string) ([]byte, error) {
|
||||
if cmd == "" {
|
||||
return nil, errors.New("command cannot be empty")
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ func newResponse() response {
|
||||
return response{}
|
||||
}
|
||||
|
||||
func (r response) IsValid(buf []byte) bool {
|
||||
func (r response) isValid(buf []byte) bool {
|
||||
return len(buf) > len(responseHeader) && bytes.HasPrefix(buf, []byte(responseHeader))
|
||||
}
|
||||
|
||||
func (r response) Decode(buf []byte) string {
|
||||
func (r response) decode(buf []byte) string {
|
||||
return string(buf[len(responseHeader):])
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user