/// <summary>
        /// Creates a new estate.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="cmd">Cmd.</param>
        protected void CreateEstateCommand(IScene scene, string [] cmd)
        {
            IEstateConnector      estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> ();
            IUserAccountService   accountService  = m_registry.RequestModuleInterface <IUserAccountService> ();
            ISystemAccountService sysAccounts     = m_registry.RequestModuleInterface <ISystemAccountService> ();

            string estateName  = "";
            string estateOwner = sysAccounts.SystemEstateOwnerName;

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

            // verify that the estate does not already exist
            if (estateConnector.EstateExists(estateName))
            {
                MainConsole.Instance.ErrorFormat("[EstateService]: The estate '{0}' already exists!", estateName);
                return;
            }

            // owner?
            estateOwner = (cmd.Length > 3)
                ? Util.CombineParams(cmd, 4)  // in case of spaces in the name eg Allan Allard
                : MainConsole.Instance.Prompt("Estate owner: ", estateOwner);
            if (estateOwner == "")
            {
                return;
            }


            // check to make sure the user exists
            UserAccount account = accountService.GetUserAccount(null, estateOwner);

            if (account == null)
            {
                MainConsole.Instance.WarnFormat("[User account service]: The user, '{0}' was not found!", estateOwner);

                // temporary fix until remote user creation can be implemented
                if (accountService.IsLocalConnector)
                {
                    string createUser = MainConsole.Instance.Prompt("Do you wish to create this user?  (yes/no)", "yes").ToLower();
                    if (!createUser.StartsWith("y", StringComparison.Ordinal))
                    {
                        return;
                    }

                    // Create a new account
                    string password = MainConsole.Instance.PasswordPrompt(estateOwner + "'s password");
                    string email    = MainConsole.Instance.Prompt(estateOwner + "'s email", "");

                    accountService.CreateUser(estateOwner, Util.Md5Hash(password), email);
                    // CreateUser will tell us success or problem
                    account = accountService.GetUserAccount(null, estateOwner);

                    if (account == null)
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[EstateService]: Unable to store account details.\n   If this simulator is connected to a grid, create the estate owner account first at the grid level.");
                        return;
                    }
                }
                else
                {
                    MainConsole.Instance.WarnFormat("[User account service]: The user must be created on the Grid before assigning an estate!");
                    MainConsole.Instance.WarnFormat("[User account service]: Regions should be assigned to the system user estate until this can be corrected");

                    return;
                }
            }

            // check for bogies...
            if (Utilities.IsSystemUser(account.PrincipalID))
            {
                MainConsole.Instance.Info("[EstateService]: Tsk, tsk.  System users should not be used as estate managers!");
                return;
            }

            // we have an estate name and a user
            // Create a new estate
            var ES = new EstateSettings();

            ES.EstateName  = estateName;
            ES.EstateOwner = account.PrincipalID;

            ES.EstateID = (uint)estateConnector.CreateNewEstate(ES);
            if (ES.EstateID == 0)
            {
                MainConsole.Instance.Warn("There was an error in creating this estate: " + ES.EstateName);
                //EstateName holds the error. See LocalEstateConnector for more info.
            }
            else
            {
                MainConsole.Instance.InfoFormat("[EstateService]: The estate '{0}' owned by '{1}' has been created.", estateName, estateOwner);
            }
        }
        /// <summary>
        /// Checks for a valid system estate. Adds or corrects if required
        /// </summary>
        /// <param name="estateID">Estate I.</param>
        /// <param name="estateName">Estate name.</param>
        /// <param name="ownerUUID">Owner UUI.</param>
        void CheckSystemEstateInfo(int estateID, string estateName, UUID ownerUUID)
        {
            // these should have already been checked but just make sure...
            if (m_estateConnector == null)
            {
                return;
            }

            if (m_estateConnector.RemoteCalls())
            {
                return;
            }

            ISystemAccountService sysAccounts = m_registry.RequestModuleInterface <ISystemAccountService> ();
            EstateSettings        ES;

            // check for existing estate name in case of estate ID change
            ES = m_estateConnector.GetEstateSettings(estateName);
            if (ES != null)
            {
                // ensure correct ID
                if (ES.EstateID != estateID)
                {
                    UpdateSystemEstates(m_estateConnector, ES, estateID);
                }
            }

            ES = m_estateConnector.GetEstateIDSettings(estateID);
            if ((ES != null) && (ES.EstateID != 0))
            {
                // ensure correct owner
                if (ES.EstateOwner != ownerUUID)
                {
                    ES.EstateOwner = ownerUUID;
                    m_estateConnector.SaveEstateSettings(ES);
                    MainConsole.Instance.Info("[EstateService]: The system Estate owner has been updated to " +
                                              sysAccounts.GetSystemEstateOwnerName(estateID));
                }


                // in case of configuration changes
                if (ES.EstateName != estateName)
                {
                    ES.EstateName = estateName;
                    m_estateConnector.SaveEstateSettings(ES);
                    MainConsole.Instance.Info("[EstateService]: The system Estate name has been updated to " + estateName);
                }

                return;
            }

            // Create a new estate

            ES             = new EstateSettings();
            ES.EstateName  = estateName;
            ES.EstateOwner = ownerUUID;

            ES.EstateID = (uint)m_estateConnector.CreateNewEstate(ES);
            if (ES.EstateID == 0)
            {
                MainConsole.Instance.Warn("There was an error in creating the system estate: " + ES.EstateName);
                //EstateName holds the error. See LocalEstateConnector for more info.
            }
            else
            {
                MainConsole.Instance.InfoFormat("[EstateService]: The estate '{0}' owned by '{1}' has been created.",
                                                ES.EstateName, sysAccounts.GetSystemEstateOwnerName(estateID));
            }
        }
        protected void HandleResetSystemEstate(IScene scene, string [] cmd)
        {
            // delete and recreate the system estate
            IEstateConnector      estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> ();
            ISystemAccountService sysAccounts     = m_registry.RequestModuleInterface <ISystemAccountService> ();

            bool update = false;

            // verify that the estate does exist
            EstateSettings ES;

            ES = estateConnector.GetEstateSettings(Constants.SystemEstateName);
            if (ES == null)
            {
                ES = estateConnector.GetEstateSettings(SystemEstateName);
                if (ES == null)
                {
                    MainConsole.Instance.ErrorFormat("[EstateService]: The estate '{0}' does not exist yet!", SystemEstateName);
                    MainConsole.Instance.Warn("[EstateService]: It will be created when you link a region to the estate");
                }
            }

            // A system Estate exists?
            if (ES != null)
            {
                if (ES.EstateName != SystemEstateName)
                {
                    ES.EstateName = SystemEstateName;
                    update        = true;
                }

                if (ES.EstateOwner != sysAccounts.SystemEstateOwnerUUID)
                {
                    ES.EstateOwner = sysAccounts.SystemEstateOwnerUUID;
                    update         = true;
                }

                // save any updates
                if (update)
                {
                    estateConnector.SaveEstateSettings(ES);
                    MainConsole.Instance.Warn("[EstateService]: Estate details have been updated");
                }
            }

            // check the System estate owner details
            UserAccount uinfo;

            uinfo = m_accountService.GetUserAccount(null, UUID.Parse(Constants.RealEstateOwnerUUID));
            if (uinfo == null)
            {
                MainConsole.Instance.Warn("[EstateService]: The system estate user does not exist yet!");
                MainConsole.Instance.Warn("[EstateService]: This account will be created automatically");
            }

            if ((uinfo != null) && (uinfo.Name != sysAccounts.SystemEstateOwnerName))
            {
                //string[] name = uinfo.Name.Split (' ');
                //uinfo.FirstName = name [0];
                //uinfo.LastName = name [1];
                uinfo.Name = sysAccounts.SystemEstateOwnerName;
                m_accountService.StoreUserAccount(uinfo);
                update = true;
            }

            if (update)
            {
                MainConsole.Instance.InfoFormat("[EstateService]: The system Estate details have been reset");
            }
            else
            {
                MainConsole.Instance.InfoFormat("[EstateService]: Estate details are correct as configured");
            }
        }
Пример #4
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);
            }
        }