Exemplo 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;
        }
        public virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags,
                                        AgentData data, out int requestedUDPPort, out string reason)
        {
            reason = String.Empty;
            // Try local first
            if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, data, out requestedUDPPort,
                                           out reason))
                return true;
            requestedUDPPort = destination.ExternalEndPoint.Port; //Just make sure..

            reason = String.Empty;

            string uri = MakeUri(destination, true) + aCircuit.AgentID + "/";

            try
            {
                OSDMap args = aCircuit.PackAgentCircuitData();

                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());
                args["teleport_flags"] = OSD.FromString(teleportFlags.ToString());
                if (data != null)
                    args["agent_data"] = data.Pack();

                string resultStr = WebUtils.PostToService(uri, args);
                //Pull out the result and set it as the reason
                if (resultStr == "")
                    return false;
                OSDMap result = OSDParser.DeserializeJson(resultStr) as OSDMap;
                reason = result["reason"] != null ? result["reason"].AsString() : "";
                if (result["success"].AsBoolean())
                {
                    //Not right... don't return true except for opensim combatibility :/
                    if (reason == "" || reason == "authorized")
                        return true;
                    //We were able to contact the region
                    try
                    {
                        //We send the CapsURLs through, so we need these
                        OSDMap responseMap = (OSDMap) OSDParser.DeserializeJson(reason);
                        if (responseMap.ContainsKey("Reason"))
                            reason = responseMap["Reason"].AsString();
                        if (responseMap.ContainsKey("requestedUDPPort"))
                            requestedUDPPort = responseMap["requestedUDPPort"];
                        return result["success"].AsBoolean();
                    }
                    catch
                    {
                        //Something went wrong
                        return false;
                    }
                }

                reason = result.ContainsKey("Message") ? result["Message"].AsString() : "Could not contact the region";
                return false;
            }
            catch (Exception e)
            {
                MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e);
                reason = e.Message;
            }

            return false;
        }
        public virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags,
                                        AgentData data, out int requestedUDPPort, out string reason)
        {
            reason = String.Empty;
            // Try local first
            if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, data, out requestedUDPPort,
                                           out reason))
            {
                return(true);
            }
            requestedUDPPort = destination.ExternalEndPoint.Port; //Just make sure..

            reason = String.Empty;

            string uri = MakeUri(destination, true) + aCircuit.AgentID + "/";

            try
            {
                OSDMap args = aCircuit.PackAgentCircuitData();

                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());
                args["teleport_flags"]   = OSD.FromString(teleportFlags.ToString());
                if (data != null)
                {
                    args["agent_data"] = data.Pack();
                }

                string resultStr = WebUtils.PostToService(uri, args);
                //Pull out the result and set it as the reason
                if (resultStr == "")
                {
                    return(false);
                }
                OSDMap result = OSDParser.DeserializeJson(resultStr) as OSDMap;
                reason = result["reason"] != null ? result["reason"].AsString() : "";
                if (result["success"].AsBoolean())
                {
                    //Not right... don't return true except for opensim combatibility :/
                    if (reason == "" || reason == "authorized")
                    {
                        return(true);
                    }
                    //We were able to contact the region
                    try
                    {
                        //We send the CapsURLs through, so we need these
                        OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason);
                        if (responseMap.ContainsKey("Reason"))
                        {
                            reason = responseMap["Reason"].AsString();
                        }
                        if (responseMap.ContainsKey("requestedUDPPort"))
                        {
                            requestedUDPPort = responseMap["requestedUDPPort"];
                        }
                        return(result["success"].AsBoolean());
                    }
                    catch
                    {
                        //Something went wrong
                        return(false);
                    }
                }

                reason = result.ContainsKey("Message") ? result["Message"].AsString() : "Could not contact the region";
                return(false);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e);
                reason = e.Message;
            }

            return(false);
        }
Exemplo n.º 4
0
        public static OSDMap TeleportAgent(int DrawDistance, AgentCircuitData circuit,
                                           AgentData data, uint TeleportFlags,
                                           GridRegion destination, ulong requestingRegion)
        {
            OSDMap llsdBody = new OSDMap
                                  {
                                      {"DrawDistance", DrawDistance},
                                      {"Circuit", circuit.PackAgentCircuitData()},
                                      {"TeleportFlags", TeleportFlags},
                                      {"AgentData", data.Pack()},
                                      {"Region", destination.ToOSD()}
                                  };

            return buildEvent("TeleportAgent", llsdBody, circuit.AgentID, requestingRegion);
        }
Exemplo n.º 5
0
        public static OSDMap CrossAgent(GridRegion crossingRegion, Vector3 pos,
                                        Vector3 velocity, AgentCircuitData circuit, AgentData cAgent,
                                        ulong RequestingRegion)
        {
            OSDMap llsdBody = new OSDMap
                                  {
                                      {"Pos", pos},
                                      {"Vel", velocity},
                                      {"Region", crossingRegion.ToOSD()},
                                      {"Circuit", circuit.PackAgentCircuitData()},
                                      {"AgentData", cAgent.Pack()}
                                  };

            return buildEvent("CrossAgent", llsdBody, circuit.AgentID, RequestingRegion);
        }
Exemplo n.º 6
0
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, AgentData data, out string reason)
        {
            reason = String.Empty;
            // Try local first
            if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, data, out reason))
            {
                return(true);
            }

            reason = String.Empty;

            string uri = MakeUri(destination, true) + aCircuit.AgentID + "/";

            try
            {
                OSDMap args = aCircuit.PackAgentCircuitData();

                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());
                args["teleport_flags"]   = OSD.FromString(teleportFlags.ToString());
                if (data != null)
                {
                    args["agent_data"] = data.Pack();
                }

                OSDMap result  = WebUtils.PostToService(uri, args);
                OSDMap results = WebUtils.GetOSDMap(result["_RawResult"].AsString());
                //Pull out the result and set it as the reason
                if (results == null)
                {
                    return(false);
                }
                reason = results["reason"] != null ? results["reason"].AsString() : "";
                if (result["Success"].AsBoolean())
                {
                    try
                    {
                        OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason);
                        if (responseMap.ContainsKey("Reason"))
                        {
                            reason = responseMap["Reason"].AsString();
                        }
                        return(responseMap["Success"].AsBoolean());
                    }
                    catch
                    {
                        //Not right... don't return true except for opensim combatibility :/
                        return(true);
                    }
                }

                reason = result["Message"] != null ? result["Message"].AsString() : "error";
                return(false);
            }
            catch (Exception e)
            {
                m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
                reason = e.Message;
            }

            return(false);
        }