Exemple #1
0
        public void TestAgentCircuitDataOSDConversion()
        {
            AgentCircuitData Agent1Data = new AgentCircuitData();

            Agent1Data.AgentID          = AgentId;
            Agent1Data.Appearance       = AvAppearance;
            Agent1Data.BaseFolder       = BaseFolder;
            Agent1Data.CapsPath         = CapsPath;
            Agent1Data.child            = false;
            Agent1Data.ChildrenCapSeeds = ChildrenCapsPaths;
            Agent1Data.circuitcode      = circuitcode;
            Agent1Data.firstname        = firstname;
            Agent1Data.InventoryFolder  = BaseFolder;
            Agent1Data.lastname         = lastname;
            Agent1Data.SecureSessionID  = SecureSessionId;
            Agent1Data.SessionID        = SessionId;
            Agent1Data.startpos         = StartPos;

            EntityTransferContext ctx = new EntityTransferContext();
            OSDMap map2;
            OSDMap map = Agent1Data.PackAgentCircuitData(ctx);

            try
            {
                string str = OSDParser.SerializeJsonString(map);
                //System.Console.WriteLine(str);
                map2 = (OSDMap)OSDParser.DeserializeJson(str);
            }
            catch (System.NullReferenceException)
            {
                //spurious litjson errors :P
                map2 = map;
                Assert.That(1 == 1);
                return;
            }

            AgentCircuitData Agent2Data = new AgentCircuitData();

            Agent2Data.UnpackAgentCircuitData(map2);

            Assert.That((Agent1Data.AgentID == Agent2Data.AgentID));
            Assert.That((Agent1Data.BaseFolder == Agent2Data.BaseFolder));

            Assert.That((Agent1Data.CapsPath == Agent2Data.CapsPath));
            Assert.That((Agent1Data.child == Agent2Data.child));
            Assert.That((Agent1Data.ChildrenCapSeeds.Count == Agent2Data.ChildrenCapSeeds.Count));
            Assert.That((Agent1Data.circuitcode == Agent2Data.circuitcode));
            Assert.That((Agent1Data.firstname == Agent2Data.firstname));
            Assert.That((Agent1Data.InventoryFolder == Agent2Data.InventoryFolder));
            Assert.That((Agent1Data.lastname == Agent2Data.lastname));
            Assert.That((Agent1Data.SecureSessionID == Agent2Data.SecureSessionID));
            Assert.That((Agent1Data.SessionID == Agent2Data.SessionID));
            Assert.That((Agent1Data.startpos == Agent2Data.startpos));

            /*
             * Enable this once VisualParams go in the packing method
             * for (int i = 0; i < 208; i++)
             *  Assert.That((Agent1Data.Appearance.VisualParams[i] == Agent2Data.Appearance.VisualParams[i]));
             */
        }
        protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress)
        {
            OSDMap args = null;

            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message);
            }

            // Add the input arguments
            args["gatekeeper_serveruri"]  = OSD.FromString(gatekeeper.ServerURI);
            args["gatekeeper_host"]       = OSD.FromString(gatekeeper.ExternalHostName);
            args["gatekeeper_port"]       = OSD.FromString(gatekeeper.HttpPort.ToString());
            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["destination_serveruri"] = OSD.FromString(destination.ServerURI);

            // 10/3/2010
            // I added the client_ip up to the regular AgentCircuitData, so this doesn't need to be here.
            // This need cleaning elsewhere...
            //if (ipaddress != null)
            //    args["client_ip"] = OSD.FromString(ipaddress.Address.ToString());

            return(args);
        }
        public void TestAgentCircuitDataOSDConversion()
        {
            AgentCircuitData Agent1Data = new AgentCircuitData();

            Agent1Data.AgentID          = AgentId;
            Agent1Data.Appearance       = AvAppearance;
            Agent1Data.BaseFolder       = BaseFolder;
            Agent1Data.CapsPath         = CapsPath;
            Agent1Data.child            = false;
            Agent1Data.ChildrenCapSeeds = ChildrenCapsPaths;
            Agent1Data.circuitcode      = circuitcode;
            Agent1Data.firstname        = firstname;
            Agent1Data.InventoryFolder  = BaseFolder;
            Agent1Data.lastname         = lastname;
            Agent1Data.SecureSessionID  = SecureSessionId;
            Agent1Data.SessionID        = SessionId;
            Agent1Data.startpos         = StartPos;

            OSDMap map2;
            OSDMap map = Agent1Data.PackAgentCircuitData();

            try
            {
                string str = OSDParser.SerializeJsonString(map);
                map2 = (OSDMap)OSDParser.DeserializeJson(str);
            }
            catch (System.NullReferenceException)
            {
                map2 = map;
                Assert.That(1 == 1);
                return;
            }

            AgentCircuitData Agent2Data = new AgentCircuitData();

            Agent2Data.UnpackAgentCircuitData(map2);

            Assert.That((Agent1Data.AgentID == Agent2Data.AgentID));
            Assert.That((Agent1Data.BaseFolder == Agent2Data.BaseFolder));

            Assert.That((Agent1Data.CapsPath == Agent2Data.CapsPath));
            Assert.That((Agent1Data.child == Agent2Data.child));
            Assert.That((Agent1Data.ChildrenCapSeeds.Count == Agent2Data.ChildrenCapSeeds.Count));
            Assert.That((Agent1Data.circuitcode == Agent2Data.circuitcode));
            Assert.That((Agent1Data.firstname == Agent2Data.firstname));
            Assert.That((Agent1Data.InventoryFolder == Agent2Data.InventoryFolder));
            Assert.That((Agent1Data.lastname == Agent2Data.lastname));
            Assert.That((Agent1Data.SecureSessionID == Agent2Data.SecureSessionID));
            Assert.That((Agent1Data.SessionID == Agent2Data.SessionID));
            Assert.That((Agent1Data.startpos == Agent2Data.startpos));
        }
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
        {
            // m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");

            myipaddress = String.Empty;
            reason      = String.Empty;

            if (destination == null)
            {
                m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
                return(false);
            }

            string uri = destination.ServerURI + AgentPath() + 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(flags.ToString());

                OSDMap result = WebUtil.PostToService(uri, args, 80000);
                if (result["Success"].AsBoolean())
                {
                    OSDMap unpacked = (OSDMap)result["_Result"];

                    if (unpacked != null)
                    {
                        reason      = unpacked["reason"].AsString();
                        myipaddress = unpacked["your_ip"].AsString();
                        return(unpacked["success"].AsBoolean());
                    }
                }

                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);
        }
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
        {
            // MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");

            myipaddress = String.Empty;
            reason      = String.Empty;

            if (destination == null)
            {
                MainConsole.Instance.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
                return(false);
            }

            string uri = (destination.ServerURI.EndsWith("/") ? destination.ServerURI : (destination.ServerURI + "/"))
                         + AgentPath() + 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(flags.ToString());

                string r        = WebUtils.PostToService(uri, args);
                OSDMap unpacked = OSDParser.DeserializeJson(r) as OSDMap;
                if (unpacked != null)
                {
                    reason      = unpacked["reason"].AsString();
                    myipaddress = unpacked["your_ip"].AsString();
                    return(unpacked["success"].AsBoolean());
                }

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

            return(false);
        }
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
        {
            // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start");

            reason = String.Empty;
            if (destination == null)
            {
                m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
                return(false);
            }

            string uri = destination.ServerURI + AgentPath() + 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(flags.ToString());

                OSDMap result = WebUtil.PostToService(uri, args);
                if (result["Success"].AsBoolean())
                {
                    return(true);
                }

                m_log.WarnFormat(
                    "[REMOTE SIMULATION CONNECTOR]: Failed to create agent {0} {1} at remote simulator {1}",
                    aCircuit.firstname, aCircuit.lastname, destination.RegionName);
                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);
        }
