save/load environments to/from oars

master
UbitUmarov 2020-06-22 15:46:39 +01:00
parent 7b77609537
commit 8fe2cd6c46
13 changed files with 146 additions and 36 deletions

View File

@ -29,17 +29,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading;
using log4net; using log4net;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Data;
namespace OpenSim.Data.MySQL namespace OpenSim.Data.MySQL
{ {
@ -1510,9 +1506,7 @@ namespace OpenSim.Data.MySQL
{ {
try try
{ {
OSD oenv = OSDParser.Deserialize(env); ViewerEnvironment VEnv = ViewerEnvironment.FromOSDString(env);
ViewerEnvironment VEnv = new ViewerEnvironment();
VEnv.FromOSD(oenv);
newData.Environment = VEnv; newData.Environment = VEnv;
newData.EnvironmentVersion = VEnv.version; newData.EnvironmentVersion = VEnv.version;
} }
@ -1875,9 +1869,7 @@ namespace OpenSim.Data.MySQL
{ {
try try
{ {
OSD oenv = land.Environment.ToOSD(); cmd.Parameters.AddWithValue("environment", ViewerEnvironment.ToOSDString(land.Environment));
string env = OSDParser.SerializeLLSDNotationFull(oenv);
cmd.Parameters.AddWithValue("environment", env);
} }
catch catch
{ {

View File

@ -126,7 +126,7 @@ namespace OpenSim.Framework.Serialization
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga";
ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml"; ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml";
ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Settings] = ASSET_EXTENSION_SEPARATOR + "settings.bin"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Settings] = ASSET_EXTENSION_SEPARATOR + "settings.dat";
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart;
@ -148,7 +148,7 @@ namespace OpenSim.Framework.Serialization
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material;
EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "settings.bin"] = (sbyte)AssetType.Settings; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "settings.dat"] = (sbyte)AssetType.Settings;
} }
public static string CreateOarLandDataPath(LandData ld) public static string CreateOarLandDataPath(LandData ld)

View File

@ -28,12 +28,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Framework.Serialization.External namespace OpenSim.Framework.Serialization.External
{ {
@ -99,6 +97,9 @@ namespace OpenSim.Framework.Serialization.External
m_ldProcessors.Add( m_ldProcessors.Add(
"ParcelAccessList", ProcessParcelAccessList); "ParcelAccessList", ProcessParcelAccessList);
m_ldProcessors.Add(
"Environment", ProcessParcelEnvironment);
m_ldProcessors.Add( m_ldProcessors.Add(
"PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))); "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours")));
m_ldProcessors.Add( m_ldProcessors.Add(
@ -132,6 +133,13 @@ namespace OpenSim.Framework.Serialization.External
); );
m_laeProcessors.Add( m_laeProcessors.Add(
"AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList")));
}
public static void ProcessParcelEnvironment(LandData ld, XmlReader xtr)
{
string senv = xtr.ReadElementString("Environment");
ld.Environment = ViewerEnvironment.FromOSDString(senv);
} }
public static void ProcessParcelAccessList(LandData ld, XmlReader xtr) public static void ProcessParcelAccessList(LandData ld, XmlReader xtr)
@ -255,6 +263,15 @@ namespace OpenSim.Framework.Serialization.External
xtw.WriteElementString("Dwell", "0"); xtw.WriteElementString("Dwell", "0");
xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime)); xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime));
if(landData.Environment != null)
{
try
{
string senv = ViewerEnvironment.ToOSDString(landData.Environment);
xtw.WriteElementString("Environment", senv);
}
catch { }
}
xtw.WriteEndElement(); xtw.WriteEndElement();
xtw.Close(); xtw.Close();

View File

