GetHomeRegion() 공개 메소드

public GetHomeRegion ( Aurora.Framework.AgentCircuitData circuit, System.Vector3 &position, System.Vector3 &lookAt ) : GridRegion
circuit Aurora.Framework.AgentCircuitData
position System.Vector3
lookAt System.Vector3
리턴 OpenSim.Services.Interfaces.GridRegion
        public GridRegion GetHomeRegion(AgentCircuitData circuit, out Vector3 position, out Vector3 lookAt)
        {
            if (circuit.ServiceURLs.ContainsKey("HomeURI"))
            {
                IUserAgentService userAgentService = new UserAgentServiceConnector(circuit.ServiceURLs["HomeURI"].ToString());
                GridRegion        region           = userAgentService.GetHomeRegion(circuit, out position, out lookAt);
                if (region != null)
                {
                    Uri uri = null;
                    if (!circuit.ServiceURLs.ContainsKey("HomeURI") ||
                        (circuit.ServiceURLs.ContainsKey("HomeURI") && !Uri.TryCreate(circuit.ServiceURLs["HomeURI"].ToString(), UriKind.Absolute, out uri)))
                    {
                        return(null);
                    }

                    region.ExternalHostName = uri.Host;
                    region.HttpPort         = (uint)uri.Port;
                    region.ServerURI        = region.ServerURI;
                    region.RegionName       = string.Empty;
                    region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0);
                    bool isComingHome = userAgentService.AgentIsComingHome(circuit.SessionID, m_GridName);
                    return(region);
                }
            }
            return(GetHomeRegion(circuit.AgentID, out position, out lookAt));
        }
예제 #2
0
        public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason)
        {
            reason = string.Empty;

            string authURL = string.Empty;
            if (aCircuit.ServiceURLs.ContainsKey ("HomeURI"))
                authURL = aCircuit.ServiceURLs["HomeURI"].ToString ();
            MainConsole.Instance.InfoFormat ("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2}",
                authURL, aCircuit.AgentID, destination.RegionName);

            //
            // Authenticate the user
            //
            if (!Authenticate (aCircuit))
            {
                reason = "Unable to verify identity";
                MainConsole.Instance.InfoFormat ("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0}. Refusing service.", aCircuit.AgentID);
                return false;
            }
            MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE]: Identity verified for {0} @ {1}", aCircuit.AgentID, authURL);

            //
            // Check for impersonations
            //
            UserAccount account = null;
            if (m_UserAccountService != null)
            {
                // Check to see if we have a local user with that UUID
                account = m_UserAccountService.GetUserAccount (null, aCircuit.AgentID);
                if (account != null && m_userFinder.IsLocalGridUser(account.PrincipalID))
                {
                    // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
                    if (m_UserAgentService != null)
                    {
                        if (!m_UserAgentService.AgentIsComingHome (aCircuit.SessionID, m_ExternalName))
                        {
                            // Can't do, sorry
                            reason = "Unauthorized";
                            MainConsole.Instance.InfoFormat ("[GATEKEEPER SERVICE]: Foreign agent {0} has same ID as local user. Refusing service.",
                                aCircuit.AgentID);
                            return false;

                        }
                    }
                }
            }
            MainConsole.Instance.InfoFormat ("[GATEKEEPER SERVICE]: User is ok");

            // May want to authorize

            //bool isFirstLogin = false;
            //
            // Login the presence, if it's not there yet (by the login service)
            //
            UserInfo presence = m_PresenceService.GetUserInfo (aCircuit.AgentID.ToString());
            if (m_userFinder.IsLocalGridUser(aCircuit.AgentID) && presence != null && presence.IsOnline) // it has been placed there by the login service
            {
                //    isFirstLogin = true;
            }
            else
            {
                IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString());
                Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
                GridRegion finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt);
                if (finalDestination == null)
                {
                    reason = "You do not have a home position set.";
                    return false;
                }
                m_PresenceService.SetHomePosition(aCircuit.AgentID.ToString(), finalDestination.RegionID, position, lookAt);
                m_PresenceService.SetLoggedIn(aCircuit.AgentID.ToString(), true, true, destination.RegionID);
            }

            MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE]: Login presence ok");

            //
            // Get the region
            //
            destination = m_GridService.GetRegionByUUID(null, destination.RegionID);
            if (destination == null)
            {
                reason = "Destination region not found";
                return false;
            }

            //
            // Adjust the visible name
            //
            if (account != null)
            {
                aCircuit.firstname = account.FirstName;
                aCircuit.lastname = account.LastName;
            }
            if (account == null && !aCircuit.lastname.StartsWith ("@"))
            {
                aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
                try
                {
                    Uri uri = new Uri (aCircuit.ServiceURLs["HomeURI"].ToString ());
                    aCircuit.lastname = "@" + uri.Host; // + ":" + uri.Port;
                }
                catch
                {
                    MainConsole.Instance.WarnFormat ("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
                    aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString ();
                }
                m_userFinder.AddUser(aCircuit.AgentID, aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs);
                m_UserAccountService.CacheAccount(new UserAccount(UUID.Zero, aCircuit.AgentID, aCircuit.firstname + aCircuit.lastname, "") { UserFlags = 1024 });
            }

            retry:
            //
            // Finally launch the agent at the destination
            //
            TeleportFlags loginFlag = /*isFirstLogin ? */TeleportFlags.ViaLogin/* : TeleportFlags.ViaHGLogin*/;
            IRegionClientCapsService regionClientCaps = null;
            if (m_CapsService != null)
            {
                //Remove any previous users
                string ServerCapsBase = Aurora.Framework.Capabilities.CapsUtil.GetRandomCapsObjectPath ();
                m_CapsService.CreateCAPS(aCircuit.AgentID,
                    Aurora.Framework.Capabilities.CapsUtil.GetCapsSeedPath(ServerCapsBase),
                    destination.RegionHandle, true, aCircuit, 0);

                regionClientCaps = m_CapsService.GetClientCapsService (aCircuit.AgentID).GetCapsService (destination.RegionHandle);
                if (aCircuit.ServiceURLs == null)
                    aCircuit.ServiceURLs = new Dictionary<string, object>();
                aCircuit.ServiceURLs["IncomingCAPSHandler"] = regionClientCaps.CapsUrl;
            }
            aCircuit.child = false;//FIX THIS, OPENSIM ALWAYS SENDS CHILD!
            int requestedUDPPort = 0;
            bool success = m_SimulationService.CreateAgent (destination, aCircuit, (uint)loginFlag, null, out requestedUDPPort, out reason);
            if (success)
            {
                if (regionClientCaps != null)
                {
                    if (requestedUDPPort == 0)
                        requestedUDPPort = destination.ExternalEndPoint.Port;
                    IPAddress ipAddress = destination.ExternalEndPoint.Address;
                    aCircuit.RegionUDPPort = requestedUDPPort;
                    regionClientCaps.LoopbackRegionIP = ipAddress;
                    regionClientCaps.CircuitData.RegionUDPPort = requestedUDPPort;
                    OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson (reason);
                    OSDMap SimSeedCaps = (OSDMap)responseMap["CapsUrls"];
                    regionClientCaps.AddCAPS (SimSeedCaps);
                }
            }
            else
            {
                if (m_CapsService != null)
                    m_CapsService.RemoveCAPS (aCircuit.AgentID);
                m_GridService.SetRegionUnsafe(destination.RegionID);
                if(!m_foundDefaultRegion)
                    m_DefaultGatewayRegion = FindDefaultRegion();
                if (destination != m_DefaultGatewayRegion)
                {
                    destination = m_DefaultGatewayRegion;
                    goto retry;
                }
                else
                {
                    m_DefaultGatewayRegion = FindDefaultRegion ();
                    if (m_DefaultGatewayRegion == destination)
                        return false;//It failed to find a new one
                    destination = m_DefaultGatewayRegion;
                    goto retry;//It found a new default region
                }
            }
            return success;
        }
