private GridRegion FindAlternativeRegion(UUID scopeID)
        {
            List <GridRegion> hyperlinks = null;
            List <GridRegion> regions    = m_GridService.GetFallbackRegions(scopeID, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000));

            if (regions != null && regions.Count > 0)
            {
                hyperlinks = m_GridService.GetHyperlinks(scopeID);
                IEnumerable <GridRegion> availableRegions = regions.Except(hyperlinks);
                if (availableRegions.Count() > 0)
                {
                    return(availableRegions.ElementAt(0));
                }
            }
            // No fallbacks, try to find an arbitrary region that is not a hyperlink
            // maxNumber is fixed for now; maybe use some search pattern with increasing maxSize here?
            regions = m_GridService.GetRegionsByName(scopeID, "", 10);
            if (regions != null && regions.Count > 0)
            {
                if (hyperlinks == null)
                {
                    hyperlinks = m_GridService.GetHyperlinks(scopeID);
                }
                IEnumerable <GridRegion> availableRegions = regions.Except(hyperlinks);
                if (availableRegions.Count() > 0)
                {
                    return(availableRegions.ElementAt(0));
                }
            }
            return(null);
        }
示例#2
0
        private byte[] GetFallbackRegions(Dictionary <string, object> request)
        {
            //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
            UUID scopeID = UUID.Zero;

            if (request.ContainsKey("SCOPEID"))
            {
                UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
            }

            int x = 0, y = 0;

            if (request.ContainsKey("X"))
            {
                Int32.TryParse(request["X"].ToString(), out x);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
            }
            if (request.ContainsKey("Y"))
            {
                Int32.TryParse(request["Y"].ToString(), out y);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
            }


            List <GridRegion> rinfos           = m_GridService.GetFallbackRegions(scopeID, x, y);

            rinfos = CleanRegions(rinfos);

            Dictionary <string, object> result = new Dictionary <string, object>();

            if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
            {
                result["result"] = "null";
            }
            else
            {
                int i = 0;
                foreach (GridRegion rinfo in rinfos)
                {
                    Dictionary <string, object> rinfoDict = rinfo.ToKeyValuePairs();
                    result["region" + i] = rinfoDict;
                    i++;
                }
            }
            string xmlString                   = WebUtils.BuildXmlResponse(result);
            //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
            UTF8Encoding encoding = new UTF8Encoding();

            return(encoding.GetBytes(xmlString));
        }