@ -46,9 +46,10 @@ namespace OpenSim.Framework.Serialization.External
/// <param name="serializedSettings"></param> /// <param name="serializedSettings"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="System.Xml.XmlException"></exception> /// <exception cref="System.Xml.XmlException"></exception>
public static RegionSettings Deserialize(byte[] serializedSettings) public static RegionSettings Deserialize(byte[] serializedSettings, out ViewerEnvironment regionEnv)
{ {
return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length)); // encoding is wrong. old oars seem to be on utf-16
return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length), out regionEnv);
} }
/// <summary> /// <summary>
@ -57,9 +58,10 @@ namespace OpenSim.Framework.Serialization.External
/// <param name="serializedSettings"></param> /// <param name="serializedSettings"></param>
/// <returns></returns> /// <returns></returns>
/// <exception cref="System.Xml.XmlException"></exception> /// <exception cref="System.Xml.XmlException"></exception>
public static RegionSettings Deserialize(string serializedSettings) public static RegionSettings Deserialize(string serializedSettings, out ViewerEnvironment regionEnv)
{ {
RegionSettings settings = new RegionSettings(); RegionSettings settings = new RegionSettings();
regionEnv = null;
StringReader sr = new StringReader(serializedSettings); StringReader sr = new StringReader(serializedSettings);
XmlTextReader xtr = new XmlTextReader(sr); XmlTextReader xtr = new XmlTextReader(sr);
@ -210,13 +212,28 @@ namespace OpenSim.Framework.Serialization.External
} }
} }
if (xtr.IsStartElement("Environment"))
{
xtr.ReadStartElement("Environment");
while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
{
switch (xtr.Name)
{
case "data":
regionEnv = ViewerEnvironment.FromOSDString(xtr.ReadElementContentAsString());
break;
}
}
}
xtr.Close(); xtr.Close();
sr.Close(); sr.Close();
return settings; return settings;
} }
public static string Serialize(RegionSettings settings) public static string Serialize(RegionSettings settings, ViewerEnvironment RegionEnv)
{ {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw); XmlTextWriter xtw = new XmlTextWriter(sw);
@ -263,8 +280,6 @@ namespace OpenSim.Framework.Serialization.External
xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString()); xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString());
xtw.WriteElementString("FixedSun", settings.FixedSun.ToString()); xtw.WriteElementString("FixedSun", settings.FixedSun.ToString());
xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); 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.WriteStartElement("Telehub"); xtw.WriteStartElement("Telehub");
@ -276,6 +291,13 @@ namespace OpenSim.Framework.Serialization.External
} }
xtw.WriteEndElement(); xtw.WriteEndElement();
if (RegionEnv != null)
{
xtw.WriteStartElement("Environment");
xtw.WriteElementString("data", ViewerEnvironment.ToOSDString(RegionEnv));
xtw.WriteEndElement();
}
xtw.WriteEndElement(); xtw.WriteEndElement();
xtw.Close(); xtw.Close();

View File

@ -130,7 +130,7 @@ namespace OpenSim.Framework.Serialization.Tests
TestHelpers.InMethod(); TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure(); // log4net.Config.XmlConfigurator.Configure();
RegionSettings deserRs = RegionSettingsSerializer.Deserialize(m_serializedRs); RegionSettings deserRs = RegionSettingsSerializer.Deserialize(m_serializedRs, out ViewerEnvironment dummy);
Assert.That(deserRs, Is.Not.Null); Assert.That(deserRs, Is.Not.Null);
Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2)); Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2));
Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics)); Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics));

View File

@ -3381,6 +3381,14 @@ namespace OpenSim.Framework
return ticks * TimeStampClockPeriodMS; return ticks * TimeStampClockPeriodMS;
} }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static void AddToGatheredIds(Dictionary<UUID, sbyte> uuids, UUID id, sbyte type)
{
if (id == UUID.Zero)
return;
uuids[id] = type;
}
/// <summary> /// <summary>
/// Formats a duration (given in milliseconds). /// Formats a duration (given in milliseconds).
/// </summary> /// </summary>
@ -3976,7 +3984,5 @@ namespace OpenSim.Framework
{ {
rng.GetBytes(buff); rng.GetBytes(buff);
} }
} }
} }

View File

@ -484,6 +484,16 @@ namespace OpenSim.Framework
sunlight_color = otmp; sunlight_color = otmp;
Name = name; Name = name;
} }
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
{
Util.AddToGatheredIds(uuids, bloom_id, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, cloud_id, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, halo_id, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, moon_id, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, rainbow_id, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, sun_id, (sbyte)AssetType.Texture);
}
} }
public class WaterData public class WaterData
@ -599,6 +609,12 @@ namespace OpenSim.Framework
return map; return map;
} }
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
{
Util.AddToGatheredIds(uuids, normalMap, (sbyte)AssetType.Texture);
Util.AddToGatheredIds(uuids, transpTexture, (sbyte)AssetType.Texture);
}
} }
public class DayCycle public class DayCycle
@ -889,6 +905,18 @@ namespace OpenSim.Framework
return cycle; return cycle;
} }
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
{
foreach (WaterData wd in waterframes.Values)
{
wd.GatherAssets(uuids);
}
foreach (SkyData sd in skyframes.Values)
{
sd.GatherAssets(uuids);
}
}
} }
public class ViewerEnvironment public class ViewerEnvironment
@ -1216,6 +1244,35 @@ namespace OpenSim.Framework
return env; return env;
} }
public static ViewerEnvironment FromOSDString(string s)
{
try
{
OSD eosd = OSDParser.Deserialize(s);
ViewerEnvironment VEnv = new ViewerEnvironment();
VEnv.FromOSD(eosd);
return VEnv;
}
catch
{
}
return null;
}
public static string ToOSDString(ViewerEnvironment VEnv, bool xml = false)
{
try
{
OSD eosd= VEnv.ToOSD();
if(xml)
return OSDParser.SerializeLLSDXmlString(eosd);
else
return OSDParser.SerializeLLSDNotationFull(eosd);
}
catch {}
return String.Empty;
}
public ViewerEnvironment Clone() public ViewerEnvironment Clone()
{ {
// im lazy need to proper clone later // im lazy need to proper clone later
@ -1398,5 +1455,11 @@ namespace OpenSim.Framework
return true; return true;
} }
*/ */
public void GatherAssets(Dictionary<UUID, sbyte> uuids)
{
if (Cycle != null)
Cycle.GatherAssets(uuids);
}
} }
} }

