private void SendMessageToGroup(GridInstantMessage im, UUID groupID)
        {
            if (m_debugEnabled)
            {
                m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID))
            {
                if (m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid))
                {
                    // Don't deliver messages to people who have dropped this session
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
                    }
                    continue;
                }

                // Copy Message
                GridInstantMessage msg = new GridInstantMessage();
                msg.imSessionID    = im.imSessionID;
                msg.fromAgentName  = im.fromAgentName;
                msg.message        = im.message;
                msg.dialog         = im.dialog;
                msg.offline        = im.offline;
                msg.ParentEstateID = im.ParentEstateID;
                msg.Position       = im.Position;
                msg.RegionID       = im.RegionID;
                msg.binaryBucket   = im.binaryBucket;
                msg.timestamp      = (uint)Util.UnixTimeSinceEpoch();

                // Updat Pertinate fields to make it a "group message"
                msg.fromAgentID = groupID.Guid;
                msg.fromGroup   = true;

                msg.toAgentID = member.AgentID.Guid;

                IClientAPI client = GetActiveClient(member.AgentID);
                if (client == null)
                {
                    // If they're not local, forward across the grid
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID);
                    }
                    m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { });
                }
                else
                {
                    // Deliver locally, directly
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name);
                    }
                    ProcessMessageFromGroupSession(msg);
                }
            }
        }
        public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            IGroupsModule groupService = m_scene.RequestModuleInterface <IGroupsModule>();
            ScenePresence SP           = m_scene.GetScenePresence(this.m_agentID);
            IClientAPI    client       = (SP == null) ? null : SP.ControllingClient;

            if ((groupService == null) || (client == null))
            {
                return(new byte[0]);
            }
            try
            {
                // Get *this* user's friends list (should be fast).
                List <FriendListItem> friends = m_scene.CommsManager.UserService.GetUserFriendList(this.m_agentID);

                OSDMap rm      = (OSDMap)OSDParser.DeserializeLLSDXml(request);
                UUID   groupID = rm["group_id"].AsUUID();

                OSDMap defaults = new OSDMap();
                defaults["default_powers"] = (ulong)Constants.DefaultEveryonePowers;

                OSDMap        members   = new OSDMap();
                List <string> titleList = new List <string>();
                int           count     = 0;
                foreach (GroupMembersData gmd in groupService.GroupMembersRequest(null, m_scene, m_agentID, groupID))
                {
                    OSDMap member = new OSDMap();
                    member["donated_square_meters"] = gmd.Contribution;
                    member["last_login"]            = FilterOnlineStatus(gmd.AgentID, gmd.OnlineStatus, gmd.LastLogout, friends);
                    member["powers"] = gmd.AgentPowers;

                    if (gmd.IsOwner)
                    {
                        member["owner"] = "Y";  // mere presence of this means IsOwner to the viewer.
                    }
                    int titleIndex;
                    if (titleList.Contains(gmd.Title))
                    {
                        titleIndex = titleList.IndexOf(gmd.Title);
                    }
                    else
                    {
                        titleIndex = titleList.Count;   // before adding, 0-based
                        titleList.Add(gmd.Title);
                    }
                    member["title"] = titleIndex.ToString();

                    count++;
                    members[gmd.AgentID.ToString()] = member;
                }

                // Convert optimized list to OSDArray.
                OSDArray titles = new OSDArray();
                foreach (string title in titleList)
                {
                    titles.Add(title);
                }

                OSDMap map = new OSDMap();
                map["member_count"] = count;
                map["group_id"]     = groupID;
                map["defaults"]     = defaults;
                map["titles"]       = titles;
                map["members"]      = members;
                return(OSDParser.SerializeLLSDXmlBytes(map));
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[CAPS]: " + e);
            }

            return(new byte[0]);
        }
        private void SendMessageToGroup(IClientAPI remoteClient, GridInstantMessage im, UUID groupID)
        {
            if (m_debugEnabled)
            {
                m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            List <UUID>     muters;
            IMuteListModule m_muteListModule = m_sceneList[0].RequestModuleInterface <IMuteListModule>();

            if (m_muteListModule != null)
            {
                muters = m_muteListModule.GetInverseMuteList(remoteClient.AgentId);
            }
            else
            {
                muters = new List <UUID>();
            }

            List <GroupMembersData> members = m_groupsModule.GroupMembersRequest(null, null, UUID.Zero, groupID);

            foreach (GroupMembersData member in members)
            {
                if (HasAgentDroppedSession(member.AgentID.Guid, im.imSessionID))
                {
                    // Don't deliver messages to people who have dropped this session
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
                    }
                    continue;
                }

                if (member.OnlineStatus == false)
                {
                    continue;
                }
                if ((member.AgentPowers & (ulong)GroupPowers.JoinChat) != (ulong)GroupPowers.JoinChat)
                {
                    continue;
                }
                if (muters.Contains(member.AgentID))
                {   // Don't deliver messages to people who have the sender muted.
                    continue;
                }

                // Copy Message
                GridInstantMessage msg = new GridInstantMessage();
                msg.imSessionID    = groupID.Guid;
                msg.fromAgentName  = im.fromAgentName;
                msg.message        = im.message;
                msg.dialog         = im.dialog;
                msg.offline        = im.offline;
                msg.ParentEstateID = im.ParentEstateID;
                msg.Position       = im.Position;
                msg.RegionID       = im.RegionID;
                msg.binaryBucket   = im.binaryBucket;
                msg.timestamp      = (uint)Util.UnixTimeSinceEpoch();

                // Update pertinent fields to make it a "group message"
                msg.fromAgentID = im.fromAgentID;
                msg.fromGroup   = true;

                msg.toAgentID = member.AgentID.Guid;

                IClientAPI client = GetActiveClient(member.AgentID);
                if (client == null)
                {
                    // If they're not local, forward across the grid
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID);
                    }
                    m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { });
                }
                else
                {
                    // Deliver locally, directly
                    if (m_debugEnabled)
                    {
                        m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name);
                    }
                    ProcessMessageFromGroupSession(msg);
                }
            }
        }