diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 15ad762..9fc24de 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -98,6 +98,7 @@ func server(l *log.Logger, proto, address string) error { GameType: "Game Type", Map: "Map", Port: 1000, + Metrics: []float32{-1, 0, 1, 3.14159, 1253.232, -933.32}, }) if err != nil { return err diff --git a/lib/svrquery/protocol/sqp/consts.go b/lib/svrquery/protocol/sqp/consts.go index 1397bd3..e593cd7 100644 --- a/lib/svrquery/protocol/sqp/consts.go +++ b/lib/svrquery/protocol/sqp/consts.go @@ -5,9 +5,6 @@ const ( // DefaultMaxPacketSize is the default maximum size of a packet (MTU 1500 - UDP+IP header size) DefaultMaxPacketSize = 1472 - // Version is the query protocol version this client uses. - Version = uint16(1) - // MaxMetrics is the maximum number of metrics supported in a request. MaxMetrics = byte(25) ) diff --git a/lib/svrquery/protocol/sqp/query.go b/lib/svrquery/protocol/sqp/query.go index a5b3146..7ef0b57 100644 --- a/lib/svrquery/protocol/sqp/query.go +++ b/lib/svrquery/protocol/sqp/query.go @@ -16,17 +16,21 @@ type queryer struct { reader *packetReader challengeID uint32 requestedChunks byte + version uint16 } -func newCreator(c protocol.Client) protocol.Queryer { - return newQueryer(ServerInfo, DefaultMaxPacketSize, c) +func newCreator(requestedChunks byte, version uint16) func(c protocol.Client) protocol.Queryer { + return func(c protocol.Client) protocol.Queryer { + return newQueryer(requestedChunks, DefaultMaxPacketSize, version, c) + } } -func newQueryer(requestedChunks byte, maxPktSize int, c protocol.Client) *queryer { +func newQueryer(requestedChunks byte, maxPktSize int, version uint16, c protocol.Client) *queryer { return &queryer{ c: c, maxPktSize: maxPktSize, requestedChunks: requestedChunks, + version: version, reader: newPacketReader(bufio.NewReaderSize(c, maxPktSize)), } } @@ -55,7 +59,7 @@ func (q *queryer) sendQuery(requestedChunks byte) error { return err } - if err := binary.Write(pkt, binary.BigEndian, Version); err != nil { + if err := binary.Write(pkt, binary.BigEndian, q.version); err != nil { return err } diff --git a/lib/svrquery/protocol/sqp/query_test.go b/lib/svrquery/protocol/sqp/query_test.go index 1cc5ef7..199db76 100644 --- a/lib/svrquery/protocol/sqp/query_test.go +++ b/lib/svrquery/protocol/sqp/query_test.go @@ -17,7 +17,7 @@ const ( func newClient(requestedChunks byte) (*clienttest.MockClient, *queryer) { m := &clienttest.MockClient{} m.On("Address").Return("127.0.0.1:8000") - c := newQueryer(requestedChunks, DefaultMaxPacketSize, m) + c := newQueryer(requestedChunks, DefaultMaxPacketSize, 2, m) return m, c } diff --git a/lib/svrquery/protocol/sqp/register.go b/lib/svrquery/protocol/sqp/register.go index 3aadcf5..2eabf11 100644 --- a/lib/svrquery/protocol/sqp/register.go +++ b/lib/svrquery/protocol/sqp/register.go @@ -5,5 +5,6 @@ import ( ) func init() { - protocol.MustRegister("sqp", newCreator) + protocol.MustRegister("sqp", newCreator(ServerInfo, 1)) + protocol.MustRegister("sqp-v2", newCreator(ServerInfo|Metrics, 2)) } diff --git a/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request b/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request index a6b29b2..adddd25 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request and b/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request differ diff --git a/lib/svrquery/protocol/sqp/testdata/info_single_request b/lib/svrquery/protocol/sqp/testdata/info_single_request index a6b29b2..adddd25 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/info_single_request and b/lib/svrquery/protocol/sqp/testdata/info_single_request differ diff --git a/lib/svrquery/protocol/sqp/testdata/metrics_request b/lib/svrquery/protocol/sqp/testdata/metrics_request index 3c7eb21..8ffd73e 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/metrics_request and b/lib/svrquery/protocol/sqp/testdata/metrics_request differ diff --git a/lib/svrquery/protocol/sqp/testdata/player_request b/lib/svrquery/protocol/sqp/testdata/player_request index c90c18e..7cee708 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/player_request and b/lib/svrquery/protocol/sqp/testdata/player_request differ diff --git a/lib/svrquery/protocol/sqp/testdata/rules_request b/lib/svrquery/protocol/sqp/testdata/rules_request index 719d15a..25e877f 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/rules_request and b/lib/svrquery/protocol/sqp/testdata/rules_request differ diff --git a/lib/svrquery/protocol/sqp/testdata/team_request b/lib/svrquery/protocol/sqp/testdata/team_request index d57d009..f68290c 100644 Binary files a/lib/svrquery/protocol/sqp/testdata/team_request and b/lib/svrquery/protocol/sqp/testdata/team_request differ