/// <summary> /// Loads all Parcel data from the datastore for region identified by regionID /// </summary> public void LoadAllLandObjectsFromStorage() { if (m_haveLoadedParcels || !m_shouldLoadParcels) { return; } m_haveLoadedParcels = true; m_log.Info("[BackupModule]: Loading Land Objects from database... "); IParcelServiceConnector conn = DataManager.DataManager.RequestPlugin <IParcelServiceConnector>(); List <LandData> LandObjects = m_scene.SimulationDataService.LoadLandObjects(m_scene.RegionInfo.RegionID); if (conn != null) { //Read from the old database as well if (LandObjects.Count != 0) { foreach (LandData land in LandObjects) { //Store it in the new database conn.StoreLandObject(land); //Remove it from the old m_scene.SimulationDataService.RemoveLandObject(m_scene.RegionInfo.RegionID, land.GlobalID); } } m_scene.EventManager.TriggerIncomingLandDataFromStorage(conn.LoadLandObjects(m_scene.RegionInfo.RegionID)); } }
public EventData CreateEvent(UUID creator, UUID regionID, UUID parcelID, DateTime date, uint cover, EventFlags maturity, uint flags, uint duration, Vector3 localPos, string name, string description, string category) { IRegionData regiondata = Aurora.DataManager.DataManager.RequestPlugin <IRegionData>(); IParcelServiceConnector parceldata = Aurora.DataManager.DataManager.RequestPlugin <IParcelServiceConnector>(); if (regiondata == null || parceldata == null) { return(null); } GridRegion region = regiondata.Get(regionID, UUID.Zero); if (region == null) { return(null); } if (parcelID != UUID.Zero) { LandData parcel = parceldata.GetLandData(region.RegionID, parcelID); if (parcel == null) { return(null); } } EventData eventData = new EventData(); eventData.eventID = GetMaxEventID() + 1; eventData.creator = creator.ToString(); eventData.simName = region.RegionName; eventData.date = date.ToString(new DateTimeFormatInfo()); eventData.dateUTC = (uint)Util.ToUnixTime(date); eventData.cover = eventData.amount = cover; eventData.maturity = (int)maturity; eventData.eventFlags = flags | (uint)maturity; eventData.duration = duration; eventData.globalPos = new Vector3( region.RegionLocX + localPos.X, region.RegionLocY + localPos.Y, region.RegionLocZ + localPos.Z ); eventData.name = name; eventData.description = description; eventData.category = category; GD.Insert("asevents", new string[] { "EID", "creator", "region", "parcel", "date", "cover", "maturity", "flags", "duration", "localPosX", "localPosY", "localPosZ", "name", "description", "category" }, new object[] { eventData.eventID, creator.ToString(), regionID.ToString(), parcelID.ToString(), date.ToString("s"), eventData.cover, (uint)maturity, flags, duration, localPos.X, localPos.Y, localPos.Z, name, description, category }); return(eventData); }
/// <summary> /// Checks whether an older style database exists /// </summary> /// <returns>Whether an older style database exists</returns> protected virtual bool CheckForOldDataBase() { string connString = ""; string name = ""; // Try reading the [DatabaseService] section, if it exists IConfig dbConfig = m_scene.Config.Configs["DatabaseService"]; if (dbConfig != null) { connString = dbConfig.GetString("ConnectionString", String.Empty); } // Try reading the [SimulationDataStore] section IConfig simConfig = m_scene.Config.Configs["SimulationDataStore"]; if (simConfig != null) { name = simConfig.GetString("LegacyDatabaseLoaderName", "FileBasedDatabase"); connString = simConfig.GetString("ConnectionString", connString); } ILegacySimulationDataStore[] stores = AuroraModuleLoader.PickupModules <ILegacySimulationDataStore>().ToArray(); #if (!ISWIN) ILegacySimulationDataStore simStore = null; foreach (ILegacySimulationDataStore store in stores) { if (store.Name == name) { simStore = store; break; } } #else ILegacySimulationDataStore simStore = stores.FirstOrDefault(store => store.Name == name); #endif if (simStore == null) { return(false); } try { if (!m_hasShownFileBasedWarning) { m_hasShownFileBasedWarning = true; IConfig startupConfig = m_scene.Config.Configs["Startup"]; if (startupConfig == null || startupConfig.GetBoolean("NoGUI", false)) { DoNoGUIWarning(); } else if (!m_scene.RegionInfo.NewRegion) { MessageBox.Show( @"Your sim has been updated to use the FileBased Simulation Service. Your sim is now saved in a .abackup file in the bin/ directory with the same name as your region. More configuration options and info can be found in the Configuration/Data/FileBased.ini file.", "WARNING"); } } } catch { DoNoGUIWarning(); } simStore.Initialise(connString); IParcelServiceConnector conn = DataManager.DataManager.RequestPlugin <IParcelServiceConnector>(); m_parcels = simStore.LoadLandObjects(m_scene.RegionInfo.RegionID); m_parcels.AddRange(conn.LoadLandObjects(m_scene.RegionInfo.RegionID)); m_groups = simStore.LoadObjects(m_scene.RegionInfo.RegionID, m_scene); if (m_groups.Count != 0 || m_parcels.Count != 0) { try { m_shortterrain = simStore.LoadTerrain(m_scene, false, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY); m_shortrevertTerrain = simStore.LoadTerrain(m_scene, true, m_scene.RegionInfo.RegionSizeX, m_scene.RegionInfo.RegionSizeY); //Remove these so that we don't get stuck loading them later conn.RemoveAllLandObjects(m_scene.RegionInfo.RegionID); simStore.RemoveAllLandObjects(m_scene.RegionInfo.RegionID); } catch { } return(true); } return(false); }
/// <summary> /// This method will produce a random city with the central region of the city being /// specified as a parameter. More parameters need to be made available for this method /// to produce a better quality city, note for now the minimum area for a city is a /// 3x3 grid of regions. This code is based on the original C++ version called pixel city. /// </summary> /// <param name="seed_value">Random integer seed value.</param> /// <returns>true / false indicator of success or failure.</returns> private bool doGenerate(int seed_value) { int rx, ry; // Based on the initial seed value populate the regions that this shared module // is connected to, this means first get a list of the region, determine which // region is in the center of all the regions and set this as the hotzone, or // central part of the city (this is where the tallest/largest buildings will // be created) and will extend out to cover virtually all of the connected // regions if desired. No support for aging of the buildings or the city exists // yet it is a possible course for the future of this module. // First quick check to see if the module is enabled or not. if (!m_fEnabled) { m_log.Info("[CITY BUILDER]: Disabled, aborting auto generation."); return(false); } m_log.Info("[CITY BUILDER]: Auto generating the city."); // Now we need to ask some basic values for the city generation, we already have // the base seed value as this is part of the 'city generate' command, now what // about a name, position, size, densities etc. Some of this can be generated // based on the seed value, but then, it would need to be confirmed by the user // or allow them to change it. TODO move all requested data into the configuration file. if (m_UserAccountService == null) { m_UserAccountService = simulationBase.ApplicationRegistry.RequestModuleInterface <IUserAccountService>(); } // Decide where the city is to be placed within the server instance. int r = this.randomValue(10); string regionCount = MainConsole.Instance.CmdPrompt("Region Count ", r.ToString()); r = Convert.ToInt32(regionCount); m_log.InfoFormat("[CITY BUILDER]: City area {0} x {1} regions ", r, r); cityName = MainConsole.Instance.CmdPrompt("City Name ", cityName); cityOwner = MainConsole.Instance.CmdPrompt("City Owner ", cityOwner); m_DefaultUserName = cityOwner; // Make sure that the user and estate information specified in the configuration file // have been loaded and the information has either been found or has been created. m_DefaultUserAccount = m_UserAccountService.GetUserAccount(UUID.Zero, cityOwner); if (m_DefaultUserAccount == null) { m_log.InfoFormat("[CITY BUILDER]: Creating default account {0}", m_DefaultUserName); m_UserAccountService.CreateUser(m_DefaultUserName, Util.Md5Hash(m_DefaultUserPword), m_DefaultUserEmail); m_DefaultUserAccount = m_UserAccountService.GetUserAccount(UUID.Zero, m_DefaultUserName); cityOwner = m_DefaultUserName; } else { m_log.InfoFormat("[CITY BUILDER]: Account found for {0}", m_DefaultUserName); } // Obtain the scene manager that the server instance is using. sceneManager = simulationBase.ApplicationRegistry.RequestModuleInterface <SceneManager>(); // Construct the data instance for a city map to hold the total regions in the simulation. cityMap = new CityMap(); citySeed = seed_value; cityMap.cityRegions = new Scene[r, r]; cityMap.cityPlots = new List <BuildingPlot>(); cityMap.cityBuildings = new List <CityBuilding>(); // Construct land and estate data and update to reflect the found user or the newly created one. cityLandData = new LandData(); RegionInfo regionInfo = new RegionInfo(); regionInfo.RegionID = UUID.Random(); //Create an estate m_DefaultEstate = new EstateSettings(); m_log.InfoFormat("[CITY BUILDER]: No estates found for user {0}, constructing default estate.", m_DefaultUserAccount.Name); m_DefaultEstate.EstateOwner = m_DefaultUserAccount.PrincipalID; m_DefaultEstate.EstateName = m_DefaultEstateName; m_DefaultEstate.EstatePass = Util.Md5Hash(Util.Md5Hash(m_DefaultEstatePassword)); m_DefaultEstate.EstateID = (uint)this.randomValue(1000); regionInfo.EstateSettings = m_DefaultEstate; //Just set the estate, this module took care of the loading and the rest will leave it alone cityLandData.OwnerID = m_DefaultUserAccount.PrincipalID; cityLandData.Name = m_DefaultEstateName; cityLandData.GlobalID = UUID.Random(); cityLandData.GroupID = UUID.Zero; int regionPort = startPort; // Construct the region. regionInfo.RegionSizeX = cityConfig.GetInt("DefaultRegionSize", 256); regionInfo.RegionSizeY = regionInfo.RegionSizeX; regionInfo.RegionType = "Mainland"; regionInfo.ObjectCapacity = 100000; regionInfo.Startup = StartupType.Normal; regionInfo.ScopeID = UUID.Zero; IParcelServiceConnector parcelService = Aurora.DataManager.DataManager.RequestPlugin <IParcelServiceConnector>(); if (r == 1) { m_log.Info("[CITY BUILDER]: Single region city."); IPAddress address = IPAddress.Parse("0.0.0.0"); regionInfo.ExternalHostName = Aurora.Framework.Utilities.GetExternalIp(); regionInfo.FindExternalAutomatically = true; regionInfo.InternalEndPoint = new IPEndPoint(address, regionPort++); cityLandData.RegionID = regionInfo.RegionID; if (parcelService != null) { parcelService.StoreLandObject(cityLandData.LandData); } regionInfo.RegionName = "Region00"; regionInfo.RegionLocX = (int)m_DefaultStartLocation.X; regionInfo.RegionLocY = (int)m_DefaultStartLocation.Y; if (!createRegion(0, 0, regionInfo)) { m_log.Info("[CITY BUILDER]: Failed to construct region."); return(false); } } else if (r > 1) { m_log.Info("[CITY BUILDER]: Multi-region city."); IPAddress address = IPAddress.Parse("0.0.0.0"); regionInfo.ExternalHostName = Aurora.Framework.Utilities.GetExternalIp(); regionInfo.FindExternalAutomatically = true; // Construct the regions for the city. regionPort = startPort; for (rx = 0; rx < r; rx++) { for (ry = 0; ry < r; ry++) { regionInfo.InternalEndPoint = new IPEndPoint(address, regionPort++); cityLandData.RegionID = regionInfo.RegionID; if (parcelService != null) { parcelService.StoreLandObject(cityLandData.LandData); } regionInfo.RegionName = "Region" + rx + ry; regionInfo.RegionLocX = (int)(m_DefaultStartLocation.X + rx); regionInfo.RegionLocY = (int)(m_DefaultStartLocation.Y + ry); m_log.InfoFormat("[CITY BUILDER]: '{0}' @ {1},{2}, http://{3}/", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY, regionInfo.InternalEndPoint); //We already set the estate before, we don't need to deal with linking it or anything //EstateConnector.LinkRegion(regionInfo.RegionID, (int)m_DefaultEstate.EstateID, m_DefaultEstate.EstatePass); if (!createRegion(rx, ry, regionInfo)) { m_log.InfoFormat("[CITY BUILDER]: Failed to construct region at {0},{1}", rx, ry); return(false); } } } } // Either generate the terrain or loading from an existing file, DEM for example. m_log.Info("[CITY BUILDER]: [TERRAIN]"); // For each region, just fill the terrain to be 21. This is just above the default // water level for Aurora. float[,] tHeight = new float[256, 256]; for (rx = 0; rx < 256; rx++) { for (ry = 0; ry < 256; ry++) { tHeight[rx, ry] = 21.0f; } } // Construct the new terrain for each region and pass the height map to it. for (rx = 0; rx < r; rx++) { for (ry = 0; ry < r; ry++) { Scene region = cityMap.cityRegions[rx, ry]; ITerrainChannel tChannel = new TerrainChannel(true, region); ITerrain terrain = null; try { region.TryRequestModuleInterface <ITerrain>(out terrain); terrain.SetHeights2D(tHeight); } catch { } } } // Rivers and other waterways. // From the total number of regions pick a number of regions that will be 'centers' // for the entire city, record these in the centralRegions list. m_log.Info("[CITY BUILDER]: [CENTERS]"); // ( region count * region count ) / 3 int aNum = this.randomValue((cityMap.cityRegions.GetUpperBound(0) * cityMap.cityRegions.GetUpperBound(1)) / 3); if (aNum == 0) { aNum = 1; } m_log.InfoFormat("[CITY BUILDER]: Total regions {0}, selecting {1} regions for centers.", (r * r), aNum); int prevRegionX = 0; int prevRegionY = 0; while (aNum > 0) { int currRegionX = randomValue(cityMap.cityRegions.GetUpperBound(0)) / 2; int currRegionY = randomValue(cityMap.cityRegions.GetUpperBound(1)) / 2; // If the location selected is the same as the previous location try again. if (currRegionX == prevRegionX && currRegionY == prevRegionY) { aNum--; continue; } m_log.InfoFormat("[CITY BUILDER]: Region {0}, located {1},{2}", aNum, prevRegionX, prevRegionY); try { Scene region = cityMap.centralRegions[(prevRegionX * cityMap.cityRegions.GetUpperBound(0)) + prevRegionY]; if (region != null) { cityMap.centralRegions.Add(region); } } catch { } aNum--; prevRegionX = currRegionX; prevRegionY = currRegionY; } m_log.Info("[CITY BUILDER]: [DENSITY]"); float avgDensity = 0.0f; avgDensity += cityDensities[0]; avgDensity += cityDensities[1]; avgDensity += cityDensities[2]; avgDensity += cityDensities[3]; avgDensity /= 4; // Before ANYTHING else is created construct the transport systems, priority is given // to the road network before the rail network, perhaps a configuration option to allow // for the prioritisation value of the transport system is possible. m_log.Info("[CITY BUILDER]: [FREEWAYS]"); m_log.Info("[CITY BUILDER]: [HIGHWAYS]"); m_log.Info("[CITY BUILDER]: [STREETS]"); m_log.Info("[CITY BUILDER]: [RAILWAYS]"); m_log.InfoFormat("[CITY BUILDER]: [RESIDENTIAL DENSITY] {0}%", cityDensities[0] * 100); m_log.InfoFormat("[CITY BUILDER]: [COMMERCIAL DENSITY] {0}%", cityDensities[1] * 100); m_log.InfoFormat("[CITY BUILDER]: [CORPORATE DENSITY] {0}%", cityDensities[2] * 100); m_log.InfoFormat("[CITY BUILDER]: [INDUSTRIAL DENISTY] {0}%", cityDensities[3] * 100); m_log.InfoFormat("[CITY BUILDER]: [AVERAGE DENSITY] {0}%", avgDensity); m_log.Info("[CITY BUILDER]: [BLOCKS]"); m_log.Info("[CITY BUILDER]: [ALLOTMENT PLOTS]"); m_log.Info("[CITY BUILDER]: [BUILDINGS]"); return(true); }