mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2026-04-18 15:53:33 +00:00
remove internal packages, move everything into q3rcon
{request}.buf initialised with 0 length.
encoder, decoder interfaces added.
This commit is contained in:
35
request.go
Normal file
35
request.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package q3rcon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
bufSz = 1024
|
||||
requestHeader = "\xff\xff\xff\xffrcon"
|
||||
)
|
||||
|
||||
type request struct {
|
||||
password string
|
||||
buf *bytes.Buffer
|
||||
}
|
||||
|
||||
func newRequest(password string) request {
|
||||
return request{
|
||||
password: password,
|
||||
buf: bytes.NewBuffer(make([]byte, 0, bufSz)),
|
||||
}
|
||||
}
|
||||
|
||||
func (r request) Encode(cmd string) ([]byte, error) {
|
||||
if cmd == "" {
|
||||
return nil, errors.New("command cannot be empty")
|
||||
}
|
||||
|
||||
r.buf.Reset()
|
||||
r.buf.WriteString(requestHeader)
|
||||
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
|
||||
return r.buf.Bytes(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user