UnpackAgentCircuitData() публичный Метод

Unpack agent circuit data map into an AgentCiruitData object
public UnpackAgentCircuitData ( OSDMap args ) : void
args OSDMap
Результат void
Пример #1
0
 protected object OnGenericEvent(string FunctionName, object parameters)
 {
     if (FunctionName == "NewUserConnection")
     {
         ICapsService service = m_scene.RequestModuleInterface<ICapsService>();
         if (service != null)
         {
             OSDMap param = (OSDMap)parameters;
             AgentCircuitData circuit = new AgentCircuitData();
             circuit.UnpackAgentCircuitData((OSDMap)param["Agent"]);
             service.CreateCAPS(circuit.AgentID, CapsUtil.GetCapsSeedPath(circuit.CapsPath),
                 m_scene.RegionInfo.RegionHandle, !circuit.child, circuit);
             IClientCapsService clientCaps = service.GetClientCapsService(circuit.AgentID);
             if (clientCaps != null)
             {
                 IRegionClientCapsService regionCaps = clientCaps.GetCapsService(m_scene.RegionInfo.RegionHandle);
                 if (regionCaps != null)
                 {
                     regionCaps.AddCAPS((OSDMap)param["CapsUrls"]);
                 }
             }
         }
     }
     else if (FunctionName == "UserStatusChange")
     {
         UserInfo info = (UserInfo)parameters;
         if (!info.IsOnline) //Logging out
         {
             ICapsService service = m_scene.RequestModuleInterface<ICapsService>();
             if (service != null)
             {
                 service.RemoveCAPS(UUID.Parse(info.UserID));
             }
         }
     }
     return null;
 }
        protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = 400;
                responsedata["str_response_string"] = "false";
                return;
            }

            // retrieve the regionhandle
            ulong regionhandle = 0;
            bool authorize = false;
            if (args.ContainsKey("destination_handle"))
                UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
            if (args.ContainsKey("authorize_user")) // not implemented on the sending side yet
                bool.TryParse(args["authorize_user"].AsString(), out authorize);

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message);
                return;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            // This is the meaning of POST agent
            bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, authorize, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = 200;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
Пример #3
0
        protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            // retrieve the input arguments
            int x = 0, y = 0;
            UUID uuid = UUID.Zero;
            string regionname = string.Empty;
            uint teleportFlags = 0;
            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
                Int32.TryParse(args["destination_x"].AsString(), out x);
            else
                m_log.WarnFormat("  -- request didn't have destination_x");
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
                Int32.TryParse(args["destination_y"].AsString(), out y);
            else
                m_log.WarnFormat("  -- request didn't have destination_y");
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
                regionname = args["destination_name"].ToString();
            if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
                teleportFlags = args["teleport_flags"].AsUInteger();

            GridRegion destination = new GridRegion();
            destination.RegionID = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            // This is the meaning of POST agent
            //m_regionClient.AdjustUserInformation(aCircuit);
            //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
            bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);
            // Let's also send out the IP address of the caller back to the caller (HG 1.5)
            resp["your_ip"] = OSD.FromString(GetCallerIP(request));

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = HttpStatusCode.OK;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
        public bool RetrieveAgent(GridRegion destination, UUID id, bool agentIsLeaving, out AgentData agent,
                                  out AgentCircuitData circuitData)
        {
            agent = null;
            // Try local first
            if (m_localBackend.RetrieveAgent(destination, id, agentIsLeaving, out agent, out circuitData))
                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) + id + "/" + destination.RegionID.ToString() + "/" +
                             agentIsLeaving.ToString() + "/";

                try
                {
                    OSDMap result = WebUtils.GetFromService(uri, true, false, false);
                    if (result["Success"].AsBoolean())
                    {
                        OSDMap r = (OSDMap) OSDParser.DeserializeJson(result["_RawResult"]);
                        if (r["Result"] == "Not Found")
                            return false;
                        agent = new AgentData();

                        if (!r.ContainsKey("AgentData"))
                            return false; //Disable old simulators

                        agent.Unpack((OSDMap) r["AgentData"]);
                        circuitData = new AgentCircuitData();
                        circuitData.UnpackAgentCircuitData((OSDMap) r["CircuitData"]);
                        return true;
                    }
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e);
                }

                return false;
            }

            return false;
        }
