q3rcon/internal/packet/request.go

26 lines
470 B
Go
Raw Normal View History

2024-11-04 13:33:53 +00:00
package packet
import "fmt"
type Request struct {
magic []byte
password string
}
func NewRequest(password string) Request {
return Request{
magic: []byte{'\xff', '\xff', '\xff', '\xff'},
password: password,
}
}
func (r Request) Header() []byte {
return append(r.magic, []byte("rcon")...)
}
func (r Request) Encode(cmd string) []byte {
datagram := r.Header()
datagram = append(datagram, fmt.Sprintf(" %s %s", r.password, cmd)...)
return datagram
}