Skip to content

Commit

Permalink
feat: Add relay health (#35)
Browse files Browse the repository at this point in the history
This adds a relay health flag for TF2E
  • Loading branch information
lwaddicor authored Jun 7, 2023
1 parent 341cd7a commit 39bbff0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/svrquery/protocol/titanfall/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (a HealthFlags) MarshalJSON() ([]byte, error) {
SlowServerFrames bool
Hitching bool
DOS bool
Relay bool
}{}
obj.None = a.None()
obj.PacketLossIn = a.PacketLossIn()
Expand All @@ -122,6 +123,7 @@ func (a HealthFlags) MarshalJSON() ([]byte, error) {
obj.SlowServerFrames = a.SlowServerFrames()
obj.Hitching = a.Hitching()
obj.DOS = a.DOS()
obj.Relay = a.Relay()

return json.Marshal(obj)
}
Expand Down Expand Up @@ -166,6 +168,11 @@ func (a HealthFlags) DOS() bool {
return (a>>6)&1 == 1
}

// Relay health flag
func (a HealthFlags) Relay() bool {
return (a>>7)&1 == 1
}

// BasicInfo represents basic information contained in a query response.
type BasicInfo struct {
Port uint16
Expand Down
9 changes: 8 additions & 1 deletion lib/svrquery/protocol/titanfall/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestHealthFlags(t *testing.T) {
expSlowServerFrames bool
expHitching bool
expDOS bool
expRelay bool
}{
{
input: 0,
Expand Down Expand Up @@ -51,10 +52,14 @@ func TestHealthFlags(t *testing.T) {
input: 1 << 6,
expDOS: true,
},
{
input: 1 << 7,
expRelay: true,
},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("verify 0b%b", tc.input), func(t *testing.T) {
t.Run(fmt.Sprintf("verify 0b%.32b", tc.input), func(t *testing.T) {
hf := HealthFlags(tc.input)
require.Equal(t, tc.expNone, hf.None())
require.Equal(t, tc.expPacketLossIn, hf.PacketLossIn())
Expand All @@ -63,6 +68,8 @@ func TestHealthFlags(t *testing.T) {
require.Equal(t, tc.expPacketChokedOut, hf.PacketChokedOut())
require.Equal(t, tc.expSlowServerFrames, hf.SlowServerFrames())
require.Equal(t, tc.expHitching, hf.Hitching())
require.Equal(t, tc.expDOS, hf.DOS())
require.Equal(t, tc.expRelay, hf.Relay())
})
}
}

0 comments on commit 39bbff0

Please sign in to comment.