Пример #5
0
        protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            // retrieve the input arguments
            int x = 0, y = 0;
            UUID uuid = UUID.Zero;
            string regionname = string.Empty;
            string gatekeeper_host = string.Empty;
            int gatekeeper_port = 0;

            if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
                gatekeeper_host = args["gatekeeper_host"].AsString();
            if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
                Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port);

            GridRegion gatekeeper = new GridRegion();
            gatekeeper.ExternalHostName = gatekeeper_host;
            gatekeeper.HttpPort = (uint)gatekeeper_port;
            gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);

            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
                Int32.TryParse(args["destination_x"].AsString(), out x);
            else
                m_log.WarnFormat("  -- request didn't have destination_x");
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
                Int32.TryParse(args["destination_y"].AsString(), out y);
            else
                m_log.WarnFormat("  -- request didn't have destination_y");
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
                regionname = args["destination_name"].ToString();

            GridRegion destination = new GridRegion();
            destination.RegionID = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = HttpStatusCode.OK;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
Пример #6
0
        protected OSDMap OnMessageReceived(OSDMap message)
        {
            if (!message.ContainsKey("Method"))
                return null;

            UUID AgentID = message["AgentID"].AsUUID();
            ulong requestingRegion = message["RequestingRegion"].AsULong();
            ICapsService capsService = m_registry.RequestModuleInterface<ICapsService>();
            if (capsService == null)
            {
                //m_log.Info("[AgentProcessing]: Failed OnMessageReceived ICapsService is null");
                return new OSDMap();
            }
            IClientCapsService clientCaps = capsService.GetClientCapsService(AgentID);

            IRegionClientCapsService regionCaps = null;
            if (clientCaps != null)
                regionCaps = clientCaps.GetCapsService(requestingRegion);
            if (message["Method"] == "LogoutRegionAgents")
            {
                LogOutAllAgentsForRegion(requestingRegion);
            }
            else if (message["Method"] == "RegionIsOnline") //This gets fired when the scene is fully finished starting up
            {
                //Log out all the agents first, then add any child agents that should be in this region
                LogOutAllAgentsForRegion(requestingRegion);
                IGridService GridService = m_registry.RequestModuleInterface<IGridService>();
                if (GridService != null)
                {
                    int x, y;
                    Util.UlongToInts(requestingRegion, out x, out y);
                    GridRegion requestingGridRegion = GridService.GetRegionByPosition(UUID.Zero, x, y);
                    if (requestingGridRegion != null)
                        EnableChildAgentsForRegion(requestingGridRegion);
                }
            }
            else if (message["Method"] == "DisableSimulator")
            {
                //KILL IT!
                if (regionCaps == null || clientCaps == null)
                    return null;
                IEventQueueService eventQueue = m_registry.RequestModuleInterface<IEventQueueService> ();
                eventQueue.DisableSimulator (regionCaps.AgentID, regionCaps.RegionHandle);
                //regionCaps.Close();
                //clientCaps.RemoveCAPS(requestingRegion);
            }
            else if (message["Method"] == "ArrivedAtDestination")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Recieved a callback
                if (clientCaps.InTeleport) //Only set this if we are in a teleport, 
                    //  otherwise (such as on login), this won't check after the first tp!
                    clientCaps.CallbackHasCome = true;

                regionCaps.Disabled = false;

                //The agent is getting here for the first time (eg. login)
                OSDMap body = ((OSDMap)message["Message"]);

                //Parse the OSDMap
                int DrawDistance = body["DrawDistance"].AsInteger();

                AgentCircuitData circuitData = new AgentCircuitData();
                circuitData.UnpackAgentCircuitData((OSDMap)body["Circuit"]);

                //Now do the creation
                EnableChildAgents(AgentID, requestingRegion, DrawDistance, circuitData);
            }
            else if (message["Method"] == "CancelTeleport")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Only the region the client is root in can do this
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService ();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //The user has requested to cancel the teleport, stop them.
                    clientCaps.RequestToCancelTeleport = true;
                    regionCaps.Disabled = false;
                }
            }
            else if (message["Method"] == "AgentLoggedOut")
            {
                //ONLY if the agent is root do we even consider it
                if (regionCaps != null)
                {
                    if (regionCaps.RootAgent)
                    {
                        LogoutAgent(regionCaps);
                    }
                }
            }
            else if (message["Method"] == "SendChildAgentUpdate")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService ();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.Unpack((OSDMap)body["AgentPos"]);

                    SendChildAgentUpdate(pos, regionCaps);
                    regionCaps.Disabled = false;
                }
            }
            else if (message["Method"] == "TeleportAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService ();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    GridRegion destination = new GridRegion();
                    destination.FromOSD((OSDMap)body["Region"]);

                    uint TeleportFlags = body["TeleportFlags"].AsUInteger();
                    int DrawDistance = body["DrawDistance"].AsInteger();

                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]);

                    AgentData AgentData = new AgentData();
                    AgentData.Unpack((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    OSDMap result = new OSDMap();
                    string reason = "";
                    result["Success"] = TeleportAgent(destination, TeleportFlags, DrawDistance,
                        Circuit, AgentData, AgentID, requestingRegion, out reason);
                    result["Reason"] = reason;
                    return result;
                }
            }
            else if (message["Method"] == "CrossAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                if (clientCaps.GetRootCapsService().RegionHandle == regionCaps.RegionHandle)
                {
                    //This is a simulator message that tells us to cross the agent
                    OSDMap body = ((OSDMap)message["Message"]);

                    Vector3 pos = body["Pos"].AsVector3();
                    Vector3 Vel = body["Vel"].AsVector3();
                    GridRegion Region = new GridRegion();
                    Region.FromOSD((OSDMap)body["Region"]);
                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]);
                    AgentData AgentData = new AgentData();
                    AgentData.Unpack((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    OSDMap result = new OSDMap();
                    string reason = "";
                    result["Success"] = CrossAgent(Region, pos, Vel, Circuit, AgentData,
                        AgentID, requestingRegion, out reason);
                    result["Reason"] = reason;
                    return result;
                }
                else if (clientCaps.InTeleport)
                {
                    OSDMap result = new OSDMap ();
                    result["Success"] = false;
                    result["Note"] = false;
                    return result;
                }
                else
                {
                    OSDMap result = new OSDMap ();
                    result["Success"] = false;
                    result["Note"] = false;
                    return result;
                }
            }
            return null;
        }
