Ejemplo n.º 1
0
        protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID,
                                          bool agentIsLeaving)
        {
            if (m_SimulationService == null)
            {
                MainConsole.Instance.Debug("[AGENT HANDLER]: Agent GET called. Harmless but useless.");
                responsedata["content_type"]        = "application/json";
                responsedata["int_response_code"]   = HttpStatusCode.NotImplemented;
                responsedata["str_response_string"] = string.Empty;

                return;
            }

            GridRegion destination = new GridRegion {
                RegionID = regionID
            };

            AgentData        agent = null;
            AgentCircuitData circuitData;
            bool             result    = m_SimulationService.RetrieveAgent(destination, id, agentIsLeaving, out agent, out circuitData);
            OSDMap           map       = new OSDMap();
            string           strBuffer = "";

            if (result)
            {
                if (agent != null) // just to make sure
                {
                    map["AgentData"]   = agent.Pack();
                    map["CircuitData"] = circuitData.PackAgentCircuitData();
                    try
                    {
                        strBuffer = OSDParser.SerializeJsonString(map);
                    }
                    catch (Exception e)
                    {
                        MainConsole.Instance.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e);
                        responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
                        // ignore. buffer will be empty, caller should check.
                    }
                }
                else
                {
                    map           = new OSDMap();
                    map["Result"] = "Internal error";
                }
            }
            else
            {
                map           = new OSDMap();
                map["Result"] = "Not Found";
            }
            strBuffer = OSDParser.SerializeJsonString(map);

            responsedata["content_type"]        = "application/json";
            responsedata["int_response_code"]   = HttpStatusCode.OK;
            responsedata["str_response_string"] = strBuffer;
        }
Ejemplo n.º 2
0
        protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID)
        {
            if (m_SimulationService == null)
            {
                m_log.Debug("[AGENT HANDLER]: Agent GET called. Harmless but useless.");
                responsedata["content_type"]        = "application/json";
                responsedata["int_response_code"]   = HttpStatusCode.NotImplemented;
                responsedata["str_response_string"] = string.Empty;

                return;
            }

            GridRegion destination = new GridRegion();

            destination.RegionID = regionID;

            IAgentData agent  = null;
            bool       result = m_SimulationService.RetrieveAgent(destination, id, out agent);
            OSDMap     map    = null;

            if (result)
            {
                if (agent != null) // just to make sure
                {
                    map = agent.Pack();
                    string strBuffer = "";
                    try
                    {
                        strBuffer = OSDParser.SerializeJsonString(map);
                    }
                    catch (Exception e)
                    {
                        m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
                        responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
                        // ignore. buffer will be empty, caller should check.
                    }

                    responsedata["content_type"]        = "application/json";
                    responsedata["int_response_code"]   = HttpStatusCode.OK;
                    responsedata["str_response_string"] = strBuffer;
                }
                else
                {
                    responsedata["int_response_code"]   = HttpStatusCode.InternalServerError;
                    responsedata["str_response_string"] = "Internal error";
                }
            }
            else
            {
                responsedata["int_response_code"]   = HttpStatusCode.NotFound;
                responsedata["str_response_string"] = "Not Found";
            }
        }
