API: Allow more advanced group filtering

This commit is contained in:
mkwcat 2024-01-05 19:00:09 -05:00
parent 3337d7fc0d
commit fbde8963db
No known key found for this signature in database
GPG Key ID: 7A505679CE9E7AA9
3 changed files with 8 additions and 5 deletions

View File

@ -24,8 +24,7 @@ func HandleGroups(w http.ResponseWriter, r *http.Request) {
return
}
gameName := query.Get("game")
groups := qr2.GetGroups(gameName)
groups := qr2.GetGroups(query["game"], query["id"])
for _, group := range groups {
for i, player := range group.Players {

View File

@ -35,7 +35,7 @@ func HandleStats(w http.ResponseWriter, r *http.Request) {
stats := map[string]Stats{}
servers := qr2.GetSessionServers()
groups := qr2.GetGroups("")
groups := qr2.GetGroups([]string{}, []string{})
globalStats := Stats{
OnlinePlayerCount: len(servers),

View File

@ -238,14 +238,18 @@ type GroupInfo struct {
}
// GetGroups returns an unsorted copy of all online rooms
func GetGroups(gameName string) []GroupInfo {
func GetGroups(gameNames []string, groupNames []string) []GroupInfo {
var groupsCopy []GroupInfo
mutex.Lock()
defer mutex.Unlock()
for _, group := range groups {
if gameName != "" && gameName != group.GameName {
if len(gameNames) > 0 && !common.StringInSlice(group.GameName, gameNames) {
continue
}
if len(groupNames) > 0 && !common.StringInSlice(group.GroupName, groupNames) {
continue
}