Пример #7
0
        protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            AgentDestinationData data = CreateAgentDestinationData();
            UnpackData(args, data, request);

            GridRegion destination = new GridRegion();
            destination.RegionID = data.uuid;
            destination.RegionLocX = data.x;
            destination.RegionLocY = data.y;
            destination.RegionName = data.name;

            GridRegion gatekeeper = ExtractGatekeeper(data);

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            GridRegion source = null;

            if (args.ContainsKey("source_uuid"))
            {
                source = new GridRegion();
                source.RegionLocX = Int32.Parse(args["source_x"].AsString());
                source.RegionLocY = Int32.Parse(args["source_y"].AsString());
                source.RegionName = args["source_name"].AsString();
                source.RegionID = UUID.Parse(args["source_uuid"].AsString());
                
                if (args.ContainsKey("source_server_uri"))
                    source.RawServerURI = args["source_server_uri"].AsString();
                else
                    source.RawServerURI = null;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            // This is the meaning of POST agent
            //m_regionClient.AdjustUserInformation(aCircuit);
            //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
            bool result = CreateAgent(source, gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);
            // Let's also send out the IP address of the caller back to the caller (HG 1.5)
            resp["your_ip"] = OSD.FromString(GetCallerIP(request));

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = HttpStatusCode.OK;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
Пример #8
0
        public override byte[] Handle(string path, Stream request,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            byte[] result = new byte[0];

            UUID agentID;
            string action;
            ulong regionHandle;
            if (!RestHandlerUtils.GetParams(path, out agentID, out regionHandle, out action))
            {
                m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path);
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Invalid parameters for agent message " + path;

                return result;
            }

            if (m_AuthenticationService != null)
            {
                // Authentication
                string authority = string.Empty;
                string authToken = string.Empty;
                if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken))
                {
                    m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
                    httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return result;
                }
                // TODO: Rethink this
                //if (!m_AuthenticationService.VerifyKey(agentID, authToken))
                //{
                //    m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
                //    httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
                //    return result;
                //}
                m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID);
            }

            OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength);
            if (args == null)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Unable to retrieve data";
                m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path);
                return result;
            }

            // retrieve the regionhandle
            ulong regionhandle = 0;
            if (args["destination_handle"] != null)
                UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message);
                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                httpResponse.StatusDescription = "Problems with data deserialization";
                return result;
            }

            string reason = string.Empty;

            // We need to clean up a few things in the user service before I can do this
            //if (m_AllowForeignGuests)
            //    m_regionClient.AdjustUserInformation(aCircuit);

            // Finally!
            bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason);

            OSDMap resp = new OSDMap(1);

            resp["success"] = OSD.FromBoolean(success);

            httpResponse.StatusCode = (int)HttpStatusCode.OK;

            return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(resp));
        }
