private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
        {
            // Try local first
            if (cAgentData is AgentData)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentData)cAgentData))
                {
                    return(true);
                }
            }
            else if (cAgentData is AgentPosition)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentPosition)cAgentData))
                {
                    return(true);
                }
            }

            // else do the remote thing
            if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
            {
                // Eventually, we want to use a caps url instead of the agentID
                string uri = MakeUri(destination, true) + cAgentData.AgentID + "/";

                if (m_blackListedRegions.ContainsKey(uri))
                {
                    //Check against time
                    if (m_blackListedRegions[uri] > 3 &&
                        Util.EnvironmentTickCountSubtract(m_blackListedRegions[uri]) > 0)
                    {
                        MainConsole.Instance.Warn("[SimServiceConnector]: Blacklisted region " + destination.RegionName + " requested");
                        //Still blacklisted
                        return(false);
                    }
                }
                try
                {
                    OSDMap args = cAgentData.Pack();

                    args["destination_x"]    = OSD.FromString(destination.RegionLocX.ToString());
                    args["destination_y"]    = OSD.FromString(destination.RegionLocY.ToString());
                    args["destination_name"] = OSD.FromString(destination.RegionName);
                    args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());

                    string result = WebUtils.PutToService(uri, args);
                    if (result == "")
                    {
                        if (m_blackListedRegions.ContainsKey(uri))
                        {
                            if (m_blackListedRegions[uri] == 3)
                            {
                                //add it to the blacklist as the request completely failed 3 times
                                m_blackListedRegions[uri] = Util.EnvironmentTickCount() + 60 * 1000; //60 seconds
                            }
                            else if (m_blackListedRegions[uri] == 0)
                            {
                                m_blackListedRegions[uri]++;
                            }
                        }
                        else
                        {
                            m_blackListedRegions[uri] = 0;
                        }
                        return(false);
                    }
                    //Clear out the blacklist if it went through
                    m_blackListedRegions.Remove(uri);

                    OSDMap innerResult = (OSDMap)OSDParser.DeserializeJson(result);
                    return(innerResult["Updated"].AsBoolean());
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e);
                }

                return(false);
            }

            return(false);
        }
Пример #2
0
        private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
        {
            // Try local first
            if (cAgentData is AgentData)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentData)cAgentData))
                {
                    return(true);
                }
            }
            else if (cAgentData is AgentPosition)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentPosition)cAgentData))
                {
                    return(true);
                }
            }

            // else do the remote thing
            if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
            {
                // Eventually, we want to use a caps url instead of the agentID
                string uri = MakeUri(destination, true) + cAgentData.AgentID + "/";

                if (m_blackListedRegions.ContainsKey(uri))
                {
                    //Check against time
                    if (Util.EnvironmentTickCountSubtract(m_blackListedRegions[uri]) > 0)
                    {
                        //Still blacklisted
                        return(false);
                    }
                }

                try
                {
                    OSDMap args = cAgentData.Pack();

                    args["destination_x"]    = OSD.FromString(destination.RegionLocX.ToString());
                    args["destination_y"]    = OSD.FromString(destination.RegionLocY.ToString());
                    args["destination_name"] = OSD.FromString(destination.RegionName);
                    args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());

                    OSDMap result = WebUtils.PutToService(uri, args);
                    if (!result["Success"].AsBoolean())
                    {
                        //add it to the blacklist
                        m_blackListedRegions[uri] = Util.EnvironmentTickCount() + 60 * 1000; //60 seconds
                        return(result["Success"].AsBoolean());
                    }
                    //Clear out the blacklist if it went through
                    m_blackListedRegions.Remove(uri);

                    OSDMap innerResult = (OSDMap)result["_Result"];
                    return(innerResult["Updated"].AsBoolean());
                }
                catch (Exception e)
                {
                    m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
                }

                return(false);
            }

            return(false);
        }