Skip to content

Commit

Permalink
fix: Crash on missing serverinfo chunk (#18)
Browse files Browse the repository at this point in the history
This adds a null check around accesses of accesses to a potentially null serverinfo chunk
  • Loading branch information
lwaddicor authored Oct 8, 2021
1 parent cbc6351 commit 6cdc429
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/svrquery/protocol/sqp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ type QueryResponse struct {
TeamInfo *TeamInfoChunk `json:"team_info,omitempty"`
}

// MaxClients returns the maximum number of clients.
func (q *QueryResponse) MaxClients() int64 {
if q.ServerInfo == nil {
// No server info chunk, use 0
return 0
}
return int64(q.ServerInfo.MaxPlayers)
}

// NumClients returns the number of clients.
func (q *QueryResponse) NumClients() int64 {
if q.ServerInfo == nil {
// No server info chunk, use 0
return 0
}
return int64(q.ServerInfo.CurrentPlayers)
}

Expand Down

0 comments on commit 6cdc429

Please sign in to comment.