From 0273baaef67824da5cb2cc2de2593a8800ce3cb6 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 13 Oct 2019 16:41:38 +0100 Subject: [PATCH] mantis 8598: filter dead groups from group search. honor querystart request. Viewers are very broken on this, seems protocol was made by someone with no idea about lludp --- .../Addons/Groups/Service/GroupsService.cs | 11 +++++-- .../ClientStack/Linden/UDP/LLClientView.cs | 8 ++--- .../Framework/Search/BasicSearchModule.cs | 31 +++++++++++++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/OpenSim/Addons/Groups/Service/GroupsService.cs b/OpenSim/Addons/Groups/Service/GroupsService.cs index 0792a470e3..b5f8ff5494 100644 --- a/OpenSim/Addons/Groups/Service/GroupsService.cs +++ b/OpenSim/Addons/Groups/Service/GroupsService.cs @@ -230,15 +230,22 @@ namespace OpenSim.Groups if (d.Data.ContainsKey("Location") && d.Data["Location"] != string.Empty) continue; + int nmembers = m_Database.MemberCount(d.GroupID); + if(nmembers == 0) + continue; + DirGroupsReplyData g = new DirGroupsReplyData(); - g.groupID = d.GroupID; if (d.Data.ContainsKey("Name")) g.groupName = d.Data["Name"]; else + { m_log.DebugFormat("[Groups]: Key Name not found"); + continue; + } - g.members = m_Database.MemberCount(d.GroupID); + g.groupID = d.GroupID; + g.members = nmembers; groups.Add(g); } diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 7c2a887604..80ca67bce0 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -3850,19 +3850,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP packet.QueryData = new DirGroupsReplyPacket.QueryDataBlock(); packet.QueryData.QueryID = queryID; - packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[ - data.Length]; + packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[data.Length]; int i = 0; foreach (DirGroupsReplyData d in data) { packet.QueryReplies[i] = new DirGroupsReplyPacket.QueryRepliesBlock(); packet.QueryReplies[i].GroupID = d.groupID; - packet.QueryReplies[i].GroupName = - Utils.StringToBytes(d.groupName); + packet.QueryReplies[i].GroupName = Util.StringToBytes(d.groupName, 35); packet.QueryReplies[i].Members = d.members; packet.QueryReplies[i].SearchOrder = d.searchOrder; - i++; + ++i; } OutPacket(packet, ThrottleOutPacketType.Task); diff --git a/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs b/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs index c04d856ce3..1026eae91d 100644 --- a/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs @@ -186,10 +186,35 @@ namespace OpenSim.Region.CoreModules.Framework.Search if (string.IsNullOrEmpty(queryText)) remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); - // TODO: This currently ignores pretty much all the query flags including Mature and sort order - remoteClient.SendDirGroupsReply(queryID, m_GroupsService.FindGroups(remoteClient, queryText).ToArray()); - } + List answer = m_GroupsService.FindGroups(remoteClient, queryText); + if(answer.Count == 0) + { + remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); + return; + } + // filter out groups with no members + DirGroupsReplyData[] result = new DirGroupsReplyData[answer.Count]; + int count = 0; + foreach(DirGroupsReplyData dgrd in answer) + { + if(dgrd.members > 0) + result[count++] = dgrd; + } + answer = null; + + // viewers don't sent sorting, so results they show are a nice mess + if ((queryStart > 0) && (queryStart < count)) + { + int len = count - queryStart; + DirGroupsReplyData[] tmp = new DirGroupsReplyData[len]; + Array.Copy(result, queryStart, tmp, 0, len); + result = tmp; + } + + // TODO: This currently ignores pretty much all the query flags including Mature and sort order + remoteClient.SendDirGroupsReply(queryID, result); + } } #endregion Event Handlers