From 67026eb8befabf33533c40f490ae53be44df5f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Tue, 18 Oct 2022 11:48:11 +0100 Subject: [PATCH 1/6] fix(sqp): Request metrics chunk in the default queryer When a client was created using svrquery.NewClient() then c.Query() was executed only server info chunk was going to be requested by default. This fix adds the metrics chunk to the requested chunks used in the default queryer. This was missed from the previous commit. --- lib/svrquery/protocol/sqp/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svrquery/protocol/sqp/query.go b/lib/svrquery/protocol/sqp/query.go index a5b3146..de7378e 100644 --- a/lib/svrquery/protocol/sqp/query.go +++ b/lib/svrquery/protocol/sqp/query.go @@ -19,7 +19,7 @@ type queryer struct { } func newCreator(c protocol.Client) protocol.Queryer { - return newQueryer(ServerInfo, DefaultMaxPacketSize, c) + return newQueryer(ServerInfo|Metrics, DefaultMaxPacketSize, c) } func newQueryer(requestedChunks byte, maxPktSize int, c protocol.Client) *queryer { From 596f7e5a1aeca3164f257671ab71b04a7b4bd710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Wed, 2 Nov 2022 11:24:19 +0000 Subject: [PATCH 2/6] bump client version --- cmd/cli/main.go | 1 + lib/svrquery/protocol/sqp/consts.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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..41d9026 100644 --- a/lib/svrquery/protocol/sqp/consts.go +++ b/lib/svrquery/protocol/sqp/consts.go @@ -6,7 +6,7 @@ const ( DefaultMaxPacketSize = 1472 // Version is the query protocol version this client uses. - Version = uint16(1) + Version = uint16(2) // MaxMetrics is the maximum number of metrics supported in a request. MaxMetrics = byte(25) From ad39f0a1d8cdcbaa09789799d93ef7ce3079c39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Wed, 2 Nov 2022 13:13:07 +0000 Subject: [PATCH 3/6] bump version in test request packets --- .../sqp/testdata/info_single_malformed_request | Bin 8 -> 8 bytes .../protocol/sqp/testdata/info_single_request | Bin 8 -> 8 bytes lib/svrquery/protocol/sqp/testdata/metrics_request | Bin 8 -> 8 bytes lib/svrquery/protocol/sqp/testdata/player_request | Bin 8 -> 8 bytes lib/svrquery/protocol/sqp/testdata/rules_request | Bin 8 -> 8 bytes lib/svrquery/protocol/sqp/testdata/team_request | Bin 8 -> 8 bytes 6 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request b/lib/svrquery/protocol/sqp/testdata/info_single_malformed_request index a6b29b21349729ad94f1a1749d0868ba55556883..adddd258a35c412252f7a7ccebc5c3f2ebef9fee 100644 GIT binary patch literal 8 PcmZQ%U|?WmU}6LS02u%V literal 8 PcmZQ%U|?WmU}OXU02crS diff --git a/lib/svrquery/protocol/sqp/testdata/info_single_request b/lib/svrquery/protocol/sqp/testdata/info_single_request index a6b29b21349729ad94f1a1749d0868ba55556883..adddd258a35c412252f7a7ccebc5c3f2ebef9fee 100644 GIT binary patch literal 8 PcmZQ%U|?WmU}6LS02u%V literal 8 PcmZQ%U|?WmU}OXU02crS diff --git a/lib/svrquery/protocol/sqp/testdata/metrics_request b/lib/svrquery/protocol/sqp/testdata/metrics_request index 3c7eb2168b18f87f867c0c8406e7bbc52afa5197..8ffd73e88514d9acd37c371c79028e79a12bd5dc 100644 GIT binary patch literal 8 PcmZQ%U|?WmU=jcT04M+z literal 8 PcmZQ%U|?WmU=#oV044ww diff --git a/lib/svrquery/protocol/sqp/testdata/player_request b/lib/svrquery/protocol/sqp/testdata/player_request index c90c18e3e7924fee64ee9c63d903600d2cc192bf..7cee7082a58620be0fce69b13646c85e2c57a518 100644 GIT binary patch literal 8 PcmZQ%U|?WmU}6CP02}}b literal 8 PcmZQ%U|?WmU}OOR02%-Y diff --git a/lib/svrquery/protocol/sqp/testdata/rules_request b/lib/svrquery/protocol/sqp/testdata/rules_request index 719d15ad0ebf9efbee227ca20a698139bb4c0803..25e877f7982cf703f076b962cec2d118e610625a 100644 GIT binary patch literal 8 PcmZQ%U|?WmU}6FQ02%-X literal 8 PcmZQ%U|?WmU}ORS02lxU diff --git a/lib/svrquery/protocol/sqp/testdata/team_request b/lib/svrquery/protocol/sqp/testdata/team_request index d57d009019dcf0ea7c85f16c30b89a16d8c951c0..f68290c2887a8054a22a93e8fdc4711205023d29 100644 GIT binary patch literal 8 PcmZQ%U|?WmVB!D(03ZMj literal 8 PcmZQ%U|?WmVB`P*03HAg From 31003354d302279fc63de6ddf55f891de0c12463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Tue, 31 Jan 2023 16:19:48 +0000 Subject: [PATCH 4/6] support 2 versions of SQP --- lib/svrquery/protocol/sqp/query.go | 6 ++++-- lib/svrquery/protocol/sqp/register.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/svrquery/protocol/sqp/query.go b/lib/svrquery/protocol/sqp/query.go index de7378e..b941bef 100644 --- a/lib/svrquery/protocol/sqp/query.go +++ b/lib/svrquery/protocol/sqp/query.go @@ -18,8 +18,10 @@ type queryer struct { requestedChunks byte } -func newCreator(c protocol.Client) protocol.Queryer { - return newQueryer(ServerInfo|Metrics, DefaultMaxPacketSize, c) +func newCreator(requestedChunks byte) func(c protocol.Client) protocol.Queryer { + return func(c protocol.Client) protocol.Queryer { + return newQueryer(requestedChunks, DefaultMaxPacketSize, c) + } } func newQueryer(requestedChunks byte, maxPktSize int, c protocol.Client) *queryer { diff --git a/lib/svrquery/protocol/sqp/register.go b/lib/svrquery/protocol/sqp/register.go index 3aadcf5..ddb676d 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)) + protocol.MustRegister("sqp2", newCreator(ServerInfo|Metrics)) } From e4aaadf7f7f09268219d4a0febebf649f6e65463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Tue, 31 Jan 2023 16:30:44 +0000 Subject: [PATCH 5/6] use correct version number in queryer --- lib/svrquery/protocol/sqp/consts.go | 3 --- lib/svrquery/protocol/sqp/query.go | 10 ++++++---- lib/svrquery/protocol/sqp/query_test.go | 2 +- lib/svrquery/protocol/sqp/register.go | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/svrquery/protocol/sqp/consts.go b/lib/svrquery/protocol/sqp/consts.go index 41d9026..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(2) - // 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 b941bef..7ef0b57 100644 --- a/lib/svrquery/protocol/sqp/query.go +++ b/lib/svrquery/protocol/sqp/query.go @@ -16,19 +16,21 @@ type queryer struct { reader *packetReader challengeID uint32 requestedChunks byte + version uint16 } -func newCreator(requestedChunks byte) func(c protocol.Client) protocol.Queryer { +func newCreator(requestedChunks byte, version uint16) func(c protocol.Client) protocol.Queryer { return func(c protocol.Client) protocol.Queryer { - return newQueryer(requestedChunks, DefaultMaxPacketSize, c) + 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)), } } @@ -57,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 ddb676d..1b46a97 100644 --- a/lib/svrquery/protocol/sqp/register.go +++ b/lib/svrquery/protocol/sqp/register.go @@ -5,6 +5,6 @@ import ( ) func init() { - protocol.MustRegister("sqp", newCreator(ServerInfo)) - protocol.MustRegister("sqp2", newCreator(ServerInfo|Metrics)) + protocol.MustRegister("sqp", newCreator(ServerInfo, 1)) + protocol.MustRegister("sqp2", newCreator(ServerInfo|Metrics, 2)) } From f811b0c36eb542ea4341daf50f1525876562f7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Boleradszki?= Date: Wed, 1 Feb 2023 17:02:30 +0000 Subject: [PATCH 6/6] use "sqp-v2" instead of "sqp2" --- lib/svrquery/protocol/sqp/register.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svrquery/protocol/sqp/register.go b/lib/svrquery/protocol/sqp/register.go index 1b46a97..2eabf11 100644 --- a/lib/svrquery/protocol/sqp/register.go +++ b/lib/svrquery/protocol/sqp/register.go @@ -6,5 +6,5 @@ import ( func init() { protocol.MustRegister("sqp", newCreator(ServerInfo, 1)) - protocol.MustRegister("sqp2", newCreator(ServerInfo|Metrics, 2)) + protocol.MustRegister("sqp-v2", newCreator(ServerInfo|Metrics, 2)) }