View File

@ -285,14 +285,13 @@ namespace OpenSim.Framework
if (tickdiff > LongCallTime) if (tickdiff > LongCallTime)
{ {
m_log.InfoFormat( m_log.InfoFormat(
"[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {7} bytes ({8} uncomp): {9}", "[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4} bytes ({5} uncomp): {6}",
reqnum, reqnum,
method, method,
url, url,
tickdiff, tickdiff,
compsize, compsize,
strBuffer != null ? strBuffer.Length : 0, strBuffer != null ? strBuffer.Length : 0,
strBuffer != null strBuffer != null
? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
: ""); : "");

View File

@ -1039,10 +1039,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes) private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes)
{ {
RegionSettings loadedRegionSettings; RegionSettings loadedRegionSettings;
ViewerEnvironment regionEnv = null;
try try
{ {
loadedRegionSettings = RegionSettingsSerializer.Deserialize(data); loadedRegionSettings = RegionSettingsSerializer.Deserialize(data, out regionEnv);
} }
catch (Exception e) catch (Exception e)
{ {
@ -1051,7 +1051,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
settingsPath, e); settingsPath, e);
return false; return false;
} }
scene.RegionEnvironment = regionEnv;
RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings; RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings;
currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit; currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit;

View File

@ -321,6 +321,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4) if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
assetUuids[regionSettings.TerrainTexture4] = (sbyte)AssetType.Texture; assetUuids[regionSettings.TerrainTexture4] = (sbyte)AssetType.Texture;
if(scene.RegionEnvironment != null)
scene.RegionEnvironment.GatherAssets(assetUuids);
List<ILandObject> landObjects = scene.LandChannel.AllParcels();
foreach (ILandObject lo in landObjects)
{
if(lo.LandData != null && lo.LandData.Environment != null)
lo.LandData.Environment.GatherAssets(assetUuids);
}
Save(scene, sceneObjects, regionDir); Save(scene, sceneObjects, regionDir);
GC.Collect(); GC.Collect();
} }
@ -572,7 +582,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
// Write out region settings // Write out region settings
string settingsPath = String.Format("{0}{1}{2}.xml", string settingsPath = String.Format("{0}{1}{2}.xml",
regionDir, ArchiveConstants.SETTINGS_PATH, scene.RegionInfo.RegionName); regionDir, ArchiveConstants.SETTINGS_PATH, scene.RegionInfo.RegionName);
m_archiveWriter.WriteFile(settingsPath, RegionSettingsSerializer.Serialize(scene.RegionInfo.RegionSettings)); m_archiveWriter.WriteFile(settingsPath, RegionSettingsSerializer.Serialize(scene.RegionInfo.RegionSettings, scene.RegionEnvironment));
m_log.InfoFormat("[ARCHIVER]: Adding parcel settings to archive."); m_log.InfoFormat("[ARCHIVER]: Adding parcel settings to archive.");

View File

@ -657,7 +657,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111"); rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111");
rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33")); rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33"));
tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs)); tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs, null));
tar.Close(); tar.Close();

View File

@ -837,6 +837,7 @@ namespace OpenSim.Region.CoreModules.World.LightShare
return OSDParser.SerializeLLSDNotationToBytes(osddata,true); return OSDParser.SerializeLLSDNotationToBytes(osddata,true);
} }
public List<byte[]> MakeLightShareData() public List<byte[]> MakeLightShareData()
{ {
if(m_scene.RegionEnvironment == null) if(m_scene.RegionEnvironment == null)

View File

@ -66,10 +66,10 @@ namespace OpenSim.Server.Handlers.Authentication
m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userService, args); m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userService, args);
// Handler for OpenID user identity pages // Handler for OpenID user identity pages
server.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", m_UserAccountService, m_AuthenticationService)); server.AddStreamHandler(new OpenIdStreamHandler("GET", "/users", m_UserAccountService, m_AuthenticationService));
// Handlers for the OpenID endpoint server // Handlers for the OpenID endpoint server
server.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", m_UserAccountService, m_AuthenticationService)); server.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server", m_UserAccountService, m_AuthenticationService));
server.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", m_UserAccountService, m_AuthenticationService)); server.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server", m_UserAccountService, m_AuthenticationService));
m_log.Info("[OPENID]: OpenId service enabled"); m_log.Info("[OPENID]: OpenId service enabled");
} }