Example #1
0
        private bool SendAndGetBoolReply(UUID avatarID, Dictionary <string, object> sendData)
        {
            string reqString = WebUtils.BuildQueryString(sendData);

            // MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
            try
            {
                List <string> m_ServerURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf(avatarID.ToString(), "UserAccountServerURI");
                foreach (string m_ServerURI in m_ServerURIs)
                {
                    string reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                             m_ServerURI + "/accounts",
                                                                             reqString);
                    if (reply != string.Empty)
                    {
                        Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                        if (replyData.ContainsKey("result"))
                        {
                            if (replyData["result"].ToString().ToLower() == "success")
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field");
                        }
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply");
                    }
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: Exception when contacting user account server: {0}", e.Message);
            }

            return(false);
        }
        public bool Delete(Dictionary <string, object> sendData, string PrincipalID, string Friend)
        {
            string        reply = string.Empty;
            List <string> urls  = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AvatarServerURI");

            foreach (string uri in urls)
            {
                try
                {
                    reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, WebUtils.BuildQueryString(sendData));
                }
                catch (Exception e)
                {
                    MainConsole.Instance.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
                    return(false);
                }

                if (reply != string.Empty)
                {
                    Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                    if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null))
                    {
                        bool success = false;
                        Boolean.TryParse(replyData["Result"].ToString(), out success);
                        return(success);
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend {0} {1} received null response",
                                                         PrincipalID, Friend);
                    }
                }
                else
                {
                    MainConsole.Instance.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend received null reply");
                }
            }

            return(false);
        }
Example #3
0
        private UserAccount SendAndGetReply(UUID avatarID, Dictionary <string, object> sendData)
        {
            string reply     = string.Empty;
            string reqString = WebUtils.BuildQueryString(sendData);
            // MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
            UserAccount   account      = null;
            List <string> m_ServerURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf(avatarID.ToString(), "UserAccountServerURI", true);

            foreach (string m_ServerURI in m_ServerURIs)
            {
                try
                {
                    reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                      m_ServerURI,
                                                                      reqString);
                    if (reply == string.Empty)
                    {
                        continue;
                    }

                    Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                    if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
                    {
                        if (replyData["result"] is Dictionary <string, object> )
                        {
                            account = new UserAccount();
                            account.FromKVP((Dictionary <string, object>)replyData["result"]);
                            account.GenericData["GridURL"] = m_ServerURI.Remove(m_ServerURI.LastIndexOf('/'));
                            return(account);
                        }
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.InfoFormat("[ACCOUNT CONNECTOR]: Exception when contacting user account server: {0}", e.Message);
                }
            }

            return(account);
        }
