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
|
const respBufSiz = 2048
|
||||||
|
|
||||||
type encoder interface {
|
type encoder interface {
|
||||||
Encode(cmd string) ([]byte, error)
|
encode(cmd string) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type decoder interface {
|
type decoder interface {
|
||||||
IsValid(buf []byte) bool
|
isValid(buf []byte) bool
|
||||||
Decode(buf []byte) string
|
decode(buf []byte) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rcon struct {
|
type Rcon struct {
|
||||||
@ -101,7 +101,7 @@ func (r Rcon) Send(cmdWithArgs string) (string, error) {
|
|||||||
|
|
||||||
go r.listen(timeout, respChan, errChan)
|
go r.listen(timeout, respChan, errChan)
|
||||||
|
|
||||||
encodedCmd, err := r.request.Encode(cmdWithArgs)
|
encodedCmd, err := r.request.encode(cmdWithArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error encoding command: %w", err)
|
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]) {
|
if r.response.isValid(respBuf[:rlen]) {
|
||||||
sb.WriteString(r.response.Decode(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 == "" {
|
if cmd == "" {
|
||||||
return nil, errors.New("command cannot be empty")
|
return nil, errors.New("command cannot be empty")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,10 @@ func newResponse() response {
|
|||||||
return 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))
|
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):])
|
return string(buf[len(responseHeader):])
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user