Пример #9
0
        protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = Utils.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            // retrieve the input arguments
            int x = 0, y = 0;
            UUID uuid = UUID.Zero;
            string regionname = string.Empty;
            string gatekeeper_host = string.Empty;
            string gatekeeper_serveruri = string.Empty;
            string destination_serveruri = string.Empty;
            int gatekeeper_port = 0;
            IPEndPoint client_ipaddress = null;

            if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
                gatekeeper_host = args["gatekeeper_host"].AsString();
            if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
                Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port);
            if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] !=null)
                gatekeeper_serveruri = args["gatekeeper_serveruri"];
            if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] !=null)
                destination_serveruri = args["destination_serveruri"];

            GridRegion gatekeeper = new GridRegion();
            gatekeeper.ServerURI = gatekeeper_serveruri;
            gatekeeper.ExternalHostName = gatekeeper_host;
            gatekeeper.HttpPort = (uint)gatekeeper_port;
            gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);

            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
                Int32.TryParse(args["destination_x"].AsString(), out x);
            else
                m_log.WarnFormat("  -- request didn't have destination_x");
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
                Int32.TryParse(args["destination_y"].AsString(), out y);
            else
                m_log.WarnFormat("  -- request didn't have destination_y");
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
                regionname = args["destination_name"].ToString();

            if (args.ContainsKey("client_ip") && args["client_ip"] != null)
            {
                string ip_str = args["client_ip"].ToString();
                try
                {
                    string callerIP = GetCallerIP(request);
                    // Verify if this caller has authority to send the client IP
                    if (callerIP == m_LoginServerIP)
                        client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0);
                    else // leaving this for now, but this warning should be removed
                        m_log.WarnFormat("[HOME AGENT HANDLER]: Unauthorized machine {0} tried to set client ip to {1}", callerIP, ip_str);
                }
                catch
                {
                    m_log.DebugFormat("[HOME AGENT HANDLER]: Exception parsing client ip address from {0}", ip_str);
                }
            }

            GridRegion destination = new GridRegion();
            destination.RegionID = uuid;
            destination.RegionLocX = x;
            destination.RegionLocY = y;
            destination.RegionName = regionname;
            destination.ServerURI = destination_serveruri;
            
            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, client_ipaddress, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = HttpStatusCode.OK;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