Exemple #7
0
        protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination)
        {
            OSDMap args = null;

            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message);
            }
            // Add the input arguments
            args["gatekeeper_host"]  = OSD.FromString(gatekeeper.ExternalHostName);
            args["gatekeeper_port"]  = OSD.FromString(gatekeeper.HttpPort.ToString());
            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());

            return(args);
        }
Exemple #8
0
        protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags)
        {
            OSDMap args = null;

            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message);
                return(null);
            }
            // Add the input arguments
            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(flags.ToString());

            return(args);
        }
Exemple #9
0
        public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, EntityTransferContext ctx, out string reason)
        {
            reason = String.Empty;

            if (destination == null)
            {
                reason = "Destination not found";
                m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Create agent destination is null");
                return(false);
            }

            m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Creating agent at {0}", destination.ServerURI);

            string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
            OSD    tmpOSD;

            try
            {
                OSDMap args = aCircuit.PackAgentCircuitData(ctx);
                if (ctx == null)
                {
                    ctx = new EntityTransferContext();
                }
                args["context"] = ctx.Pack();
                PackData(args, source, aCircuit, destination, flags);

                OSDMap result  = WebUtil.PostToServiceCompressed(uri, args, 30000);
                bool   success = result["success"].AsBoolean();
                if (success && result.TryGetValue("_Result", out tmpOSD) && tmpOSD is OSDMap)
                {
                    OSDMap data = (OSDMap)tmpOSD;
                    reason  = data["reason"].AsString();
                    success = data["success"].AsBoolean();
                    return(success);
                }

                // Try the old version, uncompressed
                result = WebUtil.PostToService(uri, args, 30000, false);

                success = result["success"].AsBoolean();
                if (success)
                {
                    if (result.TryGetValue("_Result", out tmpOSD) && tmpOSD is OSDMap)
                    {
                        OSDMap data = (OSDMap)tmpOSD;
                        reason  = data["reason"].AsString();
                        success = data["success"].AsBoolean();

                        m_log.WarnFormat(
                            "[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName);
                        return(success);
                    }
                }

                m_log.WarnFormat(
                    "[REMOTE SIMULATION CONNECTOR]: Failed to create agent {0} {1} at remote simulator {2}",
                    aCircuit.firstname, aCircuit.lastname, destination.RegionName);
                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);
        }
Exemple #10
0
        public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey, out string reason)
        {
            // Eventually, we want to use a caps url instead of the agentID
            string uri = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
            //Console.WriteLine("   >>> DoCreateChildAgentCall <<< " + uri);

            HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
            AgentCreateRequest.Method = "POST";
            AgentCreateRequest.ContentType = "application/json";
            AgentCreateRequest.Timeout = 10000;
            //AgentCreateRequest.KeepAlive = false;

            AgentCreateRequest.Headers["authorization"] = GenerateAuthorization();

            reason = String.Empty;

            // Fill it in
            OSDMap args = null;
            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
                reason = "PackAgentCircuitData exception";
                return false;
            }

            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(region.RegionHandle);
            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = "";
            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                UTF8Encoding str = new UTF8Encoding();
                buffer = str.GetBytes(strBuffer);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
                // ignore. buffer will be empty, caller should check.
            }

            Stream os = null;
            try
            { // send the Post
                AgentCreateRequest.ContentLength = buffer.Length;   //Count bytes to send
                os = AgentCreateRequest.GetRequestStream();
                os.Write(buffer, 0, strBuffer.Length);         //Send it
                os.Close();
                //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
            }
            //catch (WebException ex)
            catch
            {
                //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
                reason = "cannot contact remote region";
                return false;
            }
            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");

            try
            {
                WebResponse webResponse = AgentCreateRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
                    reason = "response is null";
                    return false;
                }

                StreamReader sr = new StreamReader(webResponse.GetResponseStream());
                string response = sr.ReadToEnd().Trim();
                sr.Close();
                m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
                if (String.IsNullOrEmpty(response))
                {
                    reason = "response is empty";
                    return false;
                }

                try
                {
                    // we assume we got an OSDMap back
                    OSDMap r = GetOSDMap(response);
                    bool success = r["success"].AsBoolean();
                    reason = r["reason"].AsString();
                    return success;
                }
                catch (NullReferenceException e)
                {
                    m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);

                    // check for old style response
                    if (response.ToLower().StartsWith("true"))
                        return true;

                    reason = "null reference exception";
                    return false;
                }
            }
            catch (WebException ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
                reason = "web exception";
                return false;
            }
        }