예제 #3
0
        public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason)
        {
            reason = string.Empty;

            string authURL = string.Empty;

            if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
            {
                authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
            }
            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2}",
                                            authURL, aCircuit.AgentID, destination.RegionName);

            //
            // Authenticate the user
            //
            if (!Authenticate(aCircuit))
            {
                reason = "Unable to verify identity";
                MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0}. Refusing service.", aCircuit.AgentID);
                return(false);
            }
            MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} @ {1}", aCircuit.AgentID, authURL);

            //
            // Check for impersonations
            //
            UserAccount account = null;

            if (m_UserAccountService != null)
            {
                // Check to see if we have a local user with that UUID
                account = m_UserAccountService.GetUserAccount(null, aCircuit.AgentID);
                if (account != null && m_userFinder.IsLocalGridUser(account.PrincipalID))
                {
                    // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
                    if (m_UserAgentService != null)
                    {
                        if (!m_UserAgentService.AgentIsComingHome(aCircuit.SessionID, m_ExternalName))
                        {
                            // Can't do, sorry
                            reason = "Unauthorized";
                            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} has same ID as local user. Refusing service.",
                                                            aCircuit.AgentID);
                            return(false);
                        }
                    }
                }
            }
            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: User is ok");

            // May want to authorize

            //bool isFirstLogin = false;
            //
            // Login the presence, if it's not there yet (by the login service)
            //
            UserInfo presence = m_PresenceService.GetUserInfo(aCircuit.AgentID.ToString());

            if (m_userFinder.IsLocalGridUser(aCircuit.AgentID) && presence != null && presence.IsOnline) // it has been placed there by the login service
            {
                //    isFirstLogin = true;
            }
            else
            {
                IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString());
                Vector3           position = Vector3.UnitY, lookAt = Vector3.UnitY;
                GridRegion        finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt);
                if (finalDestination == null)
                {
                    reason = "You do not have a home position set.";
                    return(false);
                }
                m_PresenceService.SetHomePosition(aCircuit.AgentID.ToString(), finalDestination.RegionID, position, lookAt);
                m_PresenceService.SetLoggedIn(aCircuit.AgentID.ToString(), true, true, destination.RegionID);
            }

            MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok");

            //
            // Get the region
            //
            destination = m_GridService.GetRegionByUUID(null, destination.RegionID);
            if (destination == null)
            {
                reason = "Destination region not found";
                return(false);
            }

            //
            // Adjust the visible name
            //
            if (account != null)
            {
                aCircuit.firstname = account.FirstName;
                aCircuit.lastname  = account.LastName;
            }
            if (account == null && !aCircuit.lastname.StartsWith("@"))
            {
                aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
                try
                {
                    Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
                    aCircuit.lastname = "@" + uri.Host; // + ":" + uri.Port;
                }
                catch
                {
                    MainConsole.Instance.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
                    aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString();
                }
                m_userFinder.AddUser(aCircuit.AgentID, aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs);
                m_UserAccountService.CacheAccount(new UserAccount(UUID.Zero, aCircuit.AgentID, aCircuit.firstname + aCircuit.lastname, "")
                {
                    UserFlags = 1024
                });
            }

