mirror of
https://github.com/onyx-and-iris/q3rcon.git
synced 2024-11-23 17:10:48 +00:00
34 lines
585 B
Go
34 lines
585 B
Go
package packet
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
const bufSz = 512
|
|
|
|
type Request struct {
|
|
magic []byte
|
|
password string
|
|
buf *bytes.Buffer
|
|
}
|
|
|
|
func NewRequest(password string) Request {
|
|
return Request{
|
|
magic: []byte{'\xff', '\xff', '\xff', '\xff'},
|
|
password: password,
|
|
buf: bytes.NewBuffer(make([]byte, bufSz)),
|
|
}
|
|
}
|
|
|
|
func (r Request) Header() []byte {
|
|
return append(r.magic, []byte("rcon")...)
|
|
}
|
|
|
|
func (r Request) Encode(cmd string) []byte {
|
|
r.buf.Reset()
|
|
r.buf.Write(r.Header())
|
|
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
|
|
return r.buf.Bytes()
|
|
}
|