From 717fd3b5b91f54113ef554799f124275d5489ea1 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Wed, 3 Jun 2009 12:48:04 +0000 Subject: [PATCH] From: Chris Yeoh This patch adds oar file date and time (UTC) meta data to an oar file when it is created. It also adds a unique ID, though this id does not in anyway identify the machine that the oar file was created on. When an oar file with this meta data is loaded this extra information is saved with the region settings and available via LSL through: - osLoadedCreationDate() - osLoadedCreationTime() - osLoadedCreationID() If there is no meta data these fields will be blank. Subsequent oar file loads will erase the information for the previous oar file load. Persistence has only been implemented for MySQL, the other backends need updating. Overall this allows us to much more easily identify the specific version of software that clients are using. Its very straightforward to edit the oar file to change the ID string to be something more human friendly. Included in the patch is a new file OpenSim/Data/MySQL/Resources/030_RegionStore.sql required for the MySQL DB migration. btw I had a chat with justincc about this a few weeks ago since he wrote the oar file import/export and he sounded happy to accept something that included date/time information but didn't want anything that would silently leak private information like machine names. --- OpenSim/Data/MySQL/MySQLRegionData.cs | 26 ++++++++- .../Data/MySQL/Resources/030_RegionStore.sql | 7 +++ OpenSim/Framework/RegionSettings.cs | 24 ++++++++ .../World/Archiver/ArchiveReadRequest.cs | 58 +++++++++++++++++++ .../Archiver/ArchiveWriteRequestExecution.cs | 8 +++ .../Shared/Api/Implementation/OSSL_Api.cs | 25 ++++++++ .../Shared/Api/Interface/IOSSL_Api.cs | 5 ++ .../Shared/Api/Runtime/OSSL_Stub.cs | 17 ++++++ 8 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Data/MySQL/Resources/030_RegionStore.sql diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index 7038396e12..72c089ea0c 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -741,7 +741,8 @@ namespace OpenSim.Data.MySQL "terrain_raise_limit, terrain_lower_limit, " + "use_estate_sun, fixed_sun, sun_position, " + "covenant, Sandbox, sunvectorx, sunvectory, " + - "sunvectorz) values ( ?RegionUUID, ?BlockTerraform, " + + "sunvectorz, loaded_creation_date, loaded_creation_time, " + + "loaded_creation_id) values ( ?RegionUUID, ?BlockTerraform, " + "?BlockFly, ?AllowDamage, ?RestrictPushing, " + "?AllowLandResell, ?AllowLandJoinDivide, " + "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " + @@ -754,12 +755,14 @@ namespace OpenSim.Data.MySQL "?WaterHeight, ?TerrainRaiseLimit, " + "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " + "?SunPosition, ?Covenant, ?Sandbox, " + - "?SunVectorX, ?SunVectorY, ?SunVectorZ)"; + "?SunVectorX, ?SunVectorY, ?SunVectorZ, " + + "?LoadedCreationDate, ?LoadedCreationTime, ?LoadedCreationID)"; FillRegionSettingsCommand(cmd, rs); ExecuteNonQuery(cmd); cmd.Dispose(); + } } @@ -1039,6 +1042,21 @@ namespace OpenSim.Data.MySQL newSettings.SunPosition = Convert.ToDouble(row["sun_position"]); newSettings.Covenant = new UUID((String) row["covenant"]); + if (row["loaded_creation_date"] is DBNull) + newSettings.LoadedCreationDate = ""; + else + newSettings.LoadedCreationDate = (String) row["loaded_creation_date"]; + + if (row["loaded_creation_time"] is DBNull) + newSettings.LoadedCreationTime = ""; + else + newSettings.LoadedCreationTime = (String) row["loaded_creation_time"]; + + if (row["loaded_creation_id"] is DBNull) + newSettings.LoadedCreationID = ""; + else + newSettings.LoadedCreationID = (String) row["loaded_creation_id"]; + return newSettings; } @@ -1357,6 +1375,10 @@ namespace OpenSim.Data.MySQL cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun); cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition); cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString()); + cmd.Parameters.AddWithValue("LoadedCreationDate", settings.LoadedCreationDate); + cmd.Parameters.AddWithValue("LoadedCreationTime", settings.LoadedCreationTime); + cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID); + } /// diff --git a/OpenSim/Data/MySQL/Resources/030_RegionStore.sql b/OpenSim/Data/MySQL/Resources/030_RegionStore.sql new file mode 100644 index 0000000000..dfdcf6d710 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/030_RegionStore.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE regionsettings ADD COLUMN loaded_creation_date varchar(20) default NULL; +ALTER TABLE regionsettings ADD COLUMN loaded_creation_time varchar(20) default NULL; +ALTER TABLE regionsettings ADD COLUMN loaded_creation_id varchar(64) default NULL; + +COMMIT; diff --git a/OpenSim/Framework/RegionSettings.cs b/OpenSim/Framework/RegionSettings.cs index a47b91929b..c05cc1076a 100644 --- a/OpenSim/Framework/RegionSettings.cs +++ b/OpenSim/Framework/RegionSettings.cs @@ -560,5 +560,29 @@ namespace OpenSim.Framework get { return m_Covenant; } set { m_Covenant = value; } } + + private String m_LoadedCreationDate; + + public String LoadedCreationDate + { + get { return m_LoadedCreationDate; } + set { m_LoadedCreationDate = value; } + } + + private String m_LoadedCreationTime; + + public String LoadedCreationTime + { + get { return m_LoadedCreationTime; } + set { m_LoadedCreationTime = value; } + } + + private String m_LoadedCreationID; + public String LoadedCreationID + { + get { return m_LoadedCreationID; } + set { m_LoadedCreationID = value; } + } + } } diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index 74904e2e42..e26c145505 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -32,6 +32,7 @@ using System.IO.Compression; using System.Net; using System.Reflection; using System.Text; +using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -134,6 +135,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) { LoadRegionSettings(filePath, data); + } else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { + LoadArchiveMetadata(filePath, data); } } @@ -478,5 +481,60 @@ namespace OpenSim.Region.CoreModules.World.Archiver // return new BufferedStream(file, (int) response.ContentLength); return new BufferedStream(file, 1000000); } + + /// + /// Load oar file metadata + /// + /// + /// + /// + /// true if terrain was resolved successfully, false otherwise. + /// + private bool LoadArchiveMetadata(string terrainPath, byte[] data) + { + //Create the XmlNamespaceManager. + NameTable nt = new NameTable(); + XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); + + // Create the XmlParserContext. + XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); + + XmlTextReader xtr = new XmlTextReader(m_asciiEncoding.GetString(data), + XmlNodeType.Document, context); + + + RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings; + + // Loaded metadata will empty if no information exists in the archive + currentRegionSettings.LoadedCreationDate = ""; + currentRegionSettings.LoadedCreationTime = ""; + currentRegionSettings.LoadedCreationID = ""; + + while (xtr.Read()) + { + if (xtr.NodeType == XmlNodeType.Element) + { + if (xtr.Name.ToString()=="date") + { + currentRegionSettings.LoadedCreationDate = xtr.ReadElementContentAsString(); + } + else if (xtr.Name.ToString()=="time") + { + currentRegionSettings.LoadedCreationTime = xtr.ReadElementContentAsString(); + } + else if (xtr.Name.ToString()=="id") + { + currentRegionSettings.LoadedCreationID = xtr.ReadElementContentAsString(); + } + } + + } + currentRegionSettings.Save(); + + return true; + } + + + } } diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs index 05b51ed903..e9b24f4d66 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestExecution.cs @@ -154,7 +154,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver xtw.WriteStartElement("archive"); xtw.WriteAttributeString("major_version", "0"); xtw.WriteAttributeString("minor_version", "2"); + + xtw.WriteStartElement("creation_info"); + DateTime now = DateTime.UtcNow; + xtw.WriteElementString("date", now.ToLongDateString()); + xtw.WriteElementString("time", now.ToLongTimeString()); + xtw.WriteElementString("id", UUID.Random().ToString()); xtw.WriteEndElement(); + xtw.WriteEndElement(); + xtw.Flush(); xtw.Close(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index d759b77229..9b65d8d084 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -1709,5 +1709,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return result; } + + public string osLoadedCreationDate() + { + CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate"); + m_host.AddScriptLPS(1); + + return World.RegionInfo.RegionSettings.LoadedCreationDate; + } + + public string osLoadedCreationTime() + { + CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime"); + m_host.AddScriptLPS(1); + + return World.RegionInfo.RegionSettings.LoadedCreationTime; + } + + public string osLoadedCreationID() + { + CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID"); + m_host.AddScriptLPS(1); + + return World.RegionInfo.RegionSettings.LoadedCreationID; + } + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 548e11f98f..e337c6b9e7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -142,5 +142,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_String osFormatString(string str, LSL_List strings); LSL_List osMatchString(string src, string pattern, int start); + // Information about data loaded into the region + string osLoadedCreationDate(); + string osLoadedCreationTime(); + string osLoadedCreationID(); + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index a0d924d7f8..5df2d6eb6b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -371,6 +371,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osMatchString(src, pattern, start); } + // Information about data loaded into the region + public string osLoadedCreationDate() + { + return m_OSSL_Functions.osLoadedCreationDate(); + } + + public string osLoadedCreationTime() + { + return m_OSSL_Functions.osLoadedCreationTime(); + } + + public string osLoadedCreationID() + { + return m_OSSL_Functions.osLoadedCreationID(); + } + + public OSSLPrim Prim; [Serializable]