Exemple #11
0
        public async Task<Tuple<bool, string>> DoCreateChildAgentCallAsync(SimpleRegionInfo regionInfo, AgentCircuitData aCircuit)
        {
            string uri = regionInfo.InsecurePublicHTTPServerURI + "/agent/" + aCircuit.AgentID + "/";

            HttpWebRequest agentCreateRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
            agentCreateRequest.Method = "POST";
            agentCreateRequest.ContentType = "application/json";
            agentCreateRequest.Timeout = AGENT_UPDATE_TIMEOUT;
            agentCreateRequest.ReadWriteTimeout = AGENT_UPDATE_TIMEOUT;
            agentCreateRequest.Headers["authorization"] = GenerateAuthorization();

            OSDMap args = null;
            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
                return Tuple.Create(false, "PackAgentCircuitData exception");
            }

            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(regionInfo.RegionHandle);
            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = "";
            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                UTF8Encoding str = new UTF8Encoding();
                buffer = str.GetBytes(strBuffer);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
                return Tuple.Create(false, "Exception thrown on serialization of ChildCreate");
            }

            
            try
            { // send the Post
                agentCreateRequest.ContentLength = buffer.Length;   //Count bytes to send
                Stream os = await agentCreateRequest.GetRequestStreamAsync();

                await os.WriteAsync(buffer, 0, strBuffer.Length);         //Send it
                await os.FlushAsync();

                os.Close();
                //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Unable to contact remote region {0}: {1}", regionInfo.RegionHandle, e.Message);
                return Tuple.Create(false, "cannot contact remote region");
            }
            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");

            try
            {
                WebResponse webResponse = await agentCreateRequest.GetResponseAsync(AGENT_UPDATE_TIMEOUT);
                if (webResponse == null)
                {
                    m_log.Warn("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
                    return Tuple.Create(false, "response from remote region was null");
                }

                StreamReader sr = new StreamReader(webResponse.GetResponseStream());
                string response = await sr.ReadToEndAsync();
                response.Trim();
                sr.Close();

                //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
                if (String.IsNullOrEmpty(response))
                {
                    m_log.Info("[REST COMMS]: Empty response on DoCreateChildAgentCall post");
                    return Tuple.Create(false, "response from remote region was empty");
                }

                try
                {
                    // we assume we got an OSDMap back
                    OSDMap r = GetOSDMap(response);
                    bool success = r["success"].AsBoolean();
                    string reason = r["reason"].AsString();

                    return Tuple.Create(success, reason);
                }
                catch (NullReferenceException e)
                {
                    m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);

                    // check for old style response
                    if (response.ToLower().StartsWith("true"))
                        return Tuple.Create(true, "");

                    return Tuple.Create(false, "exception on reply of DoCreateChildAgentCall");
                }
            }
            catch (WebException ex)
            {
                m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex);
                return Tuple.Create(false, "web exception");
            }
            catch (Exception ex)
            {
                m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex);
                return Tuple.Create(false, "web exception");
            }
        }
