private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
        {
            int flags = (int)Aurora.Framework.RegionFlags.Hyperlink + (int)Aurora.Framework.RegionFlags.NoDirectLogin + (int)Aurora.Framework.RegionFlags.RegionOnline;

            regionInfo.Flags = flags;

            m_Database.Store(regionInfo);
        }
// Not currently used
//        /// <summary>
//        /// Cope with this viewer limitation.
//        /// </summary>
//        /// <param name="regInfo"></param>
//        /// <returns></returns>
//        public bool Check4096(ulong realHandle, out uint x, out uint y)
//        {
//            uint ux = 0, uy = 0;
//            Utils.LongToUInts(realHandle, out ux, out uy);
//            x = Util.WorldToRegionLoc(ux);
//            y = Util.WorldToRegionLoc(uy);
//
//            const uint limit = Util.RegionToWorldLoc(4096 - 1);
//            uint xmin = ux - limit;
//            uint xmax = ux + limit;
//            uint ymin = uy - limit;
//            uint ymax = uy + limit;
//            // World map boundary checks
//            if (xmin < 0 || xmin > ux)
//                xmin = 0;
//            if (xmax > int.MaxValue || xmax < ux)
//                xmax = int.MaxValue;
//            if (ymin < 0 || ymin > uy)
//                ymin = 0;
//            if (ymax > int.MaxValue || ymax < uy)
//                ymax = int.MaxValue;
//
//            // Check for any regions that are within the possible teleport range to the linked region
//            List<GridRegion> regions = m_GridService.GetRegionRange(m_ScopeID, (int)xmin, (int)xmax, (int)ymin, (int)ymax);
//            if (regions.Count == 0)
//            {
//                return false;
//            }
//            else
//            {
//                // Check for regions which are not linked regions
//                List<GridRegion> hyperlinks = m_GridService.GetHyperlinks(m_ScopeID);
//                IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
//                if (availableRegions.Count() == 0)
//                    return false;
//            }
//
//            return true;
//        }

        private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
        {
            RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo);
            int        flags = (int)OpenSim.Framework.RegionFlags.Hyperlink + (int)OpenSim.Framework.RegionFlags.NoDirectLogin + (int)OpenSim.Framework.RegionFlags.RegionOnline;

            rdata.Data["flags"] = flags.ToString();

            m_Database.Store(rdata);
        }
Esempio n. 3
0
        /// <summary>
        ///   Tells the grid server that this region is not able to be connected to.
        ///   This updates the down flag in the map and blocks it from becoming a 'safe' region fallback
        ///   Only called by LLLoginService
        /// </summary>
        /// <param name = "r"></param>
        public virtual void SetRegionUnsafe(UUID ID)
        {
            GridRegion data = m_Database.Get(ID, UUID.Zero);

            if (data == null)
            {
                return;
            }
            if ((data.Flags & (int)RegionFlags.Safe) == (int)RegionFlags.Safe)
            {
                data.Flags &= ~(int)RegionFlags.Safe;  //Remove only the safe var the first time
            }
            else if ((data.Flags & (int)RegionFlags.RegionOnline) == (int)RegionFlags.RegionOnline)
            {
                data.Flags &= ~(int)RegionFlags.RegionOnline;  //Remove online the second time it fails
            }
            m_Database.Store(data);
        }
