From 6cdc4294451a2089b456cdfe3336ff4f693afc94 Mon Sep 17 00:00:00 2001 From: Lewis Waddicor Date: Fri, 8 Oct 2021 12:59:26 +0100 Subject: [PATCH] fix: Crash on missing serverinfo chunk (#18) This adds a null check around accesses of accesses to a potentially null serverinfo chunk --- lib/svrquery/protocol/sqp/types.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/svrquery/protocol/sqp/types.go b/lib/svrquery/protocol/sqp/types.go index 9fc345f..d200b3f 100644 --- a/lib/svrquery/protocol/sqp/types.go +++ b/lib/svrquery/protocol/sqp/types.go @@ -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) }