示例#3
0
        private GridRegion FindDefaultRegion()
        {
            GridRegion region = null;

            if (m_defaultRegion != "")//This overrides all
            {
                region = m_GridService.GetRegionByName(null, m_defaultRegion);
                if (region != null)
                {
                    m_foundDefaultRegion = true;
                    return(region);
                }
            }
            List <GridRegion> defs = m_GridService.GetDefaultRegions(null);

            if (defs != null && defs.Count > 0)
            {
                region = FindRegion(defs);
            }
            if (region == null)
            {
                defs = m_GridService.GetFallbackRegions(null, 0, 0);
                if (defs != null && defs.Count > 0)
                {
                    region = FindRegion(defs);
                }
                if (region == null)
                {
                    defs = m_GridService.GetSafeRegions(null, 0, 0);
                    if (defs != null && defs.Count > 0)
                    {
                        region = FindRegion(defs);
                    }
                    if (region == null)
                    {
                        MainConsole.Instance.WarnFormat("[GATEKEEPER SERVICE]: Please specify a default region for this grid!");
                    }
                }
            }
            if (region != null)
            {
                m_foundDefaultRegion = true;
            }
            return(region);
        }
        public List <GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
        {
            List <GridRegion> rinfo = m_LocalGridService.GetFallbackRegions(scopeID, x, y);
            //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetFallbackRegions {0} found {1} regions", name, rinfo.Count);
            List <GridRegion> grinfo = m_RemoteGridService.GetFallbackRegions(scopeID, x, y);

            if (grinfo != null)
            {
                //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetFallbackRegions {0} found {1} regions", name, grinfo.Count);
                foreach (GridRegion r in grinfo)
                {
                    if (rinfo.Find(delegate(GridRegion gr) { return(gr.RegionID == r.RegionID); }) == null)
                    {
                        rinfo.Add(r);
                    }
                }
            }

            return(rinfo);
        }
        protected AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarAppearance avatar,
                                                     UUID session, UUID secureSession, Vector3 position, string currentWhere, string viewer, string channel, string mac, string id0,
                                                     IPEndPoint clientIP, out string where, out string reason, out GridRegion dest)
        {
            where = currentWhere;
            ISimulationService simConnector = null;

            reason = string.Empty;
            uint             circuitCode = 0;
            AgentCircuitData aCircuit    = null;

            if (m_UserAgentService == null)
            {
                // HG standalones have both a localSimulatonDll and a remoteSimulationDll
                // non-HG standalones have just a localSimulationDll
                // independent login servers have just a remoteSimulationDll
                if (m_LocalSimulationService != null)
                {
                    simConnector = m_LocalSimulationService;
                }
                else if (m_RemoteSimulationService != null)
                {
                    simConnector = m_RemoteSimulationService;
                }
            }
            else // User Agent Service is on
            {
                if (gatekeeper == null) // login to local grid
                {
                    if (hostName == string.Empty)
                    {
                        SetHostAndPort(m_GatekeeperURL);
                    }

                    gatekeeper = new GridRegion(destination);
                    gatekeeper.ExternalHostName = hostName;
                    gatekeeper.HttpPort         = (uint)port;
                }
                else // login to foreign grid
                {
                }
            }

            bool success = false;

            if (m_UserAgentService == null && simConnector != null)
            {
                circuitCode = (uint)Util.RandomClass.Next();;
                aCircuit    = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0);
                success     = LaunchAgentDirectly(simConnector, destination, aCircuit, out reason);
                if (!success && m_GridService != null)
                {
                    // Try the fallback regions
                    List <GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                    if (fallbacks != null)
                    {
                        foreach (GridRegion r in fallbacks)
                        {
                            success = LaunchAgentDirectly(simConnector, r, aCircuit, out reason);
                            if (success)
                            {
                                where       = "safe";
                                destination = r;
                                break;
                            }
                        }
                    }
                }
            }

            if (m_UserAgentService != null)
            {
                circuitCode = (uint)Util.RandomClass.Next();;
                aCircuit    = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0);
                success     = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, clientIP, out reason);
                if (!success && m_GridService != null)
                {
                    // Try the fallback regions
                    List <GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                    if (fallbacks != null)
                    {
                        foreach (GridRegion r in fallbacks)
                        {
                            success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, clientIP, out reason);
                            if (success)
                            {
                                where       = "safe";
                                destination = r;
                                break;
                            }
                        }
                    }
                }
            }
            dest = destination;
            if (success)
            {
                return(aCircuit);
            }
            else
            {
                return(null);
            }
        }
 public List <GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
 {
     return(m_GridService.GetFallbackRegions(scopeID, x, y));
 }
        public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason)
        {
            reason = string.Empty;
            List <GridRegion> defaultRegions;
            List <GridRegion> fallbackRegions;
            string            authURL = string.Empty;

            if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
            {
                authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
            }
            m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9} Teleport Flags {10}",
                             aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName,
                             aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, aCircuit.teleportFlags.ToString());

            //
            // Check client
            //
            if (m_AllowedClients != string.Empty)
            {
                Regex arx = new Regex(m_AllowedClients);
                Match am  = arx.Match(aCircuit.Viewer);

                if (!am.Success)
                {
                    m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", aCircuit.Viewer);
                    return(false);
                }
            }

            if (m_DeniedClients != string.Empty)
            {
                Regex drx = new Regex(m_DeniedClients);
                Match dm  = drx.Match(aCircuit.Viewer);

                if (dm.Success)
                {
                    m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", aCircuit.Viewer);
                    return(false);
                }
            }

            //
            // Authenticate the user
            //
            if (!Authenticate(aCircuit))
            {
                reason = "Unable to verify identity";
                m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname);
                return(false);
            }
            m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, 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(m_ScopeID, aCircuit.AgentID);
                if (account != null)
                {
                    // 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.IsAgentComingHome(aCircuit.SessionID, m_ExternalName))
                        {
                            // Can't do, sorry
                            reason = "Unauthorized";
                            m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.",
                                             aCircuit.firstname, aCircuit.lastname);
                            return(false);
                        }
                    }
                }
            }

            //
            // Foreign agents allowed? Exceptions?
            //
            if (account == null)
            {
                bool allowed = m_ForeignAgentsAllowed;

                if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions))
                {
                    allowed = false;
                }

                if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions))
                {
                    allowed = true;
                }

                if (!allowed)
                {
                    reason = "Destination does not allow visitors from your world";
                    m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.",
                                     aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]);
                    return(false);
                }
            }

            //
            // Is the user banned?
            // This uses a Ban service that's more powerful than the configs
            //
            string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));

            if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
            {
                reason = "You are banned from this world";
                m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
                return(false);
            }

            m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name);

            bool isFirstLogin = false;
            //
            // Login the presence, if it's not there yet (by the login service)
            //
            PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID);

            if (presence != null) // it has been placed there by the login service
            {
                isFirstLogin = true;
            }

            else
            {
                if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID))
                {
                    reason = "Unable to login presence";
                    m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.",
                                     aCircuit.firstname, aCircuit.lastname);
                    return(false);
                }

                m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);

                // Also login foreigners with GridUser service
                if (m_GridUserService != null && account == null)
                {
                    string userId = aCircuit.AgentID.ToString();
                    string first = aCircuit.firstname, last = aCircuit.lastname;
                    if (last.StartsWith("@"))
                    {
                        string[] parts = aCircuit.firstname.Split('.');
                        if (parts.Length >= 2)
                        {
                            first = parts[0];
                            last  = parts[1];
                        }
                    }

                    userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last;
                    m_GridUserService.LoggedIn(userId);
                }
            }

            //
            // Get the region
            //
            destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID);
            if (destination == null)
            {
                defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero);
                if (defaultRegions == null || (defaultRegions != null && defaultRegions.Count == 0))
                {
                    reason = "Destination region not found";
                    return(false);
                }
                int index = m_Random.Next(0, defaultRegions.Count - 1);
                destination = defaultRegions[index];
            }

            m_log.DebugFormat(
                "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name);

            //
            // Adjust the visible name
            //
            if (account != null)
            {
                aCircuit.firstname = account.FirstName;
                aCircuit.lastname  = account.LastName;
            }
            if (account == null)
            {
                if (!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
                {
                    m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
                    aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString();
                }
            }

            //
            // Finally launch the agent at the destination
            //
            Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin;

            // Preserve our TeleportFlags we have gathered so-far
            loginFlag |= (Constants.TeleportFlags)aCircuit.teleportFlags;

            m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0} {1}", aCircuit.Name, loginFlag);

            // try login to the desired region
            if (m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, out reason))
            {
                return(true);
            }

            // if that failed, try the fallbacks
            m_log.DebugFormat("[GATEKEEPER SERVICE]: Region {0} did not accept agent {1}", destination.RegionName, aCircuit.Name);
            fallbackRegions = m_GridService.GetFallbackRegions(UUID.Zero, destination.RegionLocX, destination.RegionLocY);
            foreach (GridRegion r in fallbackRegions)
            {
                m_log.DebugFormat("[GATEKEEPER SERVICE]: Trying region {0}...", r.RegionName);
                if (m_SimulationService.CreateAgent(r, aCircuit, (uint)loginFlag, out reason))
                {
                    return(true);
                }
            }
            return(false);
        }