Ejemplo n.º 3
0
        private Hashtable TeleportLocation(Hashtable mDhttpMethod, UUID agentID)
        {
            Hashtable responsedata = new Hashtable();

            responsedata["int_response_code"] = 200; //501; //410; //404;
            responsedata["content_type"]      = "text/plain";
            responsedata["keepalive"]         = false;

            OSDMap  rm       = (OSDMap)OSDParser.DeserializeLLSDXml((string)mDhttpMethod["requestbody"]);
            OSDMap  pos      = rm["LocationPos"] as OSDMap;
            Vector3 position = new Vector3((float)pos["X"].AsReal(),
                                           (float)pos["Y"].AsReal(),
                                           (float)pos["Z"].AsReal());
            OSDMap lookat = rm["LocationLookAt"] as OSDMap;
            // this vector does not appear to be used
            Vector3 lookAt = new Vector3((float)lookat["X"].AsReal(),
                                         (float)lookat["Y"].AsReal(),
                                         (float)lookat["Z"].AsReal());
            ulong      RegionHandle = rm["RegionHandle"].AsULong();
            const uint tpFlags      = 16;

            OSDMap retVal = new OSDMap();
            string reason = "";
            int    x, y;

            Util.UlongToInts(RegionHandle, out x, out y);
            GridRegion destination = m_service.Registry.RequestModuleInterface <IGridService>().GetRegionByPosition(UUID.Zero,
                                                                                                                    x, y);
            ISimulationService simService  = m_service.Registry.RequestModuleInterface <ISimulationService>();
            AgentData          ad          = new AgentData();
            AgentCircuitData   circuitData = null;

            if (destination != null)
            {
                simService.RetrieveAgent(m_service.Region, m_service.AgentID, true, out ad, out circuitData);
                if (ad != null)
                {
                    ad.Position = position;
                }
            }
            if (destination == null || circuitData == null)
            {
                retVal.Add("reason", "Could not find the destination region.");
                retVal.Add("success", OSD.FromBoolean(false));
                responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(retVal);
                return(responsedata);
            }
            circuitData.reallyischild = false;
            circuitData.child         = false;
            if (m_agentProcessing.TeleportAgent(ref destination, tpFlags, ad == null ? 0 : (int)ad.Far, circuitData, ad,
                                                m_service.AgentID, m_service.RegionHandle, out reason))
            {
                retVal.Add("success", OSD.FromBoolean(true));
                if (m_service.RegionHandle != destination.RegionHandle)
                {
                    simService.MakeChildAgent(m_service.AgentID, m_service.Region);
                }
            }
            else
            {
                simService.FailedToMoveAgentIntoNewRegion(m_service.AgentID, destination.RegionID);
                retVal.Add("reason", reason);
                retVal.Add("success", OSD.FromBoolean(false));
            }

            //Send back data
            responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(retVal);
            return(responsedata);
        }
Ejemplo n.º 4
0
        byte[] TeleportLocation(Stream request, UUID agentID)
        {
            OSDMap retVal = new OSDMap();

            if (_isInTeleportCurrently)
            {
                retVal.Add("reason", "Duplicate teleport request.");
                retVal.Add("success", OSD.FromBoolean(false));
                return(OSDParser.SerializeLLSDXmlBytes(retVal));
            }
            _isInTeleportCurrently = true;

            OSDMap  rm       = (OSDMap)OSDParser.DeserializeLLSDXml(HttpServerHandlerHelpers.ReadFully(request));
            OSDMap  pos      = rm ["LocationPos"] as OSDMap;
            Vector3 position = new Vector3(
                (float)pos ["X"].AsReal(),
                (float)pos ["Y"].AsReal(),
                (float)pos ["Z"].AsReal());

            /*OSDMap lookat = rm["LocationLookAt"] as OSDMap;
             * Vector3 lookAt = new Vector3((float)lookat["X"].AsReal(),
             *  (float)lookat["Y"].AsReal(),
             *  (float)lookat["Z"].AsReal());*/
            ulong      RegionHandle = rm ["RegionHandle"].AsULong();
            const uint tpFlags      = 16;

            if (m_service.ClientCaps.GetRootCapsService().RegionHandle != m_service.RegionHandle)
            {
                retVal.Add("reason", "Contacted by non-root region for teleport. Protocol implementation is wrong.");
                retVal.Add("success", OSD.FromBoolean(false));
                return(OSDParser.SerializeLLSDXmlBytes(retVal));
            }

            string reason = "";
            int    x, y;

            Util.UlongToInts(RegionHandle, out x, out y);
            GridRegion destination = m_service.Registry.RequestModuleInterface <IGridService> ().GetRegionByPosition(
                m_service.ClientCaps.AccountInfo.AllScopeIDs, x, y);
            ISimulationService simService  = m_service.Registry.RequestModuleInterface <ISimulationService> ();
            AgentData          ad          = new AgentData();
            AgentCircuitData   circuitData = null;

            if (destination != null)
            {
                simService.RetrieveAgent(m_service.Region, m_service.AgentID, true, out ad, out circuitData);
                if (ad != null)
                {
                    ad.Position = position;
                    ad.Center   = position;
                    circuitData.StartingPosition = position;
                }
            }
            if (destination == null || circuitData == null)
            {
                retVal.Add("reason", "Could not find the destination region.");
                retVal.Add("success", OSD.FromBoolean(false));
                return(OSDParser.SerializeLLSDXmlBytes(retVal));
            }
            circuitData.IsChildAgent = false;

            if (m_agentProcessing.TeleportAgent(ref destination, tpFlags, circuitData, ad,
                                                m_service.AgentID, m_service.RegionID, out reason) || reason == "")
            {
                retVal.Add("success", OSD.FromBoolean(true));
            }
            else
            {
                if (reason != "Already in a teleport")
                {
                    //If this error occurs... don't kick them out of their current region
                    simService.FailedToMoveAgentIntoNewRegion(m_service.AgentID, destination);
                }
                retVal.Add("reason", reason);
                retVal.Add("success", OSD.FromBoolean(false));
            }

            //Send back data
            _isInTeleportCurrently = false;
            return(OSDParser.SerializeLLSDXmlBytes(retVal));
        }
