/// <summary> /// Create an estate with an initial region. /// </summary> /// <remarks> /// This method doesn't allow an estate to be created with the same name as existing estates. /// </remarks> /// <param name="regInfo"></param> /// <param name="estatesByName">A list of estate names that already exist.</param> /// <param name="estateName">Estate name to create if already known</param> /// <returns>true if the estate was created, false otherwise</returns> public bool CreateEstate(RegionInfo regInfo, Dictionary <string, EstateSettings> estatesByName, string estateName) { // Create a new estate regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, true); string newName; if (!string.IsNullOrEmpty(estateName)) { newName = estateName; } else { newName = MainConsole.Instance.CmdPrompt("New estate name", regInfo.EstateSettings.EstateName); } if (estatesByName.ContainsKey(newName)) { MainConsole.Instance.OutputFormat("An estate named {0} already exists. Please try again.", newName); return(false); } regInfo.EstateSettings.EstateName = newName; // FIXME: Later on, the scene constructor will reload the estate settings no matter what. // Therefore, we need to do an initial save here otherwise the new estate name will be reset // back to the default. The reloading of estate settings by scene could be eliminated if it // knows that the passed in settings in RegionInfo are already valid. Also, it might be // possible to eliminate some additional later saves made by callers of this method. regInfo.EstateSettings.Save(); return(true); }
/// <summary> /// Load the estate information for the provided RegionInfo object. /// </summary> /// <param name="regInfo"></param> public bool PopulateRegionEstateInfo(RegionInfo regInfo) { if (EstateDataService != null) { regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false); } if (regInfo.EstateSettings.EstateID != 0) { return(false); // estate info in the database did not change } m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName); List <EstateSettings> estates = EstateDataService.LoadEstateSettingsAll(); Dictionary <string, EstateSettings> estatesByName = new Dictionary <string, EstateSettings>(); foreach (EstateSettings estate in estates) { estatesByName[estate.EstateName] = estate; } string defaultEstateName = null; if (Config.Configs[ESTATE_SECTION_NAME] != null) { defaultEstateName = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateName", null); if (defaultEstateName != null) { EstateSettings defaultEstate; bool defaultEstateJoined = false; if (estatesByName.ContainsKey(defaultEstateName)) { defaultEstate = estatesByName[defaultEstateName]; if (EstateDataService.LinkRegion(regInfo.RegionID, (int)defaultEstate.EstateID)) { defaultEstateJoined = true; } } else { if (CreateEstate(regInfo, estatesByName, defaultEstateName)) { defaultEstateJoined = true; } } if (defaultEstateJoined) { return(true); // need to update the database } else { m_log.ErrorFormat( "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName); } } } // If we have no default estate or creation of the default estate failed then ask the user. while (true) { if (estates.Count == 0) { m_log.Info("[ESTATE]: No existing estates found. You must create a new one."); if (CreateEstate(regInfo, estatesByName, null)) { break; } else { continue; } } else { string response = MainConsole.Instance.CmdPrompt( string.Format( "Do you wish to join region {0} to an existing estate (yes/no)?", regInfo.RegionName), "yes", new List <string>() { "yes", "no" }); if (response == "no") { if (CreateEstate(regInfo, estatesByName, null)) { break; } else { continue; } } else { string[] estateNames = estatesByName.Keys.ToArray(); response = MainConsole.Instance.CmdPrompt( string.Format( "Name of estate to join. Existing estate names are ({0})", string.Join(", ", estateNames)), estateNames[0]); List <int> estateIDs = EstateDataService.GetEstates(response); if (estateIDs.Count < 1) { MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again."); continue; } int estateID = estateIDs[0]; regInfo.EstateSettings = EstateDataService.LoadEstateSettings(estateID); if (EstateDataService.LinkRegion(regInfo.RegionID, estateID)) { break; } MainConsole.Instance.Output("Joining the estate failed. Please try again."); } } } return(true); // need to update the database }