From 64b76f347d2c1002c21f495b0d9b5aad95f6a33d Mon Sep 17 00:00:00 2001 From: mkwcat Date: Tue, 20 Feb 2024 10:38:30 -0500 Subject: [PATCH] QR2: Fix adding to empty join index list --- qr2/group.go | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/qr2/group.go b/qr2/group.go index 22d5478..eae5b42 100644 --- a/qr2/group.go +++ b/qr2/group.go @@ -505,15 +505,16 @@ func getGroupsRaw(gameNames []string, groupNames []string) []GroupInfo { } groupInfo := GroupInfo{ - GroupName: group.GroupName, - GameName: group.GameName, - CreateTime: group.CreateTime, - MatchType: "", - Suspend: true, - ServerIndex: "", - MKWRegion: "", - PlayersRaw: map[string]map[string]string{}, - Players: map[string]PlayerInfo{}, + GroupName: group.GroupName, + GameName: group.GameName, + CreateTime: group.CreateTime, + MatchType: "", + Suspend: true, + ServerIndex: "", + MKWRegion: "", + Players: map[string]PlayerInfo{}, + PlayersRaw: map[string]map[string]string{}, + SortedJoinIndex: []string{}, } if group.MatchType == "0" || group.MatchType == "1" { @@ -532,8 +533,6 @@ func getGroupsRaw(gameNames []string, groupNames []string) []GroupInfo { groupInfo.MKWRegion = group.MKWRegion } - sortedJoinIndexes := []string{} - for session := range group.Players { mapData := map[string]string{} for k, v := range session.Data { @@ -553,19 +552,28 @@ func getGroupsRaw(gameNames []string, groupNames []string) []GroupInfo { } // Add the join index to the sorted list - for i, joinIndex := range sortedJoinIndexes { - if joinIndex > mapData["+joinindex"] { - sortedJoinIndexes = append(sortedJoinIndexes, "") - copy(sortedJoinIndexes[i+1:], sortedJoinIndexes[i:]) - sortedJoinIndexes[i] = mapData["+joinindex"] + myJoinIndex, _ := strconv.Atoi(mapData["+joinindex"]) + added := false + + for i, joinIndex := range groupInfo.SortedJoinIndex { + if joinIndex == mapData["+joinindex"] { + added = true break } - if i == len(sortedJoinIndexes)-1 { - sortedJoinIndexes = append(sortedJoinIndexes, mapData["+joinindex"]) + intJoinIndex, _ := strconv.Atoi(joinIndex) + if intJoinIndex > myJoinIndex { + groupInfo.SortedJoinIndex = append(groupInfo.SortedJoinIndex, "") + copy(groupInfo.SortedJoinIndex[i+1:], groupInfo.SortedJoinIndex[i:]) + groupInfo.SortedJoinIndex[i] = mapData["+joinindex"] + added = true break } } + + if !added { + groupInfo.SortedJoinIndex = append(groupInfo.SortedJoinIndex, mapData["+joinindex"]) + } } groupsCopy = append(groupsCopy, groupInfo) @@ -622,6 +630,11 @@ func GetGroups(gameNames []string, groupNames []string, sorted bool) []GroupInfo } playerInfo.ConnFail = rawPlayer["+conn_fail"] + if playerInfo.ConnFail == "" { + playerInfo.ConnFail = "0" + } + + playerInfo.Suspend = rawPlayer["dwc_suspend"] groupsCopy[i].Players[joinIndex] = playerInfo }