Пример #10
0
        protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            OSDMap args = WebUtils.GetOSDMap((string) request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            // retrieve the input arguments
            int x = 0, y = 0;
            UUID uuid = UUID.Zero;
            string regionname = string.Empty;
            uint teleportFlags = 0;
            if (args.ContainsKey("destination_x") && args["destination_x"] != null)
                Int32.TryParse(args["destination_x"].AsString(), out x);
            else
                MainConsole.Instance.WarnFormat("  -- request didn't have destination_x");
            if (args.ContainsKey("destination_y") && args["destination_y"] != null)
                Int32.TryParse(args["destination_y"].AsString(), out y);
            else
                MainConsole.Instance.WarnFormat("  -- request didn't have destination_y");
            if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
                UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
            if (args.ContainsKey("destination_name") && args["destination_name"] != null)
                regionname = args["destination_name"].ToString();
            if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
                teleportFlags = args["teleport_flags"].AsUInteger();

            AgentData agent = null;
            if (args.ContainsKey("agent_data") && args["agent_data"] != null)
            {
                try
                {
                    OSDMap agentDataMap = (OSDMap) args["agent_data"];
                    agent = new AgentData();
                    agent.Unpack(agentDataMap);
                }
                catch (Exception ex)
                {
                    MainConsole.Instance.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex);
                }
            }

            GridRegion destination = new GridRegion
                                         {RegionID = uuid, RegionLocX = x, RegionLocY = y, RegionName = regionname};

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex);
                responsedata["int_response_code"] = HttpStatusCode.BadRequest;
                responsedata["str_response_string"] = "Bad request";
                return;
            }

            OSDMap resp = new OSDMap(3);
            string reason = String.Empty;

            int requestedUDPPort = 0;
            // This is the meaning of POST agent
            bool result = CreateAgent(destination, ref aCircuit, teleportFlags, agent, out requestedUDPPort, out reason);

            resp["reason"] = reason;
            resp["requestedUDPPort"] = requestedUDPPort;
            resp["success"] = OSD.FromBoolean(result);
            // Let's also send out the IP address of the caller back to the caller (HG 1.5)
            resp["your_ip"] = OSD.FromString(GetCallerIP(request));

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = HttpStatusCode.OK;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
        protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
        {
            if (m_safemode)
            {
                // Authentication
                string authority = string.Empty;
                string authToken = string.Empty;
                if (!GetAuthentication(request, out authority, out authToken))
                {
                    m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]);
                    responsedata["int_response_code"] = 403;
                    responsedata["str_response_string"] = "Forbidden";
                    return ;
                }
                if (!VerifyKey(id, authority, authToken))
                {
                    m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]);
                    responsedata["int_response_code"] = 403;
                    responsedata["str_response_string"] = "Forbidden";
                    return ;
                }
                m_log.DebugFormat("[REST COMMS]: Authentication succeeded for {0}", id);
            }

            OSDMap args = RegionClient.GetOSDMap((string)request["body"]);
            if (args == null)
            {
                responsedata["int_response_code"] = 400;
                responsedata["str_response_string"] = "false";
                return;
            }

            // retrieve the regionhandle
            ulong regionhandle = 0;
            if (args["destination_handle"] != null)
                UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);

            AgentCircuitData aCircuit = new AgentCircuitData();
            try
            {
                aCircuit.UnpackAgentCircuitData(args);
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message);
                return;
            }

            OSDMap resp = new OSDMap(2);
            string reason = String.Empty;

            // This is the meaning of POST agent
            m_regionClient.AdjustUserInformation(aCircuit);
            bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, out reason);

            resp["reason"] = OSD.FromString(reason);
            resp["success"] = OSD.FromBoolean(result);

            // TODO: add reason if not String.Empty?
            responsedata["int_response_code"] = 200;
            responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
        }
