Skip to content

Commit

Permalink
feat(tf2-e): Update tf2e query for v9 schema (#29)
Browse files Browse the repository at this point in the history
This change implements the latest version (v9) of the TF2E protocol
  • Loading branch information
nikbanerjee-unity authored Oct 13, 2022
1 parent 74530c8 commit 8d1c41f
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
.idea/
.DS_Store
Thumbs.db

# Binary
go-svrquery
30 changes: 27 additions & 3 deletions lib/svrquery/protocol/titanfall/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,24 @@ func (q *queryer) Query() (resp protocol.Responser, err error) {
return nil, err
}

if i.Version > 4 {
if i.Version >= 9 {
// PerformanceInfoV9.
if err = r.Read(&i.PerformanceInfoV9); err != nil {
return nil, err
}
} else if i.Version > 4 {
// PerformanceInfo.
if err = r.Read(&i.PerformanceInfo); err != nil {
return nil, err
}
}

if i.Version > 2 {
if i.Version > 5 {
if i.Version >= 9 {
if err = r.Read(&i.MatchStateV9); err != nil {
return nil, err
}
} else if i.Version > 5 {
// MatchState and Teams.
if err = r.Read(&i.MatchState); err != nil {
return nil, err
Expand Down Expand Up @@ -249,9 +258,24 @@ func (q *queryer) basicInfo(r *common.BinaryReader, i *Info) (err error) {

if err = r.Read(&i.BasicInfo.NumClients); err != nil {
return err
} else if err = r.Read(&i.BasicInfo.MaxClients); err != nil {
}

if i.Version >= 9 {
if err = r.Read(&i.BasicInfo.NumBotClients); err != nil {
return err
}
}

if err = r.Read(&i.BasicInfo.MaxClients); err != nil {
return err
}

if i.Version >= 9 {
if err = r.Read(&i.BasicInfo.TotalClientsConnectedEver); err != nil {
return err
}
}

i.BasicInfo.Map, err = r.ReadString()
return err
}
Expand Down
28 changes: 27 additions & 1 deletion lib/svrquery/protocol/titanfall/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestQuery(t *testing.T) {
AverageUserCommandTime: 3,
MaxUserCommandTime: 4,
}
v7.TeamsLeftWithPlayersNum = 6
v7.MatchState.TeamsLeftWithPlayersNum = 6

v8 := v7
v8.Version = 8
Expand All @@ -89,6 +89,23 @@ func TestQuery(t *testing.T) {
}
v8.InstanceInfo = InstanceInfo{}

v9 := v8
v9.Version = 9
v9.BasicInfo.NumBotClients = 3
v9.BasicInfo.TotalClientsConnectedEver = 0
v9.PerformanceInfoV9 = PerformanceInfoV9{
PerformanceInfo: v8.PerformanceInfo,
CommitMemory: 8472,
ResidentMemory: 3901,
}
v9.PerformanceInfo = PerformanceInfo{}
v9.MatchStateV9 = MatchStateV9{
Phase: 3,
TimePassed: 0,
TeamsLeftWithPlayersNum: 0,
}
v9.MatchState = MatchState{}

cases := []struct {
name string
version byte
Expand Down Expand Up @@ -121,6 +138,15 @@ func TestQuery(t *testing.T) {
key: testKey,
expEncypted: true,
},
{
name: "v9",
version: 9,
request: "request-v9",
response: "response-v9",
expected: v9,
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 @@ -9,4 +9,5 @@ func init() {
protocol.MustRegister("tf2e", newQueryer(3))
protocol.MustRegister("tf2e-v7", newQueryer(7))
protocol.MustRegister("tf2e-v8", newQueryer(8))
protocol.MustRegister("tf2e-v9", newQueryer(9))
}
Binary file not shown.
Binary file added lib/svrquery/protocol/titanfall/testdata/response-v9
Binary file not shown.
50 changes: 41 additions & 9 deletions lib/svrquery/protocol/titanfall/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ type Info struct {
BasicInfo
// Version 4+
PerformanceInfo
// Version 9+
PerformanceInfoV9
// Version 2+
MatchState
// Version 9+
MatchStateV9

Teams []Team
Clients []Client
}
Expand All @@ -33,11 +38,21 @@ func (i Info) NumClients() int64 {
return int64(i.BasicInfo.NumClients)
}

// NumBotClients implements protocol.Responser.
func (i Info) NumBotClients() int64 {
return int64(i.BasicInfo.NumBotClients)
}

// MaxClients implements protocol.Responser.
func (i Info) MaxClients() int64 {
return int64(i.BasicInfo.MaxClients)
}

// TotalClientsConnectedEver implements protocol.Responser.
func (i Info) TotalClientsConnectedEver() int64 {
return int64(i.BasicInfo.TotalClientsConnectedEver)
}

// Map implements protocol.Mapper.
func (i Info) Map() string {
return i.BasicInfo.Map
Expand Down Expand Up @@ -139,15 +154,24 @@ func (a HealthFlags) DOS() bool {

// BasicInfo represents basic information contained in a query response.
type BasicInfo struct {
Port uint16
Platform string
PlaylistVersion string
PlaylistNum uint32
PlaylistName string
NumClients byte
MaxClients byte
Map string
PlatformPlayers map[string]byte
Port uint16
Platform string
PlaylistVersion string
PlaylistNum uint32
PlaylistName string
NumClients byte
NumBotClients byte
MaxClients byte
TotalClientsConnectedEver uint32
Map string
PlatformPlayers map[string]byte
}

// PerformanceInfoV9 represents frame information contained in a query response.
type PerformanceInfoV9 struct {
PerformanceInfo
CommitMemory uint32
ResidentMemory uint32
}

// PerformanceInfo represents frame information contained in a query response.
Expand All @@ -158,6 +182,14 @@ type PerformanceInfo struct {
MaxUserCommandTime float32
}

// MatchStateV9 represents match state contained in a query response.
// A number of fields were removed in this version of the schema.
type MatchStateV9 struct {
Phase byte
TimePassed uint16 // seconds
TeamsLeftWithPlayersNum uint16
}

// MatchStateV2 represents match state contained in a query response.
// This contains a legacy v2 version of matchstate
type MatchStateV2 struct {
Expand Down

0 comments on commit 8d1c41f

Please sign in to comment.