2024-11-04 13:33:53 +00:00
|
|
|
package packet
|
|
|
|
|
2024-11-08 15:31:30 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const bufSz = 512
|
2024-11-04 13:33:53 +00:00
|
|
|
|
|
|
|
type Request struct {
|
|
|
|
magic []byte
|
|
|
|
password string
|
2024-11-08 15:31:30 +00:00
|
|
|
buf *bytes.Buffer
|
2024-11-04 13:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRequest(password string) Request {
|
|
|
|
return Request{
|
|
|
|
magic: []byte{'\xff', '\xff', '\xff', '\xff'},
|
|
|
|
password: password,
|
2024-11-08 15:31:30 +00:00
|
|
|
buf: bytes.NewBuffer(make([]byte, bufSz)),
|
2024-11-04 13:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Request) Header() []byte {
|
|
|
|
return append(r.magic, []byte("rcon")...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Request) Encode(cmd string) []byte {
|
2024-11-08 15:31:30 +00:00
|
|
|
r.buf.Reset()
|
|
|
|
r.buf.Write(r.Header())
|
|
|
|
r.buf.WriteString(fmt.Sprintf(" %s %s", r.password, cmd))
|
|
|
|
return r.buf.Bytes()
|
2024-11-04 13:33:53 +00:00
|
|
|
}
|