Esempio n. 4
0
        public string RegisterRegion(GridRegion regionInfos, UUID oldSessionID, out UUID SessionID)
        {
            SessionID = UUID.Zero;
            if (m_DisableRegistrations)
            {
                return("Registrations are disabled.");
            }

            UUID NeedToDeletePreviousRegion = UUID.Zero;

            IConfig gridConfig = m_config.Configs["GridService"];

            //Get the range of this so that we get the full count and make sure that we are not overlapping smaller regions
            List <GridRegion> regions = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY,
                                                       regionInfos.RegionLocX + regionInfos.RegionSizeX - 1, regionInfos.RegionLocY + regionInfos.RegionSizeY - 1, regionInfos.ScopeID);

            if (regions.Count > 1)
            {
                //More than one region is here... it is overlapping stuff
                m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
                                 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, regionInfos.ScopeID);
                return("Region overlaps another region");
            }

            GridRegion region = regions.Count > 0 ? regions[0] : null;

            if (!m_AllowNewRegistrations && region == null)
            {
                m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register but registrations are disabled.",
                                 regionInfos.RegionName);
                return("Registrations are disabled.");
            }

            if (m_maxRegionSize != 0 && (regionInfos.RegionSizeX > m_maxRegionSize || regionInfos.RegionSizeY > m_maxRegionSize))
            {
                //Too big... kick it out
                m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register with too large of a size {1},{2}.",
                                 regionInfos.RegionName, regionInfos.RegionSizeX, regionInfos.RegionSizeY);
                return("Region overlaps another region");
            }

            if ((region != null) && (region.RegionID != regionInfos.RegionID))
            {
                m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
                                 regionInfos.RegionName, regionInfos.RegionLocX, regionInfos.RegionLocY, regionInfos.ScopeID);
                return("Region overlaps another region");
            }

            if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
                ((region.RegionLocX != regionInfos.RegionLocX) || (region.RegionLocY != regionInfos.RegionLocY)))
            {
                if ((region.Flags & (int)RegionFlags.NoMove) != 0)
                {
                    return("Can't move this region," + region.RegionLocX + "," + region.RegionLocY);
                }

                // Region reregistering in other coordinates. Delete the old entry
                m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.",
                                  regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY);

                NeedToDeletePreviousRegion = regionInfos.RegionID;
            }

            if (region != null)
            {
                // There is a preexisting record
                //
                // Get it's flags
                //
                RegionFlags rflags = (RegionFlags)region.Flags;

                // Is this a reservation?
                //
                if ((rflags & RegionFlags.Reservation) != 0)
                {
                    // Regions reserved for the null key cannot be taken.
                    if (region.SessionID == UUID.Zero)
                    {
                        return("Region location is reserved");
                    }

                    // Treat it as an auth request
                    //
                    // NOTE: Fudging the flags value here, so these flags
                    //       should not be used elsewhere. Don't optimize
                    //       this with the later retrieval of the same flags!
                    rflags |= RegionFlags.Authenticate;
                }

                if ((rflags & RegionFlags.Authenticate) != 0)
                {
                    // Can we authenticate at all?
                    //
                    if (m_AuthenticationService == null)
                    {
                        return("No authentication possible");
                    }
                    //Make sure the key exists
                    if (!m_AuthenticationService.CheckExists(regionInfos.SessionID))
                    {
                        return("Bad authentication");
                    }
                    //Now verify the key
                    if (!m_AuthenticationService.Verify(regionInfos.SessionID, regionInfos.AuthToken, 30))
                    {
                        return("Bad authentication");
                    }
                }
            }

            if (!m_AllowDuplicateNames)
            {
                List <GridRegion> dupe = m_Database.Get(regionInfos.RegionName, regionInfos.ScopeID);
                if (dupe != null && dupe.Count > 0)
                {
                    foreach (GridRegion d in dupe)
                    {
                        if (d.RegionID != regionInfos.RegionID)
                        {
                            m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register duplicate name with ID {1}.",
                                             regionInfos.RegionName, regionInfos.RegionID);
                            return("Duplicate region name");
                        }
                    }
                }
            }

            if (region != null)
            {
                //If we are locked out, we can't come in
                if ((region.Flags & (int)RegionFlags.LockedOut) != 0)
                {
                    return("Region locked out");
                }

                //Remove the reservation if we are there now
                region.Flags &= ~(int)RegionFlags.Reservation;

                regionInfos.Flags = region.Flags; // Preserve flags
            }
            else
            {
                //Regions do not get to set flags, so wipe them
                regionInfos.Flags = 0;
                //See if we are in the configs anywhere and have flags set
                if ((gridConfig != null) && regionInfos.RegionName != string.Empty)
                {
                    int    newFlags   = 0;
                    string regionName = regionInfos.RegionName.Trim().Replace(' ', '_');
                    newFlags          = ParseFlags(newFlags, gridConfig.GetString("DefaultRegionFlags", String.Empty));
                    newFlags          = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty));
                    newFlags          = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionInfos.RegionID.ToString(), String.Empty));
                    regionInfos.Flags = newFlags;
                }
            }

            //Set these so that we can make sure the region is online later
            regionInfos.Flags   |= (int)RegionFlags.RegionOnline;
            regionInfos.Flags   |= (int)RegionFlags.Safe;
            regionInfos.LastSeen = Util.UnixTimeSinceEpoch();

            if (region != null)
            {
                //If we already have a session, we need to check it
                if (m_UseSessionID && region.SessionID != oldSessionID)
                {
                    m_log.WarnFormat("[GRID SERVICE]: Region {0} called register, but the sessionID they provided is wrong!", region.RegionName);
                    return("Wrong Session ID");
                }
            }

            //Update the sessionID, use the old so that we don't generate a bunch of these
            if (oldSessionID == UUID.Zero)
            {
                SessionID = UUID.Random();
            }
            else
            {
                SessionID = oldSessionID;
            }
            regionInfos.SessionID = SessionID;

            // Everything is ok, let's register
            try
            {
                if (NeedToDeletePreviousRegion != UUID.Zero)
                {
                    m_Database.Delete(NeedToDeletePreviousRegion);
                }

                if (m_Database.Store(regionInfos))
                {
                    //Fire the event so that other modules notice
                    m_simulationBase.EventManager.FireGenericEventHandler("RegionRegistered", regionInfos);

                    m_log.DebugFormat("[GRID SERVICE]: Region {0} registered successfully at {1}-{2}",
                                      regionInfos.RegionName, regionInfos.RegionLocX, regionInfos.RegionLocY);
                    return(String.Empty);
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[GRID SERVICE]: Database exception: {0}", e.ToString());
            }

            return("Failed to save region into the database.");
        }