Example #4
0
        protected bool Set(Dictionary <string, object> sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt)
        {
            sendData["UserID"]   = userID;
            sendData["RegionID"] = regionID.ToString();
            sendData["Position"] = position.ToString();
            sendData["LookAt"]   = lookAt.ToString();

            string reqString = WebUtils.BuildQueryString(sendData);

            // MainConsole.Instance.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString);
            try
            {
                List <string> urls = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("GridUserServerURI");
                foreach (string url in urls)
                {
                    string reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                             url,
                                                                             reqString);
                    if (reply != string.Empty)
                    {
                        Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                        if (replyData.ContainsKey("result"))
                        {
                            if (replyData["result"].ToString().ToLower() == "success")
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            { }

            return(false);
        }
Example #5
0
        public bool DeregisterRegion(GridRegion region)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["REGIONID"] = region.RegionID.ToString();

            sendData["METHOD"] = "deregister";

            List <string> serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("GridServerURI");

            foreach (string uri in serverURIs)
            {
                try
                {
                    string reply
                        = SynchronousRestFormsRequester.MakeRequest("POST", uri, WebUtils.BuildQueryString(sendData));

                    if (reply != string.Empty)
                    {
                        Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                        if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply");
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
                }
            }

            return(false);
        }
Example #6
0
        private void Call(OpenSim.Services.Interfaces.GridRegion region, Dictionary <string, object> sendData)
        {
            Util.FireAndForget(delegate(object o)
            {
                string reqString = WebUtils.BuildQueryString(sendData);
                //MainConsole.Instance.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
                if (region == null)
                {
                    return;
                }

                try
                {
                    string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
                    string a   = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                           url + "/friends",
                                                                           reqString);
                }
                catch (Exception)
                {
                }
            });
        }
        private Dictionary <string, object> MakeRequest(string method,
                                                        Dictionary <string, object> sendData)
        {
            sendData["METHOD"] = method;

            List <string> serverURIs = m_registry == null
                                          ? null
                                          : m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf(
                "InventoryServerURI");

            if (m_url != "")
            {
                serverURIs = new List <string>(new string[1] {
                    m_url
                });
            }
            return((from m_ServerURI in serverURIs
                    select
                    SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI,
                                                              WebUtils.BuildQueryString(sendData))
                    into reply
                    where reply != ""
                    select WebUtils.ParseXmlResponse(reply)).FirstOrDefault());
        }
        public bool SetAvatar(UUID userID, AvatarData avatar)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            //sendData["SCOPEID"] = scopeID.ToString();
            sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
            sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
            sendData["METHOD"]     = "setavatar";

            sendData["UserID"] = userID.ToString();

            Dictionary <string, object> structData = avatar.ToKVP();

#if (!ISWIN)
            foreach (KeyValuePair <string, object> kvp in structData)
            {
                if (kvp.Key != "Textures")
                {
                    sendData[kvp.Key] = kvp.Value.ToString();
                }
            }
#else
            foreach (KeyValuePair <string, object> kvp in structData.Where(kvp => kvp.Key != "Textures"))
            {
                sendData[kvp.Key] = kvp.Value.ToString();
            }
#endif

            ResetAvatar(userID);
            string reqString = WebUtils.BuildQueryString(sendData);
            //MainConsole.Instance.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
            try
            {
                List <string> serverURIs =
                    m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AvatarServerURI");
                foreach (string mServerUri in serverURIs)
                {
                    string reply = SynchronousRestFormsRequester.MakeRequest("POST", mServerUri, reqString);
                    if (reply != string.Empty)
                    {
                        Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                        if (replyData.ContainsKey("result"))
                        {
                            if (replyData["result"].ToString().ToLower() == "success")
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            MainConsole.Instance.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field");
                        }
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply");
                    }
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
            }

            return(false);
        }
Example #9
0
        public List <UserAccount> GetUserAccounts(List <UUID> scopeIDs, string query)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            //sendData["SCOPEID"] = scopeID.ToString();
            sendData["VERSIONMIN"] = 0.ToString();
            sendData["VERSIONMAX"] = 0.ToString();
            sendData["METHOD"]     = "getaccounts";

            sendData["ScopeID"] = GetScopeID(scopeIDs);
            sendData["query"]   = query;

            string reply     = string.Empty;
            string reqString = WebUtils.BuildQueryString(sendData);
            // MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString);
            List <UserAccount> accounts = new List <UserAccount>();

            try
            {
                List <string> m_ServerURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("UserAccountServerURI");
                foreach (string m_ServerURI in m_ServerURIs)
                {
                    reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                      m_ServerURI,
                                                                      reqString);
                    if (reply == null || (reply != null && reply == string.Empty))
                    {
                        continue;
                    }

                    Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                    if (replyData != null)
                    {
                        if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null")
                        {
                            continue;
                        }

                        Dictionary <string, object> .ValueCollection accountList = replyData.Values;
                        //MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
                        foreach (object acc in accountList)
                        {
                            if (acc is Dictionary <string, object> )
                            {
                                UserAccount pinfo = new UserAccount();
                                pinfo.FromKVP((Dictionary <string, object>)acc);
                                pinfo.GenericData["GridURL"] = m_ServerURI.Remove(m_ServerURI.LastIndexOf('/'));
                                accounts.Add(pinfo);
                            }
                            else
                            {
                                MainConsole.Instance.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}",
                                                                 acc.GetType());
                            }
                        }
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response");
                    }
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.InfoFormat("[ACCOUNT CONNECTOR]: Exception when contacting accounts server: {0}", e.Message);
            }

            return(accounts);
        }