Ejemplo n.º 5
0
        public bool TeleportAgent(GridRegion destination, uint TeleportFlags, int DrawDistance,
                                  AgentCircuitData circuit, AgentData agentData, UUID AgentID, ulong requestingRegion,
                                  out string reason)
        {
            IClientCapsService       clientCaps = m_registry.RequestModuleInterface <ICapsService>().GetClientCapsService(AgentID);
            IRegionClientCapsService regionCaps = clientCaps.GetCapsService(requestingRegion);

            if (regionCaps == null || !regionCaps.RootAgent)
            {
                reason = "";
                return(false);
            }

            bool result = false;

            try
            {
                bool callWasCanceled = false;

                ISimulationService SimulationService = m_registry.RequestModuleInterface <ISimulationService>();
                if (SimulationService != null)
                {
                    //Set the user in transit so that we block duplicate tps and reset any cancelations
                    if (!SetUserInTransit(AgentID))
                    {
                        reason = "Already in a teleport";
                        return(false);
                    }

                    //Note: we have to pull the new grid region info as the one from the region cannot be trusted
                    IGridService GridService = m_registry.RequestModuleInterface <IGridService>();
                    if (GridService != null)
                    {
                        destination = GridService.GetRegionByUUID(UUID.Zero, destination.RegionID);
                        //Inform the client of the neighbor if needed
                        circuit.child = false; //Force child status to the correct type

                        if (!InformClientOfNeighbor(AgentID, requestingRegion, circuit, destination, TeleportFlags,
                                                    agentData, out reason))
                        {
                            ResetFromTransit(AgentID);
                            return(false);
                        }
                    }
                    else
                    {
                        reason = "Could not find the grid service";
                        ResetFromTransit(AgentID);
                        return(false);
                    }

                    IEventQueueService EQService = m_registry.RequestModuleInterface <IEventQueueService>();

                    IRegionClientCapsService otherRegion = clientCaps.GetCapsService(destination.RegionHandle);

                    EQService.TeleportFinishEvent(destination.RegionHandle, destination.Access, destination.ExternalEndPoint, otherRegion.CapsUrl,
                                                  4, AgentID, TeleportFlags,
                                                  destination.RegionSizeX, destination.RegionSizeY,
                                                  requestingRegion);

                    // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
                    // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
                    // that the client contacted the destination before we send the attachments and close things here.

                    result = WaitForCallback(AgentID, out callWasCanceled);
                    if (!result)
                    {
                        //It says it failed, lets call the sim and check
                        IAgentData data = null;
                        result = SimulationService.RetrieveAgent(destination, AgentID, out data);
                    }
                    if (!result)
                    {
                        if (!callWasCanceled)
                        {
                            m_log.Warn("[AgentProcessing]: Callback never came for teleporting agent " +
                                       AgentID + ". Resetting.");
                        }
                        INeighborService service = m_registry.RequestModuleInterface <INeighborService>();
                        if (service != null)
                        {
                            //Close the agent at the place we just created if it isn't a neighbor
                            if (service.IsOutsideView(regionCaps.RegionX, destination.RegionLocX, regionCaps.Region.RegionSizeX, destination.RegionSizeX,
                                                      regionCaps.RegionY, destination.RegionLocY, regionCaps.Region.RegionSizeY, destination.RegionSizeY))
                            {
                                SimulationService.CloseAgent(destination, AgentID);
                            }
                        }
                        clientCaps.RemoveCAPS(destination.RegionHandle);
                        if (!callWasCanceled)
                        {
                            reason = "The teleport timed out";
                        }
                        else
                        {
                            reason = "Cancelled";
                        }
                    }
                    else
                    {
                        //Fix the root agent status
                        otherRegion.RootAgent = true;
                        regionCaps.RootAgent  = false;

                        // Next, let's close the child agent connections that are too far away.
                        CloseNeighborAgents(regionCaps.Region, destination, AgentID);
                        reason = "";
                    }
                }
                else
                {
                    reason = "No SimulationService found!";
                }
            }
            catch (Exception ex)
            {
                m_log.WarnFormat("[AgentProcessing]: Exception occured during agent teleport, {0}", ex.ToString());
                reason = "Exception occured.";
            }
            //All done
            ResetFromTransit(AgentID);
            return(result);
        }