Exemple #12
0
        public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
        {
            m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Creating agent at {0}", destination.ServerURI);
            reason      = String.Empty;
            myipaddress = String.Empty;

            if (destination == null)
            {
                m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
                return(false);
            }

            string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";

            try
            {
                OSDMap args = aCircuit.PackAgentCircuitData();
                PackData(args, source, aCircuit, destination, flags);

                OSDMap result  = WebUtil.PostToServiceCompressed(uri, args, 30000);
                bool   success = result["success"].AsBoolean();
                if (success && result.ContainsKey("_Result"))
                {
                    OSDMap data = (OSDMap)result["_Result"];

                    reason      = data["reason"].AsString();
                    success     = data["success"].AsBoolean();
                    myipaddress = data["your_ip"].AsString();
                    return(success);
                }

                // Try the old version, uncompressed
                result = WebUtil.PostToService(uri, args, 30000, false);

                if (result["Success"].AsBoolean())
                {
                    if (result.ContainsKey("_Result"))
                    {
                        OSDMap data = (OSDMap)result["_Result"];

                        reason      = data["reason"].AsString();
                        success     = data["success"].AsBoolean();
                        myipaddress = data["your_ip"].AsString();
                        m_log.WarnFormat(
                            "[REMOTE SIMULATION CONNECTOR]: Remote simulator {0} did not accept compressed transfer, suggest updating it.", destination.RegionName);
                        return(success);
                    }
                }

                m_log.WarnFormat(
                    "[REMOTE SIMULATION CONNECTOR]: Failed to create agent {0} {1} at remote simulator {2}",
                    aCircuit.firstname, aCircuit.lastname, destination.RegionName);
                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);
        }
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
        {
            // m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");

            myipaddress = String.Empty;
            reason = String.Empty;

            if (destination == null)
            {
                m_log.Debug ("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
                return false;
            }

            string uri = (destination.ServerURI.EndsWith ("/") ? destination.ServerURI : (destination.ServerURI + "/"))
                + AgentPath () + 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 (flags.ToString ());

                OSDMap result = WebUtils.PostToService (uri, args, true, true);
                if (result["Success"].AsBoolean ())
                {
                    OSDMap unpacked = (OSDMap)result["_Result"];

                    if (unpacked != null)
                    {
                        reason = unpacked["reason"].AsString ();
                        myipaddress = unpacked["your_ip"].AsString ();
                        return unpacked["success"].AsBoolean ();
                    }
                }

                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;
        }
Exemple #14
0
        public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey, out string reason)
        {
            // Eventually, we want to use a caps url instead of the agentID
            string uri = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
            //Console.WriteLine("   >>> DoCreateChildAgentCall <<< " + uri);

            HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);

            AgentCreateRequest.Method      = "POST";
            AgentCreateRequest.ContentType = "application/json";
            AgentCreateRequest.Timeout     = 10000;
            //AgentCreateRequest.KeepAlive = false;

            AgentCreateRequest.Headers["authorization"] = GenerateAuthorization();

            reason = String.Empty;

            // Fill it in
            OSDMap args = null;

            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
                reason = "PackAgentCircuitData exception";
                return(false);
            }

            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(region.RegionHandle);

            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = String.Empty;

            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                UTF8Encoding str = new UTF8Encoding();
                buffer = str.GetBytes(strBuffer);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
                // ignore. buffer will be empty, caller should check.
            }

            Stream os = null;

            try
            {                                                     // send the Post
                AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
                os = AgentCreateRequest.GetRequestStream();
                os.Write(buffer, 0, strBuffer.Length);            //Send it
                os.Close();
                //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
            }
            //catch (WebException ex)
            catch
            {
                //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
                reason = "cannot contact remote region";
                return(false);
            }
            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");

            try
            {
                WebResponse webResponse = AgentCreateRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
                    reason = "response is null";
                    return(false);
                }

                StreamReader sr       = new StreamReader(webResponse.GetResponseStream());
                string       response = sr.ReadToEnd().Trim();
                sr.Close();
                m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
                if (String.IsNullOrEmpty(response))
                {
                    reason = "response is empty";
                    return(false);
                }

                try
                {
                    // we assume we got an OSDMap back
                    OSDMap r       = GetOSDMap(response);
                    bool   success = r["success"].AsBoolean();
                    reason = r["reason"].AsString();
                    return(success);
                }
                catch (NullReferenceException e)
                {
                    m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);

                    // check for old style response
                    if (response.ToLower().StartsWith("true"))
                    {
                        return(true);
                    }

                    reason = "null reference exception";
                    return(false);
                }
            }
            catch (WebException ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
                reason = "web exception";
                return(false);
            }
        }
