first commit

This commit is contained in:
2024-11-04 13:33:53 +00:00
commit 2461a0116c
9 changed files with 441 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
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
}

View File

@@ -0,0 +1,13 @@
package packet
type Response struct {
magic []byte
}
func NewResponse() Response {
return Response{magic: []byte{'\xff', '\xff', '\xff', '\xff'}}
}
func (r Response) Header() []byte {
return append(r.magic, []byte("print\n")...)
}