コード例 #1
0
        /// <summary>
        /// Changes the region estate.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="cmd">Cmd parameters.</param>
        protected void ChangeRegionEstate(IScene scene, string [] cmd)
        {
            var    conScenes = MainConsole.Instance.ConsoleScenes;
            IScene regScene  = scene;

            IEstateConnector estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> ();

            if (estateConnector == null)
            {
                MainConsole.Instance.Error("[Estate]: Unable to obtain estate connector for update");
                return;
            }

            string regionName;

            if (regScene == null)
            {
                regionName = cmd.Length > 2 ? cmd [2] : MainConsole.Instance.Prompt("The region you wish to change?");
                if (string.IsNullOrEmpty(regionName))
                {
                    return;
                }

                // find the required region/scene
                regionName = regionName.ToLower();
                foreach (IScene scn in conScenes)
                {
                    if (scn.RegionInfo.RegionName.ToLower() == regionName)
                    {
                        regScene = scn;
                        break;
                    }
                }

                if (regScene == null)
                {
                    MainConsole.Instance.Error("[Estate]: The region '" + regionName + "' could not be found.");
                    return;
                }
            }
            else
            {
                regionName = regScene.RegionInfo.RegionName;
            }

            // check for mainland regions
            if (regScene.RegionInfo.RegionType.ToLower().StartsWith("m", System.StringComparison.Ordinal))
            {
                var sysEstates     = regScene.RequestModuleInterface <ISystemEstateService> ();
                var mainlandEstate = sysEstates.MainlandEstateName;
                MainConsole.Instance.InfoFormat("[Estate]: {0} is a Mainland region and is automatically part of the '{1}' estate",
                                                regionName, mainlandEstate);
                return;
            }

            var regionID   = regScene.RegionInfo.RegionID;
            var oldOwnerID = regScene.RegionInfo.EstateSettings.EstateOwner;

            // get the new estate name
            string estateName = cmd.Length > 3
                ? cmd [3]
                : MainConsole.Instance.Prompt("The new estate for " + regionName + " (? for more options)");

            if (string.IsNullOrEmpty(estateName))
            {
                return;
            }

            int newEstateId = 0;

            if (estateName != "?")
            {
                newEstateId = estateConnector.GetEstateID(estateName);
            }

            if (newEstateId == 0)
            {
                if (estateName != "?")
                {
                    MainConsole.Instance.Warn("[Estate]: The estate '" + estateName + "' matches no known estate.");
                }

                // try the long way...
                newEstateId = GetUserEstateID(regScene, estateConnector);
                if (newEstateId == 0)
                {
                    return;
                }
                var estate = estateConnector.GetEstateIDSettings(newEstateId);
                if (estate != null)
                {
                    estateName = estate.EstateName;
                }
            }

            // we have a region & estate name
            bool deLinkEstate = true;

            if (cmd.Length == 3)
            {
                var resp = MainConsole.Instance.Prompt(
                    "Are you sure you want to change '" + regionName + "' to the '" + estateName + "' estate? (yes/no)", "yes");
                deLinkEstate = (resp.StartsWith("y", System.StringComparison.Ordinal));
            }
            if (!deLinkEstate)
            {
                return;
            }

            // good to go
            if (!estateConnector.DelinkRegion(regionID))
            {
                MainConsole.Instance.Warn("[Estate]: Aborting - Unable to remove this region from the current estate.");
                return;
            }

            // check for'Mainland'
            string regType = regScene.RegionInfo.RegionType.ToLower();

            if (regType.StartsWith("m", System.StringComparison.Ordinal))
            {
                if (newEstateId == Constants.MainlandEstateID)
                {
                    MainConsole.Instance.Info("[Estate]: This region is already part of the Mainland estate");
                    return;
                }

                // link this region to the mainland
                MainConsole.Instance.Info("[Estate]: Mainland type regions must be part of the Mainland estate");
                LinkSystemEstate(regionID, Constants.MainlandEstateID);
                return;
            }

            var newEstate = LinkRegionEstate(regionID, newEstateId);

            if (newEstate != null)
            {
                regScene.RegionInfo.EstateSettings = newEstate;

                // Linking was successful, change any previously owned parcels to the new owner
                if (oldOwnerID != UUID.Zero)
                {
                    IParcelManagementModule parcelManagement = regScene.RequestModuleInterface <IParcelManagementModule> ();
                    if (parcelManagement != null)
                    {
                        parcelManagement.ReclaimParcels(oldOwnerID, newEstate.EstateOwner);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates the estate info for a region.
        /// </summary>
        /// <returns>The estate info.</returns>
        /// <param name="scene">Scene.</param>
        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", System.StringComparison.Ordinal))
            {
                return(LinkSystemEstate(scene.RegionInfo.RegionID, Constants.MainlandEstateID));
            }

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

            string sysEstateOwnerName;
            var    sysAccount = scene.UserAccountService.GetUserAccount(scene.RegionInfo.AllScopeIDs, sysAccounts.SystemEstateOwnerUUID);

            if (!sysAccount.Valid)
            {
                sysEstateOwnerName = sysAccounts.SystemEstateOwnerName;
            }
            else
            {
                sysEstateOwnerName = sysAccount.Name;
            }


            // This is an 'Estate' so get some details....
            var    LastEstateOwner = sysEstateOwnerName;
            string LastEstateName;

            while (true)
            {
                UserAccount ownerAcct;
                string      estateOwner;

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

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

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

                    string joinSystemland = MainConsole.Instance.Prompt(
                        "Do you want to 'park' the region with the system owner/estate? (yes/no)", "yes");
                    if (joinSystemland.ToLower().StartsWith("y", System.StringComparison.Ordinal))                        // joining 'Systemland'
                    {
                        return(LinkSystemEstate(scene.RegionInfo.RegionID, Constants.SystemEstateID));
                    }

                    continue;
                }

                if (ownerEstates.Count > 1)
                {
                    MainConsole.Instance.InfoFormat("[Estate]: User {0} has {1} estates currently. {2}",
                                                    ownerAcct.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(ownerAcct.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;
                UUID           oldOwnerID = UUID.Zero;
                if (scene.RegionInfo.EstateSettings != null)
                {
                    oldOwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
                }

                if (!estateConnector.LinkRegion(scene.RegionInfo.RegionID, estateID))
                {
                    MainConsole.Instance.WarnFormat("[Estate]: Joining the {0} estate failed. Please try again.", LastEstateName);
                    continue;
                }

                // make sure that the region is fully set up
                if ((ES = estateConnector.GetRegionEstateSettings(scene.RegionInfo.RegionID)) == null || ES.EstateID == 0)
                {
                    MainConsole.Instance.Warn("[Estate]: Unable to verify region update (possible server connection error), please try again.");
                    continue;
                }

                // Linking was successful, change any previously owned parcels to the new owner
                if (oldOwnerID != UUID.Zero)
                {
                    IParcelManagementModule parcelManagement = scene.RequestModuleInterface <IParcelManagementModule> ();
                    if (parcelManagement != null)
                    {
                        parcelManagement.ReclaimParcels(oldOwnerID, ES.EstateOwner);
                    }
                }

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