2024-03-26 10:47:53 +00:00
|
|
|
package udpproxy
|
|
|
|
|
2024-04-11 19:24:43 +01:00
|
|
|
import "bytes"
|
|
|
|
|
2024-03-26 10:47:53 +00:00
|
|
|
type validator struct {
|
2024-09-28 15:36:04 +01:00
|
|
|
rconRequestHeader []byte
|
|
|
|
getstatusRequestHeader []byte
|
|
|
|
getinfoRequestHeader []byte
|
|
|
|
getchallengeRequestHeader []byte
|
|
|
|
rconResponseHeader []byte
|
|
|
|
getstatusResponseHeader []byte
|
|
|
|
getinfoResponseHeader []byte
|
|
|
|
badRconIdentifier []byte
|
2024-04-11 19:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func newValidator() validator {
|
2024-09-28 15:36:04 +01:00
|
|
|
return validator{
|
|
|
|
rconRequestHeader: []byte("\xff\xff\xff\xffrcon"),
|
|
|
|
getstatusRequestHeader: []byte("\xff\xff\xff\xffgetstatus"),
|
|
|
|
getinfoRequestHeader: []byte("\xff\xff\xff\xffgetinfo"),
|
|
|
|
getchallengeRequestHeader: []byte("\xff\xff\xff\xffgetchallenge"),
|
|
|
|
rconResponseHeader: []byte("\xff\xff\xff\xffprint\n"),
|
|
|
|
getstatusResponseHeader: []byte("\xff\xff\xff\xffstatusResponse\n"),
|
|
|
|
getinfoResponseHeader: []byte("\xff\xff\xff\xffinfoResponse\n"),
|
|
|
|
badRconIdentifier: []byte("Bad rcon"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v validator) compare(buf, c []byte) bool {
|
2024-04-14 19:13:56 +01:00
|
|
|
return bytes.Equal(buf[:len(c)], c)
|
2024-04-14 08:27:30 +01:00
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isRconRequestPacket(buf []byte) bool {
|
2024-04-14 08:27:30 +01:00
|
|
|
return v.compare(buf, v.rconRequestHeader)
|
2024-03-26 10:47:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isQueryRequestPacket(buf []byte) bool {
|
2024-04-14 08:27:30 +01:00
|
|
|
return v.compare(buf, v.getstatusRequestHeader) ||
|
|
|
|
v.compare(buf, v.getinfoRequestHeader)
|
2024-03-26 10:47:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isValidRequestPacket(buf []byte) bool {
|
2024-03-26 10:47:53 +00:00
|
|
|
return v.isRconRequestPacket(buf) || v.isQueryRequestPacket(buf)
|
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isChallengeRequestPacket(buf []byte) bool {
|
|
|
|
return v.compare(buf, v.getchallengeRequestHeader)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v validator) isRconResponsePacket(buf []byte) bool {
|
2024-04-14 08:27:30 +01:00
|
|
|
return v.compare(buf, v.rconResponseHeader)
|
2024-03-26 10:47:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isQueryResponsePacket(buf []byte) bool {
|
2024-04-14 08:27:30 +01:00
|
|
|
return v.compare(buf, v.getstatusResponseHeader) ||
|
|
|
|
v.compare(buf, v.getinfoResponseHeader)
|
2024-03-26 10:47:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isValidResponsePacket(buf []byte) bool {
|
2024-03-26 10:47:53 +00:00
|
|
|
return v.isRconResponsePacket(buf) || v.isQueryResponsePacket(buf)
|
|
|
|
}
|
2024-04-03 20:54:10 +01:00
|
|
|
|
2024-09-28 15:36:04 +01:00
|
|
|
func (v validator) isBadRconResponse(buf []byte) bool {
|
2024-04-14 08:27:30 +01:00
|
|
|
return v.compare(buf[len(v.rconResponseHeader):], v.badRconIdentifier)
|
2024-04-03 20:54:10 +01:00
|
|
|
}
|