Example #10
0
        public List <string> GetAgentsLocations(string requestor, List <string> userIDs)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            //sendData["SCOPEID"] = scopeID.ToString();
            sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
            sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
            sendData["METHOD"]     = "getagents";

            sendData["uuids"] = userIDs;

            List <string> rinfos = new List <string>();
            List <string> urls   =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("PresenceServerURI");

            foreach (string url in urls)
            {
                string reply     = string.Empty;
                string reqString = WebUtils.BuildQueryString(sendData);
                //MainConsole.Instance.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
                try
                {
                    reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                      url,
                                                                      reqString);
                    if (reply == null || (reply != null && reply == string.Empty))
                    {
                        return(null);
                    }
                }
                catch (Exception)
                {
                }

                Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                if (replyData != null)
                {
                    if (replyData.ContainsKey("result") &&
                        (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
                    {
                        return(new List <string>());
                    }

                    Dictionary <string, object> .ValueCollection pinfosList = replyData.Values;
#if (!ISWIN)
                    foreach (object presence in pinfosList)
                    {
                        if (presence is Dictionary <string, object> )
                        {
                            string regionUUID = ((Dictionary <string, object>)presence)["RegionID"].ToString();
                            rinfos.Add(GetRegionService(UUID.Parse(regionUUID)));
                        }
                    }
#else
                    rinfos.AddRange(pinfosList.OfType <Dictionary <string, object> >().Select(presence => (presence)["RegionID"].ToString()).Select(regionUUID => GetRegionService(UUID.Parse(regionUUID))));
#endif
                }
            }

            return(rinfos);
        }
Example #11
0
        public List <GridRegion> GetFallbackRegions(List <UUID> scopeIDs, int x, int y)
        {
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            sendData["SCOPEID"] = GetScopeID(scopeIDs);
            sendData["X"]       = x.ToString();
            sendData["Y"]       = y.ToString();

            sendData["METHOD"] = "get_fallback_regions";

            List <GridRegion> rinfos     = new List <GridRegion>();
            string            reply      = string.Empty;
            List <string>     serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("GridServerURI");

            foreach (string uri in serverURIs)
            {
                try
                {
                    reply = SynchronousRestFormsRequester.MakeRequest("POST",
                                                                      uri,
                                                                      WebUtils.BuildQueryString(sendData));

                    //MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
                    return(rinfos);
                }

                if (reply != string.Empty)
                {
                    Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                    if (replyData != null)
                    {
                        Dictionary <string, object> .ValueCollection rinfosList = replyData.Values;
                        foreach (object r in rinfosList)
                        {
                            if (r is Dictionary <string, object> )
                            {
                                GridRegion rinfo = new GridRegion();
                                rinfo.FromKVP((Dictionary <string, object>)r);
                                rinfos.Add(rinfo);
                            }
                        }
                    }
                    else
                    {
                        MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}-{1} received null response",
                                                         x, y);
                    }
                }
                else
                {
                    MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply");
                }
            }

            return(FixGridRegions(rinfos));
        }
Example #12
0
        public RegisterRegion RegisterRegion(GridRegion regionInfo, UUID oldSessionID, string password)
        {
            Dictionary <string, object> rinfo    = regionInfo.ToKVP();
            Dictionary <string, object> sendData = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> kvp in rinfo)
            {
                sendData[kvp.Key] = kvp.Value.ToString();
            }

            sendData["SCOPEID"]    = UUID.Zero.ToString();
            sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
            sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
            sendData["METHOD"]     = "register";

            string        reqString  = WebUtils.BuildQueryString(sendData);
            List <string> serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("GridServerURI");

            foreach (string uri in serverURIs)
            {
                // MainConsole.Instance.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
                try
                {
                    string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
                    if (reply != string.Empty)
                    {
                        Dictionary <string, object> replyData = WebUtils.ParseXmlResponse(reply);

                        if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success"))
                        {
                            return(new RegisterRegion()
                            {
                                Error = ""
                            });
                        }
                        else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure"))
                        {
                            MainConsole.Instance.ErrorFormat(
                                "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri);

                            return(new RegisterRegion()
                            {
                                Error = replyData["Message"].ToString()
                            });
                        }
                        else if (!replyData.ContainsKey("Result"))
                        {
                            MainConsole.Instance.ErrorFormat(
                                "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri);
                        }
                        else
                        {
                            MainConsole.Instance.ErrorFormat(
                                "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri);

                            return(new RegisterRegion()
                            {
                                Error = "Unexpected result " + replyData["Result"].ToString()
                            });
                        }
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri);
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message);
                }
            }

            return(new RegisterRegion()
            {
                Error = string.Format("Error communicating with the grid service")
            });
        }