Skip to content

Commit

Permalink
feat: Support tf2e-v10 protocol in go-svrquery (#32)
Browse files Browse the repository at this point in the history
This adds support for the latest TF2E-V10 protocol.
  • Loading branch information
nikbanerjee-unity authored Feb 24, 2023
1 parent 38dc672 commit 2e10d43
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/svrquery/protocol/titanfall/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func (q *queryer) Query() (resp protocol.Responser, err error) {
}

if i.Version > 2 {
if i.Version >= 9 {
if i.Version >= 10 {
if err = r.Read(&i.MatchStateV10); err != nil {
return nil, err
}
} else if i.Version >= 9 {
if err = r.Read(&i.MatchStateV9); err != nil {
return nil, err
}
Expand Down
22 changes: 22 additions & 0 deletions lib/svrquery/protocol/titanfall/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ func TestQuery(t *testing.T) {
}
v9.MatchState = MatchState{}

v10 := v9
v10.Version = 10
v10.MatchStateV10 = MatchStateV10{
MatchStateV9: MatchStateV9{
Phase: 3,
TimePassed: 0,
TeamsLeftWithPlayersNum: 0,
},
CurrentEntityPropertyCount: 2,
MaxEntityPropertyCount: 5,
}
v10.MatchStateV9 = MatchStateV9{}

cases := []struct {
name string
version byte
Expand Down Expand Up @@ -147,6 +160,15 @@ func TestQuery(t *testing.T) {
key: testKey,
expEncypted: true,
},
{
name: "v10",
version: 10,
request: "request-v10",
response: "response-v10",
expected: v10,
key: testKey,
expEncypted: true,
},
{
name: "keyed",
version: 5,
Expand Down
1 change: 1 addition & 0 deletions lib/svrquery/protocol/titanfall/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ func init() {
protocol.MustRegister("tf2e-v7", newQueryer(7))
protocol.MustRegister("tf2e-v8", newQueryer(8))
protocol.MustRegister("tf2e-v9", newQueryer(9))
protocol.MustRegister("tf2e-v10", newQueryer(10))
}
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions lib/svrquery/protocol/titanfall/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Info struct {
MatchState
// Version 9+
MatchStateV9
// Version 10+
MatchStateV10

Teams []Team
Clients []Client
Expand Down Expand Up @@ -182,6 +184,14 @@ type PerformanceInfo struct {
MaxUserCommandTime float32
}

// MatchStateV10 represents match state contained in a query response.
// Two new fields on entity count were added in this version of the schema.
type MatchStateV10 struct {
MatchStateV9
CurrentEntityPropertyCount uint32
MaxEntityPropertyCount uint32
}

// MatchStateV9 represents match state contained in a query response.
// A number of fields were removed in this version of the schema.
type MatchStateV9 struct {
Expand Down

0 comments on commit 2e10d43

Please sign in to comment.