Exemplo n.º 1
0
        private void HandleClearRegion(string module, string[] cmd)
        {
            if (cmd.Length <= 3)
            {
                m_log.Warn("Wrong syntax, please check the help function and try again");
                return;
            }

            string     regionName = Util.CombineParams(cmd, 3);
            GridRegion r          = GetRegionByName(UUID.Zero, cmd[3]);

            if (r == null)
            {
                m_log.Warn("Region was not found");
                return;
            }
            m_Database.Delete(r.RegionID);
        }
 private void RemoveHyperlinkRegion(UUID regionID)
 {
     m_Database.Delete(regionID);
 }
Exemplo n.º 3
0
        public virtual string RegisterRegion(GridRegion regionInfos, UUID oldSessionID, out UUID SessionID,
                                             out List <GridRegion> neighbors)
        {
            SessionID = UUID.Zero;
            neighbors = new List <GridRegion>();
            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
                MainConsole.Instance.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)
            {
                MainConsole.Instance.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
                MainConsole.Instance.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))
            {
                MainConsole.Instance.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
                MainConsole.Instance.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, "SessionID"))
                    {
                        return("Bad authentication");
                    }
                    //Now verify the key
                    if (!m_AuthenticationService.Verify(regionInfos.SessionID, "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)
                {
#if (!ISWIN)
                    foreach (GridRegion d in dupe)
                    {
                        if (d.RegionID != regionInfos.RegionID)
                        {
                            MainConsole.Instance.WarnFormat("[GRID SERVICE]: Region {0} tried to register duplicate name with ID {1}.", regionInfos.RegionName, regionInfos.RegionID);
                            return("Duplicate region name");
                        }
                    }
#else
                    if (dupe.Any(d => d.RegionID != regionInfos.RegionID))
                    {
                        MainConsole.Instance.WarnFormat("[GRID SERVICE]: Region {0} tried to register duplicate name with ID {1}.",
                                                        regionInfos.RegionName, regionInfos.RegionID);
                        return("Duplicate region name");
                    }
#endif
                }
            }

            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 (!VerifyRegionSessionID(region, oldSessionID))
                {
                    MainConsole.Instance.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
            SessionID             = oldSessionID == UUID.Zero ? UUID.Random() : 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);

                    //Get the neighbors for them
                    neighbors = GetNeighbors(regionInfos);
                    FixNeighbors(regionInfos, neighbors, false);

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

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