Exemple #15
0
        public async Task <Tuple <bool, string> > DoCreateChildAgentCallAsync(SimpleRegionInfo regionInfo, AgentCircuitData aCircuit)
        {
            string uri = regionInfo.InsecurePublicHTTPServerURI + "/agent/" + aCircuit.AgentID + "/";

            HttpWebRequest agentCreateRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

            agentCreateRequest.Method                   = "POST";
            agentCreateRequest.ContentType              = "application/json";
            agentCreateRequest.Timeout                  = AGENT_UPDATE_TIMEOUT;
            agentCreateRequest.ReadWriteTimeout         = AGENT_UPDATE_TIMEOUT;
            agentCreateRequest.Headers["authorization"] = GenerateAuthorization();

            OSDMap args = null;

            try
            {
                args = aCircuit.PackAgentCircuitData();
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
                return(Tuple.Create(false, "PackAgentCircuitData exception"));
            }

            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(regionInfo.RegionHandle);

            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = String.Empty;

            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                UTF8Encoding str = new UTF8Encoding();
                buffer = str.GetBytes(strBuffer);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
                return(Tuple.Create(false, "Exception thrown on serialization of ChildCreate"));
            }


            try
            {                                                     // send the Post
                agentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
                Stream os = await agentCreateRequest.GetRequestStreamAsync();

                await os.WriteAsync(buffer, 0, strBuffer.Length);         //Send it

                await os.FlushAsync();

                os.Close();
                //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Unable to contact remote region {0}: {1}", regionInfo.RegionHandle, e.Message);
                return(Tuple.Create(false, "cannot contact remote region"));
            }
            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");

            try
            {
                WebResponse webResponse = await agentCreateRequest.GetResponseAsync(AGENT_UPDATE_TIMEOUT);

                if (webResponse == null)
                {
                    m_log.Warn("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
                    return(Tuple.Create(false, "response from remote region was null"));
                }

                StreamReader sr       = new StreamReader(webResponse.GetResponseStream());
                string       response = await sr.ReadToEndAsync();

                response.Trim();
                sr.Close();

                //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
                if (String.IsNullOrEmpty(response))
                {
                    m_log.Info("[REST COMMS]: Empty response on DoCreateChildAgentCall post");
                    return(Tuple.Create(false, "response from remote region was empty"));
                }

                try
                {
                    // we assume we got an OSDMap back
                    OSDMap r       = GetOSDMap(response);
                    bool   success = r["success"].AsBoolean();
                    string reason  = r["reason"].AsString();

                    return(Tuple.Create(success, reason));
                }
                catch (NullReferenceException e)
                {
                    m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);

                    // check for old style response
                    if (response.ToLower().StartsWith("true"))
                    {
                        return(Tuple.Create(true, String.Empty));
                    }

                    return(Tuple.Create(false, "exception on reply of DoCreateChildAgentCall"));
                }
            }
            catch (WebException ex)
            {
                m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex);
                return(Tuple.Create(false, "web exception"));
            }
            catch (Exception ex)
            {
                m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex);
                return(Tuple.Create(false, "web exception"));
            }
        }
       public void TestAgentCircuitDataOSDConversion()
       {
           AgentCircuitData Agent1Data = new AgentCircuitData();
           Agent1Data.AgentID = AgentId;
           Agent1Data.Appearance = AvAppearance;
           Agent1Data.BaseFolder = BaseFolder;
           Agent1Data.CapsPath = CapsPath;
           Agent1Data.child = false;
           Agent1Data.ChildrenCapSeeds = ChildrenCapsPaths;
           Agent1Data.circuitcode = circuitcode;
           Agent1Data.firstname = firstname;
           Agent1Data.InventoryFolder = BaseFolder;
           Agent1Data.lastname = lastname;
           Agent1Data.SecureSessionID = SecureSessionId;
           Agent1Data.SessionID = SessionId;
           Agent1Data.startpos = StartPos;

            OSDMap map2;
            OSDMap map = Agent1Data.PackAgentCircuitData();
            try
            {
                string str = OSDParser.SerializeJsonString(map);
                //System.Console.WriteLine(str);
                map2 = (OSDMap) OSDParser.DeserializeJson(str);
            } 
            catch (System.NullReferenceException)
            {
                //spurious litjson errors :P
                map2 = map;
                Assert.That(1==1);
                return;
            }

           AgentCircuitData Agent2Data = new AgentCircuitData();
           Agent2Data.UnpackAgentCircuitData(map2);

           Assert.That((Agent1Data.AgentID == Agent2Data.AgentID));
           Assert.That((Agent1Data.BaseFolder == Agent2Data.BaseFolder));

           Assert.That((Agent1Data.CapsPath == Agent2Data.CapsPath));
           Assert.That((Agent1Data.child == Agent2Data.child));
           Assert.That((Agent1Data.ChildrenCapSeeds.Count == Agent2Data.ChildrenCapSeeds.Count));
           Assert.That((Agent1Data.circuitcode == Agent2Data.circuitcode));
           Assert.That((Agent1Data.firstname == Agent2Data.firstname));
           Assert.That((Agent1Data.InventoryFolder == Agent2Data.InventoryFolder));
           Assert.That((Agent1Data.lastname == Agent2Data.lastname));
           Assert.That((Agent1Data.SecureSessionID == Agent2Data.SecureSessionID));
           Assert.That((Agent1Data.SessionID == Agent2Data.SessionID));
           Assert.That((Agent1Data.startpos == Agent2Data.startpos));

           /*
            Enable this once VisualParams go in the packing method
           for (int i = 0; i < 208; i++)
               Assert.That((Agent1Data.Appearance.VisualParams[i] == Agent2Data.Appearance.VisualParams[i]));
           */


        }
