add isValidPacket

ignore packets that don't match q3 rcon/query
This commit is contained in:
onyx-and-iris 2024-01-27 14:48:39 +00:00
parent 270f993cbc
commit ab91c219b9

View File

@ -36,6 +36,10 @@ func New(port, target string) (*Client, error) {
}, nil
}
func (c *Client) isValidPacket(header []byte) bool {
return string(header[:8]) == "\xff\xff\xff\xffrcon" || string(header[:13]) == "\xff\xff\xff\xffgetstatus" || string(header[:11]) == "\xff\xff\xff\xffgetinfo"
}
func (c *Client) ListenAndServe() error {
var err error
c.proxyConn, err = net.ListenUDP("udp", c.laddr)
@ -52,6 +56,10 @@ func (c *Client) ListenAndServe() error {
log.Println(err)
}
if !c.isValidPacket(buf[:16]) {
continue
}
session, found := c.sessions[caddr.String()]
if !found {
session, err = createSession(caddr, c.raddr, c.proxyConn)