Exemple #1
0
        /// <summary>
        /// Links a region to a system estate.
        /// </summary>
        /// <returns>The system estate.</returns>
        /// <param name="regionID">Region ID.</param>
        /// <param name="estateID">Estate ID.</param>
        EstateSettings LinkSystemEstate(UUID regionID, int estateID)
        {
            // link region to a system estate > Mainland / Governor  or System / RealEstateOwner
            IEstateConnector     estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> ();
            ISystemEstateService sysEstates      = m_registry.RequestModuleInterface <ISystemEstateService> ();
            EstateSettings       ES;
            string estateName = sysEstates.GetSystemEstateName(estateID);

            // try & link region
            if (estateConnector.LinkRegion(regionID, estateID))
            {
                ES = estateConnector.GetRegionEstateSettings(regionID);      // refresh to check linking
                if ((ES == null) || (ES.EstateID == 0))
                {
                    MainConsole.Instance.Warn("An error was encountered linking the region to '" + estateName + "'!\n" +
                                              "Possibly a problem with the server connection, please link this region later.");
                    return(null);
                }
                MainConsole.Instance.Warn("Successfully joined '" + estateName + "'!");
                return(ES);
            }

            MainConsole.Instance.Warn("Joining '" + estateName + "' failed. Please link this region later.");
            return(null);
        }
        /// <summary>
        /// Un-link a region from an estate region.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="cmd">Cmd.</param>
        void EstateUnLinkRegionCommand(IScene scene, string [] cmd)
        {
            IEstateConnector estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> ();
            IGridService     gridService     = m_registry.RequestModuleInterface <IGridService> ();

            string estateName = "";
            string regionName = "";

            // check for passed estate name
            estateName = (cmd.Length < 4)
                ? MainConsole.Instance.Prompt("Estate name", estateName)
                : cmd [3];
            if (estateName == "")
            {
                return;
            }

            // verify that the estate does exist
            EstateSettings ES = estateConnector.GetEstateSettings(estateName);

            if (ES == null)
            {
                MainConsole.Instance.ErrorFormat("[EstateService]: The estate '{0}' does not exist!", estateName);
                return;
            }

            // check for passed  region to link to
            if (scene != null)
            {
                regionName = scene.RegionInfo.RegionName;
            }

            regionName = (cmd.Length < 4)
                ? MainConsole.Instance.Prompt("Region to remove", regionName)
                : cmd [4];
            if (regionName == "")
            {
                return;
            }

            // verify that the region does exist
            var region = gridService.GetRegionByName(null, regionName);

            if (region == null)
            {
                MainConsole.Instance.ErrorFormat("[EstateService]: The requested region '{0}' does not exist!", regionName);
                return;
            }
            regionName = region.RegionName;

            // verify that the region is actually part of the estate
            if (!estateConnector.EstateRegionExists((int)ES.EstateID, region.RegionID))
            {
                MainConsole.Instance.ErrorFormat("[EstateService]: The requested region '{0}' is not part of the '{1}' estate!",
                                                 regionName, ES.EstateName);
                return;
            }

            // have all details.. do it...
            if (!estateConnector.DelinkRegion(region.RegionID))
            {
                MainConsole.Instance.Warn("Unlinking the region failed. Please try again.");
                return;
            }

            // unlink was successful..
            MainConsole.Instance.InfoFormat("Region '{0}' has been removed from estate '{1}'",
                                            regionName, estateName);

            //We really need to attach it to another estate though...
            ISystemEstateService sysEstateInfo = m_registry.RequestModuleInterface <ISystemEstateService> ();

            ES = estateConnector.GetEstateSettings(sysEstateInfo.SystemEstateName);
            if (ES != null)
            {
                if (estateConnector.LinkRegion(region.RegionID, (int)ES.EstateID))
                {
                    MainConsole.Instance.WarnFormat("'{0}' has been placed in the '{1}' estate until re-assigned",
                                                    regionName, sysEstateInfo.SystemEstateName);
                    UpdateConsoleRegionEstate(regionName, ES);
                }
            }
        }
        /// <summary>
        /// Creates the estate info for a region.
        /// </summary>
        /// <returns>The estate info.</returns>
        /// <param name="scene">Scene.</param>
        private EstateSettings CreateEstateInfo(IScene scene)
        {
            // check for regionType to determine if this is 'Mainland' or an 'Estate'
            string regType = scene.RegionInfo.RegionType.ToLower();

            if (regType.StartsWith("m"))
            {
                return(LinkMainlandEstate(scene.RegionInfo.RegionID));
            }

            // we are linking to a user estate
            IEstateConnector     estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector>();
            ISystemEstateService sysEstateInfo   = m_registry.RequestModuleInterface <ISystemEstateService>();

            string sysEstateOwnerName;
            var    sysAccount = scene.UserAccountService.GetUserAccount(scene.RegionInfo.AllScopeIDs, (UUID)Constants.RealEstateOwnerUUID);

            if (sysAccount == null)
            {
                sysEstateOwnerName = sysEstateInfo.SystemEstateOwnerName;
            }
            else
            {
                sysEstateOwnerName = sysAccount.Name;
            }


            // This is an 'Estate' so get some details....
            LastEstateOwner = sysEstateOwnerName;
            while (true)
            {
                UserAccount account;
                string      estateOwner;

                estateOwner = MainConsole.Instance.Prompt("Estate owner name (" + sysEstateOwnerName + "/User Name)", LastEstateOwner);

                // we have a prospective estate owner...
                List <EstateSettings> ownerEstates = null;
                account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.AllScopeIDs, estateOwner);
                if (account != null)
                {
                    // we have a user account...
                    LastEstateOwner = account.Name;

                    ownerEstates = estateConnector.GetEstates(account.PrincipalID);
                }

                if (account == null || ownerEstates == null || ownerEstates.Count == 0)
                {
                    if (account == null)
                    {
                        MainConsole.Instance.Warn("[Estate]: Unable to locate the user " + estateOwner);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[Estate]: The user, {0}, has no estates currently.", account.Name);
                    }

                    string joinMainland = MainConsole.Instance.Prompt(
                        "Do you want to 'park' the region with the system owner/estate? (yes/no)", "yes");
                    if (joinMainland.ToLower().StartsWith("y"))                      // joining 'mainland'
                    {
                        return(LinkMainlandEstate(scene.RegionInfo.RegionID));
                    }

                    continue;
                }

                if (ownerEstates.Count > 1)
                {
                    MainConsole.Instance.InfoFormat("[Estate]: User {0} has {1} estates currently. {2}",
                                                    account.Name, ownerEstates.Count, "These estates are the following:");
                    foreach (EstateSettings t in ownerEstates)
                    {
                        MainConsole.Instance.CleanInfo("         " + t.EstateName);
                    }

                    LastEstateName = ownerEstates[0].EstateName;

                    List <string> responses = ownerEstates.Select(settings => settings.EstateName).ToList();
                    responses.Add("Cancel");

                    do
                    {
                        //TODO: This could be a problem if we have a lot of estates
                        string response = MainConsole.Instance.Prompt("Estate name to join", LastEstateName, responses);
                        if (response == "None" || response == "Cancel")
                        {
                            LastEstateName = "";
                            break;
                        }
                        LastEstateName = response;
                    } while (LastEstateName == "");
                    if (LastEstateName == "")
                    {
                        continue;
                    }
                }
                else
                {
                    LastEstateName = ownerEstates[0].EstateName;
                }


                // we should have a user account and estate name by now
                int estateID = estateConnector.GetEstate(account.PrincipalID, LastEstateName);
                if (estateID == 0)
                {
                    MainConsole.Instance.Warn("[Estate]: The name you have entered matches no known estate. Please try again");
                    continue;
                }

                // link up the region
                EstateSettings ES;
                if (estateConnector.LinkRegion(scene.RegionInfo.RegionID, estateID))
                {
                    if ((ES = estateConnector.GetEstateSettings(scene.RegionInfo.RegionID)) == null ||
                        ES.EstateID == 0)
                    //We could do by EstateID now, but we need to completely make sure that it fully is set up
                    {
                        MainConsole.Instance.Warn("[Estate]: The connection to the server was broken, please try again.");
                        continue;
                    }
                }
                else
                {
                    MainConsole.Instance.WarnFormat("[Estate]: Joining the {0} estate failed. Please try again.", LastEstateName);
                    continue;
                }

                MainConsole.Instance.InfoFormat("[Estate]: Successfully joined the {0} estate!", LastEstateName);
                return(ES);
            }
        }