Exemple #17
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);
        }
        /// <summary>
        /// Do the work necessary to initiate a new user connection for a particular scene.
        /// At the moment, this consists of setting up the caps infrastructure
        /// The return bool should allow for connections to be refused, but as not all calling paths
        /// take proper notice of it let, we allowed banned users in still.
        /// </summary>
        /// <param name="agent">CircuitData of the agent who is connecting</param>
        /// <param name="reason">Outputs the reason for the false response on this string,
        /// If the agent was accepted, this will be the Caps SEED for the region</param>
        /// <param name="requirePresenceLookup">True for normal presence. False for NPC
        /// or other applications where a full grid/Hypergrid presence may not be required.</param>
        /// <returns>True if the region accepts this agent.  False if it does not.  False will
        /// also return a reason.</returns>
        public bool NewUserConnection(IScene scene, AgentCircuitData agent, uint teleportFlags, out string reason)
        {
            reason = String.Empty;

            // Don't disable this log message - it's too helpful
            m_log.DebugFormat(
                "[ConnectionBegin]: Region {0} told of incoming {1} agent {2} (circuit code {3}, teleportflags {4})",
                scene.RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.AgentID,
                agent.circuitcode, teleportFlags);

            if (!AuthorizeUser(scene, agent, out reason))
            {
                OSDMap map = new OSDMap();
                map["Reason"]  = reason;
                map["Success"] = false;
                reason         = OSDParser.SerializeJsonString(map);
                return(false);
            }

            IScenePresence sp = scene.GetScenePresence(agent.AgentID);

            if (sp != null && !sp.IsChildAgent)
            {
                // We have a zombie from a crashed session.
                // Or the same user is trying to be root twice here, won't work.
                // Kill it.
                m_log.InfoFormat("[Scene]: Zombie scene presence detected for {0} in {1}", agent.AgentID, scene.RegionInfo.RegionName);
                scene.RemoveAgent(sp);
                sp = null;
            }

            //Add possible Urls for the given agent
            IConfigurationService configService = scene.RequestModuleInterface <IConfigurationService> ();

            if (configService != null && agent.OtherInformation.ContainsKey("UserUrls"))
            {
                configService.AddNewUser(agent.AgentID.ToString(), (OSDMap)agent.OtherInformation["UserUrls"]);
            }

            OSDMap responseMap = new OSDMap();

            responseMap["CapsUrls"] = scene.EventManager.TriggerOnRegisterCaps(agent.AgentID);

            // In all cases, add or update the circuit data with the new agent circuit data and teleport flags
            agent.teleportFlags = teleportFlags;

            //Add the circuit at the end
            scene.AuthenticateHandler.AddNewCircuit(agent.circuitcode, agent);

            responseMap["Agent"] = agent.PackAgentCircuitData();

            scene.AuroraEventManager.FireGenericEventHandler("NewUserConnection", responseMap);

            m_log.InfoFormat(
                "[ConnectionBegin]: Region {0} authenticated and authorized incoming {1} agent {2} (circuit code {3})",
                scene.RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.AgentID,
                agent.circuitcode);

            responseMap["Success"] = true;
            reason = OSDParser.SerializeJsonString(responseMap);
            return(true);
        }
        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);
        }