public static string Serialize(Simulator settings, RegionSettings reg) { StringWriter sw = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(sw); xtw.Formatting = Formatting.Indented; xtw.WriteStartDocument(); xtw.WriteStartElement("RegionSettings"); xtw.WriteStartElement("General"); xtw.WriteElementString("AllowDamage", ((settings.Flags & RegionFlags.AllowDamage) != 0).ToString()); xtw.WriteElementString("AllowLandResell", ((settings.Flags & RegionFlags.BlockLandResell) == 0).ToString()); xtw.WriteElementString("AllowLandJoinDivide", ((settings.Flags & RegionFlags.AllowParcelChanges) != 0).ToString()); xtw.WriteElementString("BlockFly", ((settings.Flags & RegionFlags.NoFly) != 0).ToString()); xtw.WriteElementString("BlockLandShowInSearch", ((settings.Flags & RegionFlags.BlockParcelSearch) != 0).ToString()); xtw.WriteElementString("BlockTerraform", ((settings.Flags & RegionFlags.BlockTerraform) != 0).ToString()); xtw.WriteElementString("DisableCollisions", ((settings.Flags & RegionFlags.SkipCollisions) != 0).ToString()); xtw.WriteElementString("DisablePhysics", ((settings.Flags & RegionFlags.SkipPhysics) != 0).ToString()); xtw.WriteElementString("DisableScripts", ((settings.Flags & RegionFlags.SkipScripts) != 0).ToString()); xtw.WriteElementString("MaturityRating", settings.Access.ToString()); xtw.WriteElementString("RestrictPushing", ((settings.Flags & RegionFlags.RestrictPushObject) != 0).ToString()); xtw.WriteElementString("AgentLimit", reg.AgentLimit.ToString()); xtw.WriteElementString("ObjectBonus", reg.ObjectBonus.ToString()); xtw.WriteEndElement(); xtw.WriteStartElement("GroundTextures"); xtw.WriteElementString("Texture1", settings.TerrainDetail0.ToString()); xtw.WriteElementString("Texture2", settings.TerrainDetail1.ToString()); xtw.WriteElementString("Texture3", settings.TerrainDetail2.ToString()); xtw.WriteElementString("Texture4", settings.TerrainDetail3.ToString()); xtw.WriteElementString("ElevationLowSW", settings.TerrainStartHeight00.ToString()); xtw.WriteElementString("ElevationLowNW", settings.TerrainStartHeight01.ToString()); xtw.WriteElementString("ElevationLowSE", settings.TerrainStartHeight10.ToString()); xtw.WriteElementString("ElevationLowNE", settings.TerrainStartHeight11.ToString()); xtw.WriteElementString("ElevationHighSW", settings.TerrainHeightRange00.ToString()); xtw.WriteElementString("ElevationHighNW", settings.TerrainHeightRange01.ToString()); xtw.WriteElementString("ElevationHighSE", settings.TerrainHeightRange10.ToString()); xtw.WriteElementString("ElevationHighNE", settings.TerrainHeightRange11.ToString()); xtw.WriteEndElement(); xtw.WriteStartElement("Terrain"); xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString()); xtw.WriteElementString("TerrainRaiseLimit", reg.TerrainRaiseLimit.ToString()); xtw.WriteElementString("TerrainLowerLimit", reg.TerrainLowerLimit.ToString()); xtw.WriteElementString("UseEstateSun", reg.UseEstateSun.ToString()); xtw.WriteElementString("FixedSun", reg.FixedSun.ToString()); //todo xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which // calculates it automatically according to the date and other factors. xtw.WriteEndElement(); xtw.WriteEndElement(); xtw.Close(); sw.Close(); return sw.ToString(); }
private static bool LoadRegionSettings(string filePath, byte[] data, SettingsLoadedCallback settingsCallback) { RegionSettings settings = null; bool loaded = false; try { using (MemoryStream stream = new MemoryStream(data)) settings = RegionSettings.FromStream(stream); loaded = true; } catch (Exception ex) { Logger.Log("[OarFile] Failed to parse region settings file " + filePath + ": " + ex.Message, Helpers.LogLevel.Warning); } // Parse the region name out of the filename string regionName = Path.GetFileNameWithoutExtension(filePath); if (loaded) { settingsCallback(regionName, settings); } return(loaded); }
public static void SaveRegionSettings(Simulator sim, string settingsPath) { if (Directory.Exists(settingsPath)) { Directory.Delete(settingsPath, true); } Thread.Sleep(100); Directory.CreateDirectory(settingsPath); Thread.Sleep(100); RegionSettings settings = new RegionSettings(); //settings.AgentLimit; settings.AllowDamage = (sim.Flags & RegionFlags.AllowDamage) == RegionFlags.AllowDamage; //settings.AllowLandJoinDivide; settings.AllowLandResell = (sim.Flags & RegionFlags.BlockLandResell) != RegionFlags.BlockLandResell; settings.BlockFly = (sim.Flags & RegionFlags.NoFly) == RegionFlags.NoFly; settings.BlockLandShowInSearch = (sim.Flags & RegionFlags.BlockParcelSearch) == RegionFlags.BlockParcelSearch; settings.BlockTerraform = (sim.Flags & RegionFlags.BlockTerraform) == RegionFlags.BlockTerraform; settings.DisableCollisions = (sim.Flags & RegionFlags.SkipCollisions) == RegionFlags.SkipCollisions; settings.DisablePhysics = (sim.Flags & RegionFlags.SkipPhysics) == RegionFlags.SkipPhysics; settings.DisableScripts = (sim.Flags & RegionFlags.SkipScripts) == RegionFlags.SkipScripts; settings.FixedSun = (sim.Flags & RegionFlags.SunFixed) == RegionFlags.SunFixed; settings.MaturityRating = (int)(sim.Access & SimAccess.Mature & SimAccess.Adult & SimAccess.PG); //settings.ObjectBonus; settings.RestrictPushing = (sim.Flags & RegionFlags.RestrictPushObject) == RegionFlags.RestrictPushObject; settings.TerrainDetail0 = sim.TerrainDetail0; settings.TerrainDetail1 = sim.TerrainDetail1; settings.TerrainDetail2 = sim.TerrainDetail2; settings.TerrainDetail3 = sim.TerrainDetail3; settings.TerrainHeightRange00 = sim.TerrainHeightRange00; settings.TerrainHeightRange01 = sim.TerrainHeightRange01; settings.TerrainHeightRange10 = sim.TerrainHeightRange10; settings.TerrainHeightRange11 = sim.TerrainHeightRange11; settings.TerrainStartHeight00 = sim.TerrainStartHeight00; settings.TerrainStartHeight01 = sim.TerrainStartHeight01; settings.TerrainStartHeight10 = sim.TerrainStartHeight10; settings.TerrainStartHeight11 = sim.TerrainStartHeight11; //settings.UseEstateSun; settings.WaterHeight = sim.WaterHeight; settings.ToXML(Path.Combine(settingsPath, sim.Name + ".xml")); }
public static RegionSettings FromStream(Stream stream) { RegionSettings settings = new RegionSettings(); System.Globalization.NumberFormatInfo nfi = Utils.EnUsCulture.NumberFormat; using (XmlTextReader xtr = new XmlTextReader(stream)) { xtr.ReadStartElement("RegionSettings"); xtr.ReadStartElement("General"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "AllowDamage": settings.AllowDamage = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AllowLandResell": settings.AllowLandResell = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AllowLandJoinDivide": settings.AllowLandJoinDivide = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockFly": settings.BlockFly = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockLandShowInSearch": settings.BlockLandShowInSearch = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockTerraform": settings.BlockTerraform = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisableCollisions": settings.DisableCollisions = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisablePhysics": settings.DisablePhysics = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisableScripts": settings.DisableScripts = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "MaturityRating": settings.MaturityRating = Int32.Parse(xtr.ReadElementContentAsString()); break; case "RestrictPushing": settings.RestrictPushing = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AgentLimit": settings.AgentLimit = Int32.Parse(xtr.ReadElementContentAsString()); break; case "ObjectBonus": settings.ObjectBonus = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; } } xtr.ReadEndElement(); xtr.ReadStartElement("GroundTextures"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "Texture1": settings.TerrainDetail0 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture2": settings.TerrainDetail1 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture3": settings.TerrainDetail2 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture4": settings.TerrainDetail3 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "ElevationLowSW": settings.TerrainStartHeight00 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowNW": settings.TerrainStartHeight01 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowSE": settings.TerrainStartHeight10 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowNE": settings.TerrainStartHeight11 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighSW": settings.TerrainHeightRange00 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighNW": settings.TerrainHeightRange01 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighSE": settings.TerrainHeightRange10 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighNE": settings.TerrainHeightRange11 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; } } xtr.ReadEndElement(); xtr.ReadStartElement("Terrain"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "WaterHeight": settings.WaterHeight = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "TerrainRaiseLimit": settings.TerrainRaiseLimit = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "TerrainLowerLimit": settings.TerrainLowerLimit = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "UseEstateSun": settings.UseEstateSun = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "FixedSun": settings.FixedSun = Boolean.Parse(xtr.ReadElementContentAsString()); break; } } } return settings; }
public static void SaveRegionSettings(Simulator sim, string settingsPath) { if (Directory.Exists(settingsPath)) Directory.Delete(settingsPath, true); Thread.Sleep(100); Directory.CreateDirectory(settingsPath); Thread.Sleep(100); RegionSettings settings = new RegionSettings(); //settings.AgentLimit; settings.AllowDamage = (sim.Flags & RegionFlags.AllowDamage) == RegionFlags.AllowDamage; //settings.AllowLandJoinDivide; settings.AllowLandResell = (sim.Flags & RegionFlags.BlockLandResell) != RegionFlags.BlockLandResell; settings.BlockFly = (sim.Flags & RegionFlags.NoFly) == RegionFlags.NoFly; settings.BlockLandShowInSearch = (sim.Flags & RegionFlags.BlockParcelSearch) == RegionFlags.BlockParcelSearch; settings.BlockTerraform = (sim.Flags & RegionFlags.BlockTerraform) == RegionFlags.BlockTerraform; settings.DisableCollisions = (sim.Flags & RegionFlags.SkipCollisions) == RegionFlags.SkipCollisions; settings.DisablePhysics = (sim.Flags & RegionFlags.SkipPhysics) == RegionFlags.SkipPhysics; settings.DisableScripts = (sim.Flags & RegionFlags.SkipScripts) == RegionFlags.SkipScripts; settings.FixedSun = (sim.Flags & RegionFlags.SunFixed) == RegionFlags.SunFixed; settings.MaturityRating = (int)(sim.Access & SimAccess.Mature & SimAccess.Adult & SimAccess.PG); //settings.ObjectBonus; settings.RestrictPushing = (sim.Flags & RegionFlags.RestrictPushObject) == RegionFlags.RestrictPushObject; settings.TerrainDetail0 = sim.TerrainDetail0; settings.TerrainDetail1 = sim.TerrainDetail1; settings.TerrainDetail2 = sim.TerrainDetail2; settings.TerrainDetail3 = sim.TerrainDetail3; settings.TerrainHeightRange00 = sim.TerrainHeightRange00; settings.TerrainHeightRange01 = sim.TerrainHeightRange01; settings.TerrainHeightRange10 = sim.TerrainHeightRange10; settings.TerrainHeightRange11 = sim.TerrainHeightRange11; settings.TerrainStartHeight00 = sim.TerrainStartHeight00; settings.TerrainStartHeight01 = sim.TerrainStartHeight01; settings.TerrainStartHeight10 = sim.TerrainStartHeight10; settings.TerrainStartHeight11 = sim.TerrainStartHeight11; //settings.UseEstateSun; settings.WaterHeight = sim.WaterHeight; settings.ToXML(Path.Combine(settingsPath, sim.Name + ".xml")); }
public static RegionSettings FromStream(Stream stream) { RegionSettings settings = new RegionSettings(); System.Globalization.NumberFormatInfo nfi = Utils.EnUsCulture.NumberFormat; using (XmlTextReader xtr = new XmlTextReader(stream)) { xtr.ReadStartElement("RegionSettings"); xtr.ReadStartElement("General"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "AllowDamage": settings.AllowDamage = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AllowLandResell": settings.AllowLandResell = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AllowLandJoinDivide": settings.AllowLandJoinDivide = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockFly": settings.BlockFly = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockLandShowInSearch": settings.BlockLandShowInSearch = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "BlockTerraform": settings.BlockTerraform = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisableCollisions": settings.DisableCollisions = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisablePhysics": settings.DisablePhysics = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "DisableScripts": settings.DisableScripts = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "MaturityRating": settings.MaturityRating = Int32.Parse(xtr.ReadElementContentAsString()); break; case "RestrictPushing": settings.RestrictPushing = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "AgentLimit": settings.AgentLimit = Int32.Parse(xtr.ReadElementContentAsString()); break; case "ObjectBonus": settings.ObjectBonus = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; } } xtr.ReadEndElement(); xtr.ReadStartElement("GroundTextures"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "Texture1": settings.TerrainDetail0 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture2": settings.TerrainDetail1 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture3": settings.TerrainDetail2 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "Texture4": settings.TerrainDetail3 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "ElevationLowSW": settings.TerrainStartHeight00 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowNW": settings.TerrainStartHeight01 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowSE": settings.TerrainStartHeight10 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationLowNE": settings.TerrainStartHeight11 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighSW": settings.TerrainHeightRange00 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighNW": settings.TerrainHeightRange01 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighSE": settings.TerrainHeightRange10 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "ElevationHighNE": settings.TerrainHeightRange11 = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; } } xtr.ReadEndElement(); xtr.ReadStartElement("Terrain"); while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { switch (xtr.Name) { case "WaterHeight": settings.WaterHeight = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "TerrainRaiseLimit": settings.TerrainRaiseLimit = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "TerrainLowerLimit": settings.TerrainLowerLimit = Single.Parse(xtr.ReadElementContentAsString(), nfi); break; case "UseEstateSun": settings.UseEstateSun = Boolean.Parse(xtr.ReadElementContentAsString()); break; case "FixedSun": settings.FixedSun = Boolean.Parse(xtr.ReadElementContentAsString()); break; } } } return(settings); }