retry:
            //
            // Finally launch the agent at the destination
            //
            TeleportFlags loginFlag = /*isFirstLogin ? */ TeleportFlags.ViaLogin /* : TeleportFlags.ViaHGLogin*/;
            IRegionClientCapsService regionClientCaps = null;

            if (m_CapsService != null)
            {
                //Remove any previous users
                string ServerCapsBase = Aurora.Framework.Capabilities.CapsUtil.GetRandomCapsObjectPath();
                m_CapsService.CreateCAPS(aCircuit.AgentID,
                                         Aurora.Framework.Capabilities.CapsUtil.GetCapsSeedPath(ServerCapsBase),
                                         destination.RegionHandle, true, aCircuit, 0);

                regionClientCaps = m_CapsService.GetClientCapsService(aCircuit.AgentID).GetCapsService(destination.RegionHandle);
                if (aCircuit.ServiceURLs == null)
                {
                    aCircuit.ServiceURLs = new Dictionary <string, object>();
                }
                aCircuit.ServiceURLs["IncomingCAPSHandler"] = regionClientCaps.CapsUrl;
            }
            aCircuit.child = false;//FIX THIS, OPENSIM ALWAYS SENDS CHILD!
            int  requestedUDPPort = 0;
            bool success          = m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, null, out requestedUDPPort, out reason);

            if (success)
            {
                if (regionClientCaps != null)
                {
                    if (requestedUDPPort == 0)
                    {
                        requestedUDPPort = destination.ExternalEndPoint.Port;
                    }
                    IPAddress ipAddress = destination.ExternalEndPoint.Address;
                    aCircuit.RegionUDPPort                     = requestedUDPPort;
                    regionClientCaps.LoopbackRegionIP          = ipAddress;
                    regionClientCaps.CircuitData.RegionUDPPort = requestedUDPPort;
                    OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason);
                    OSDMap SimSeedCaps = (OSDMap)responseMap["CapsUrls"];
                    regionClientCaps.AddCAPS(SimSeedCaps);
                }
            }
            else
            {
                if (m_CapsService != null)
                {
                    m_CapsService.RemoveCAPS(aCircuit.AgentID);
                }
                m_GridService.SetRegionUnsafe(destination.RegionID);
                if (!m_foundDefaultRegion)
                {
                    m_DefaultGatewayRegion = FindDefaultRegion();
                }
                if (destination != m_DefaultGatewayRegion)
                {
                    destination = m_DefaultGatewayRegion;
                    goto retry;
                }
                else
                {
                    m_DefaultGatewayRegion = FindDefaultRegion();
                    if (m_DefaultGatewayRegion == destination)
                    {
                        return(false);//It failed to find a new one
                    }
                    destination = m_DefaultGatewayRegion;
                    goto retry;//It found a new default region
                }
            }
            return(success);
        }
예제 #4
0
        public GridRegion GetHomeRegion(AgentCircuitData circuit, out Vector3 position, out Vector3 lookAt)
        {
            if (circuit.ServiceURLs.ContainsKey ("HomeURI"))
            {
                IUserAgentService userAgentService = new UserAgentServiceConnector (circuit.ServiceURLs["HomeURI"].ToString ());
                GridRegion region = userAgentService.GetHomeRegion (circuit, out position, out lookAt);
                if (region != null)
                {
                    Uri uri = null;
                    if (!circuit.ServiceURLs.ContainsKey ("HomeURI") ||
                        (circuit.ServiceURLs.ContainsKey ("HomeURI") && !Uri.TryCreate (circuit.ServiceURLs["HomeURI"].ToString (), UriKind.Absolute, out uri)))
                        return null;

                    region.ExternalHostName = uri.Host;
                    region.HttpPort = (uint)uri.Port;
                    region.ServerURI = region.ServerURI;
                    region.RegionName = string.Empty;
                    region.InternalEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("0.0.0.0"), (int)0);
                    bool isComingHome = userAgentService.AgentIsComingHome (circuit.SessionID, m_GridName);
                    return region;
                }
            }
            return GetHomeRegion (circuit.AgentID, out position, out lookAt);
        }