public GroupMembershipData SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["AgentID"]           = AgentID.ToString();
            sendData["GroupID"]           = GroupID.ToString();
            sendData["RequestingAgentID"] = RequestingAgentID;
            sendData["OP"] = "GROUP";

            Dictionary <string, object> ret = MakeRequest("SETACTIVE", sendData);

            if (ret == null)
            {
                return(null);
            }

            if (!ret.ContainsKey("RESULT"))
            {
                return(null);
            }

            if (ret["RESULT"].ToString() == "NULL")
            {
                return(null);
            }

            return(GroupsDataUtils.GroupMembershipData((Dictionary <string, object>)ret["RESULT"]));
        }
        public List <GroupMembershipData> GetMemberships(string RequestingAgentID, string AgentID)
        {
            List <GroupMembershipData> memberships = new List <GroupMembershipData>();

            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["AgentID"]           = AgentID;
            sendData["ALL"]               = "true";
            sendData["RequestingAgentID"] = RequestingAgentID;
            Dictionary <string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);

            if (ret == null)
            {
                return(memberships);
            }

            if (!ret.ContainsKey("RESULT"))
            {
                return(memberships);
            }

            if (ret["RESULT"].ToString() == "NULL")
            {
                return(memberships);
            }

            foreach (object v in ((Dictionary <string, object>)ret["RESULT"]).Values)
            {
                GroupMembershipData m = GroupsDataUtils.GroupMembershipData((Dictionary <string, object>)v);
                memberships.Add(m);
            }

            return(memberships);
        }
        public ExtendedGroupMembershipData GetMembership(string RequestingAgentID, string AgentID, UUID GroupID)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["AgentID"] = AgentID;
            if (GroupID != UUID.Zero)
            {
                sendData["GroupID"] = GroupID.ToString();
            }
            sendData["RequestingAgentID"] = RequestingAgentID;
            Dictionary <string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);

            if (ret == null)
            {
                return(null);
            }

            if (!ret.ContainsKey("RESULT"))
            {
                return(null);
            }

            if (ret["RESULT"].ToString() == "NULL")
            {
                return(null);
            }

            return(GroupsDataUtils.GroupMembershipData((Dictionary <string, object>)ret["RESULT"]));
        }
        public GroupMembershipData AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
        {
            reason = string.Empty;

            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["AgentID"]           = AgentID;
            sendData["GroupID"]           = GroupID.ToString();
            sendData["RoleID"]            = RoleID.ToString();
            sendData["RequestingAgentID"] = RequestingAgentID;
            sendData["AccessToken"]       = token;
            Dictionary <string, object> ret = MakeRequest("ADDAGENTTOGROUP", sendData);

            if (ret == null)
            {
                return(null);
            }

            if (!ret.ContainsKey("RESULT"))
            {
                return(null);
            }

            if (ret["RESULT"].ToString() == "NULL")
            {
                reason = ret["REASON"].ToString();
                return(null);
            }

            return(GroupsDataUtils.GroupMembershipData((Dictionary <string, object>)ret["RESULT"]));
        }
        byte[] HandleAddAgentToGroup(Dictionary <string, object> request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") ||
                !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID"))
            {
                NullResult(result, "Bad network data");
            }
            else
            {
                UUID   groupID           = new UUID(request["GroupID"].ToString());
                UUID   roleID            = new UUID(request["RoleID"].ToString());
                string agentID           = request["AgentID"].ToString();
                string requestingAgentID = request["RequestingAgentID"].ToString();
                string token             = string.Empty;
                string reason            = string.Empty;

                if (request.ContainsKey("AccessToken"))
                {
                    token = request["AccessToken"].ToString();
                }

                if (!m_GroupsService.AddAgentToGroup(requestingAgentID, agentID, groupID, roleID, token, out reason))
                {
                    NullResult(result, reason);
                }
                else
                {
                    GroupMembershipData membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID);
                    if (membership == null)
                    {
                        NullResult(result, "Internal error");
                    }
                    else
                    {
                        result["RESULT"] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)membership);
                    }
                }
            }

            string xmlString = ServerUtils.BuildXmlResponse(result);

            //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
            return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
        }
        byte[] HandleSetActive(Dictionary <string, object> request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") ||
                !request.ContainsKey("AgentID") || !request.ContainsKey("OP"))
            {
                NullResult(result, "Bad network data");
                string xmlString = ServerUtils.BuildXmlResponse(result);
                return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
            }
            else
            {
                string op = request["OP"].ToString();

                if (op == "GROUP")
                {
                    ExtendedGroupMembershipData group = m_GroupsService.SetAgentActiveGroup(request["RequestingAgentID"].ToString(),
                                                                                            request["AgentID"].ToString(), new UUID(request["GroupID"].ToString()));

                    if (group == null)
                    {
                        NullResult(result, "Internal error");
                    }
                    else
                    {
                        result["RESULT"] = GroupsDataUtils.GroupMembershipData(group);
                    }

                    string xmlString = ServerUtils.BuildXmlResponse(result);

                    //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
                    return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
                }
                else if (op == "ROLE" && request.ContainsKey("RoleID"))
                {
                    m_GroupsService.SetAgentActiveGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(),
                                                            new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString()));
                    result["RESULT"] = "true";
                }

                return(Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)));
            }
        }
        byte[] HandleGetMembership(Dictionary <string, object> request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID"))
            {
                NullResult(result, "Bad network data");
            }
            else
            {
                string agentID = request["AgentID"].ToString();
                UUID   groupID = UUID.Zero;
                if (request.ContainsKey("GroupID"))
                {
                    groupID = new UUID(request["GroupID"].ToString());
                }
                string requestingAgentID = request["RequestingAgentID"].ToString();
                bool   all = request.ContainsKey("ALL");

                if (!all)
                {
                    ExtendedGroupMembershipData membership = null;
                    if (groupID == UUID.Zero)
                    {
                        membership = m_GroupsService.GetAgentActiveMembership(requestingAgentID, agentID);
                    }
                    else
                    {
                        membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID);
                    }

                    if (membership == null)
                    {
                        NullResult(result, "No such membership");
                    }
                    else
                    {
                        result["RESULT"] = GroupsDataUtils.GroupMembershipData(membership);
                    }
                }
                else
                {
                    List <GroupMembershipData> memberships = m_GroupsService.GetAgentGroupMemberships(requestingAgentID, agentID);
                    if (memberships == null || (memberships != null && memberships.Count == 0))
                    {
                        NullResult(result, "No memberships");
                    }
                    else
                    {
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        int i = 0;
                        foreach (GroupMembershipData m in memberships)
                        {
                            dict["m-" + i++] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)m);
                        }

                        result["RESULT"] = dict;
                    }
                }
            }

            string xmlString = ServerUtils.BuildXmlResponse(result);

            //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
            return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
        }