Пример #12
0
        public override bool HandleIn(RegionSyncModule pRegionContext)
        {
            if (base.HandleIn(pRegionContext))
            {
            // if this is a relay node, forward the message
            if (pRegionContext.IsSyncRelay)
                pRegionContext.SendSpecialUpdateToRelevantSyncConnectors(ConnectorContext.otherSideActorID, this);

            // If we receive a new presence that for some reason indicates this region is its "real region" then ignore it.
            // Maybe we should even send out a message to remove the avatar from other actors?
            if ((string)(((SyncInfoPresence)SyncInfo).CurrentlySyncedProperties[SyncableProperties.Type.RealRegion].LastUpdateValue) == RegionContext.Scene.Name)
            {
                m_log.WarnFormat("{0}: Attempt to handle NewPresence message with RealRegion = {1}", LogHeader, RegionContext.Scene.Name);
                return false;
            }

            //Add the SyncInfo to SyncInfoManager
            pRegionContext.InfoManager.InsertSyncInfo(SyncInfo.UUID, SyncInfo);

            // Get ACD and PresenceType from decoded SyncInfoPresence
            // NASTY CASTS AHEAD!
            AgentCircuitData acd = new AgentCircuitData();
            acd.UnpackAgentCircuitData((OSDMap)(((SyncInfoPresence)SyncInfo).CurrentlySyncedProperties[SyncableProperties.Type.AgentCircuitData].LastUpdateValue));
            // Unset the ViaLogin flag since this presence is being added to the scene by sync (not via login)
            acd.teleportFlags &= ~(uint)TeleportFlags.ViaLogin;
            PresenceType pt = (PresenceType)(int)(((SyncInfoPresence)SyncInfo).CurrentlySyncedProperties[SyncableProperties.Type.PresenceType].LastUpdateValue);
            // Fake like we're not a user so normal teleport processing will not happen.
            // No. If we make the presence an NPC, then we cannot prevent the local scene from rezzing a duplicate set of attachments.
            // So, ScenePresence will be added with the original presence type. NPC presences will always get duplicate attachments which will need
            // to be fixed to support NPC presences in DSG regions. We can fix that eventually with a DSGAttachmentsModule which will only rez for
            // presences added by the local scene. Then, we can go back to all Region Sync Avatars being NPCs.
            // PresenceType pt = PresenceType.Npc;

            // Add the decoded circuit to local scene
            pRegionContext.Scene.AuthenticateHandler.AddNewCircuit(acd.circuitcode, acd);

            // Create a client and add it to the local scene at the position of the last update from sync cache
            Vector3 currentPos = (Vector3)(((SyncInfoPresence)SyncInfo).CurrentlySyncedProperties[SyncableProperties.Type.AbsolutePosition].LastUpdateValue);
            IClientAPI client = new RegionSyncAvatar(acd.circuitcode, pRegionContext.Scene, acd.AgentID, acd.firstname, acd.lastname, currentPos);
            try
            {
                SyncInfo.SceneThing = pRegionContext.Scene.AddNewAgent(client, pt);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("{0}: Exception in AddNewAgent: {1}", LogHeader, e.ToString());
            }
            // Maybe this should be the "real" region UUID but I don't think it will matter until we understand better how teleporting in DSG will work
            ScenePresence sp = (ScenePresence)SyncInfo.SceneThing;

            // SOME UNFORTUNATE REFLECTION IS REQUIRED TO GET THIS PRESENCE CREATED
            {
                // m_originRegionID is a private instance member of ScenePresence
                BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;

                // Get the field info instance corresponding to m_originRegionID
                FieldInfo field = typeof(ScenePresence).GetField("m_originRegionID", flags);

                // Set the value to the current scene
                field.SetValue(sp, pRegionContext.Scene.RegionInfo.RegionID);
            }

            // Now that we have a presence and a client, tell the region sync "client" to finish connecting.
            ((RegionSyncAvatar)client).PostCreateRegionSyncAvatar();

            // Might need to trigger something here to send new client messages to connected clients
            }
            return true;
        }