From 3707301c59bb5d8c6a854da9f65e3799bbb6c783 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 28 Feb 2020 18:36:52 +0000 Subject: [PATCH] changes to load oar with --merge: with option --mergeReplaceObjects it will replace objects already in region, without it, skip; with opetion merge-parcels will try to merge them, without it ignores oar parcels. as before without --merge all is replaced. renamed the options force* as merge* since they are merge suboptions --- OpenSim/Region/Application/OpenSim.cs | 10 +- .../World/Archiver/ArchiveReadRequest.cs | 92 ++++++++++++------- .../World/Archiver/ArchiverModule.cs | 23 +++-- 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 786a41c406..044a672597 100755 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -317,7 +317,8 @@ namespace OpenSim m_console.Commands.AddCommand("Archiving", false, "load oar", "load oar [-m|--merge] [-s|--skip-assets]" + " [--default-user \"User Name\"]" - + " [--force-terrain] [--force-parcels]" + + " [--merge-terrain] [--merge-parcels]" + + " [--mergeReplaceObjects]" + " [--no-objects]" + " [--rotation degrees]" + " [--bounding-origin \"\"]" @@ -327,10 +328,13 @@ namespace OpenSim + " []", "Load a region's data from an OAR archive.", "--merge will merge the OAR with the existing scene (suppresses terrain and parcel info loading).\n" + + " options with --merge\n" + + " --merge-terrain also load the terrain, replacing original\n" + + " --merge-parcels also load parcels, merging with original\n" + + " --mergeReplaceObjects if scene as a object with same id, replace it\n" + + " without this option, skip loading that object\n" + "--skip-assets will load the OAR but ignore the assets it contains.\n" + "--default-user will use this user for any objects with an owner whose UUID is not found in the grid.\n" - + "--force-terrain forces the loading of terrain from the oar (undoes suppression done by --merge).\n" - + "--force-parcels forces the loading of parcels from the oar (undoes suppression done by --merge).\n" + "--no-objects suppresses the addition of any objects (good for loading only the terrain).\n" + "--rotation specified rotation to be applied to the oar. Specified in degrees.\n" + "--bounding-origin will only place objects that after displacement and rotation fall within the bounding cube who's position starts at . Defaults to <0,0,0>.\n" diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index e5c9841833..f1ffd3b55a 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -101,16 +101,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// Merging usually suppresses terrain and parcel loading /// protected bool m_merge; + protected bool m_mergeReplaceObjects; /// /// If true, force the loading of terrain from the oar file /// - protected bool m_forceTerrain; + protected bool m_mergeTerrain; /// - /// If true, force the loading of parcels from the oar file + /// If true, force the merge of parcels from the oar file /// - protected bool m_forceParcels; + protected bool m_mergeParcels; /// /// Should we ignore any assets when reloading the archive? @@ -210,8 +211,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_errorMessage = String.Empty; m_merge = options.ContainsKey("merge"); - m_forceTerrain = options.ContainsKey("force-terrain"); - m_forceParcels = options.ContainsKey("force-parcels"); + m_mergeReplaceObjects = options.ContainsKey("mReplaceObjects"); + m_mergeTerrain = options.ContainsKey("merge-terrain"); + m_mergeParcels = options.ContainsKey("merge-parcels"); m_noObjects = options.ContainsKey("no-objects"); m_skipAssets = options.ContainsKey("skipAssets"); m_requestId = requestId; @@ -270,6 +272,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_loadStream = loadStream; m_skipAssets = options.ContainsKey("skipAssets"); m_merge = options.ContainsKey("merge"); + m_mergeReplaceObjects = options.ContainsKey("mReplaceObjects"); m_requestId = requestId; m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner; @@ -352,7 +355,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); } - else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain)) + else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_mergeTerrain)) { LoadTerrain(scene, filePath, data); } @@ -360,7 +363,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { LoadRegionSettings(scene, filePath, data, dearchivedScenes); } - else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels)) + else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_mergeParcels)) { sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); } @@ -546,23 +549,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver int sceneObjectsLoadedCount = 0; Vector3 boundingExtent = new Vector3(m_boundingOrigin.X + m_boundingSize.X, m_boundingOrigin.Y + m_boundingSize.Y, m_boundingOrigin.Z + m_boundingSize.Z); + int mergeskip = 0; foreach (string serialisedSceneObject in serialisedSceneObjects) { - /* - m_log.DebugFormat("[ARCHIVER]: Loading xml with raw size {0}", serialisedSceneObject.Length); - - // Really large xml files (multi megabyte) appear to cause - // memory problems - // when loading the xml. But don't enable this check yet - - if (serialisedSceneObject.Length > 5000000) - { - m_log.Error("[ARCHIVER]: Ignoring xml since size > 5000000);"); - continue; - } - */ - SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject); + if (m_merge) + { + if(scene.TryGetSceneObjectGroup(sceneObject.UUID, out SceneObjectGroup oldSog)) + { + ++mergeskip; + if (m_mergeReplaceObjects) + scene.DeleteSceneObject(oldSog, false); + else + continue; + } + } Vector3 pos = sceneObject.AbsolutePosition; if (m_debug) @@ -636,12 +637,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver } } - m_log.InfoFormat("[ARCHIVER]: Restored {0} scene objects to the scene", sceneObjectsLoadedCount); - - int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount; + m_log.InfoFormat("[ARCHIVER]: Loaded {0} scene objects to the scene", sceneObjectsLoadedCount); + int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount - mergeskip; + if(mergeskip > 0) + { + if(m_mergeReplaceObjects) + m_log.InfoFormat("[ARCHIVER]: Replaced {0} scene objects", mergeskip); + else + m_log.InfoFormat("[ARCHIVER]: Skipped {0} scene objects that already existed in the scene", mergeskip); + } if (ignoredObjects > 0) - m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene or were out of bounds", ignoredObjects); + m_log.WarnFormat("[ARCHIVER]: Ignored {0} possible out of bounds", ignoredObjects); if (oldTelehubUUID != UUID.Zero) { @@ -730,6 +737,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// protected void LoadParcels(Scene scene, List serialisedParcels) { + if(serialisedParcels.Count == 0) + { + m_log.Info("[ARCHIVER]: No parcels to load, or skiping load"); + return; + } + // Reload serialized parcels m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count); List landData = new List(); @@ -743,6 +756,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver // Gather any existing parcels before we add any more. Later as we add parcels we can check if the new parcel // data overlays any of the old data, and we can modify and remove (if empty) the old parcel so that there's no conflict + bool domerge = m_merge & m_mergeParcels; + parcels = scene.LandChannel.AllParcels(); foreach (string serialisedParcel in serialisedParcels) @@ -787,7 +802,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver parcel.AABBMin = AABBMin; parcel.AABBMax = AABBMax; - if (m_merge) + if (domerge) { // give the remapped parcel a new GlobalID, in case we're using the same OAR twice and a bounding cube, displacement and --merge parcel.GlobalID = UUID.Random(); @@ -854,19 +869,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver landData.Add(parcel); } - if (m_merge) - { - for (int i = 0; i < parcels.Count; i++) //if merging then we need to also add back in any existing parcels - { - if (parcels[i] != null) landData.Add(parcels[i].LandData); - } - } - m_log.InfoFormat("[ARCHIVER]: Clearing {0} parcels.", parcels.Count); bool setupDefaultParcel = (landData.Count == 0); scene.LandChannel.Clear(setupDefaultParcel); + + if (domerge) + { + int j = 0; + for (int i = 0; i < parcels.Count; i++) //if merging then we need to also add back in any existing parcels + { + if (parcels[i] != null) + { + landData.Add(parcels[i].LandData); + j++; + } + } + m_log.InfoFormat("[ARCHIVER]: Keeping {0} old parcels.", j); + } + scene.EventManager.TriggerIncomingLandDataFromStorage(landData); - m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count); + m_log.InfoFormat("[ARCHIVER]: Added {0} total parcels.", landData.Count); } /// diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs index 1305545dbf..8ad861d9f0 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiverModule.cs @@ -101,9 +101,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver public void HandleLoadOarConsoleCommand(string module, string[] cmdparams) { bool mergeOar = false; + bool mergeReplaceObjects = false; bool skipAssets = false; - bool forceTerrain = false; - bool forceParcels = false; + bool mergeTerrain = false; + bool mergeParcels = false; bool noObjects = false; Vector3 displacement = new Vector3(0f, 0f, 0f); String defaultUser = ""; @@ -112,14 +113,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver Vector3 boundingOrigin = new Vector3(0f, 0f, 0f); Vector3 boundingSize = new Vector3(Scene.RegionInfo.RegionSizeX, Scene.RegionInfo.RegionSizeY, float.MaxValue); bool debug = false; - + OptionSet options = new OptionSet(); options.Add("m|merge", delegate(string v) { mergeOar = (v != null); }); + options.Add("mergeReplaceObjects", delegate (string v) { mergeReplaceObjects = (v != null); }); options.Add("s|skip-assets", delegate(string v) { skipAssets = (v != null); }); - options.Add("force-terrain", delegate(string v) { forceTerrain = (v != null); }); - options.Add("forceterrain", delegate(string v) { forceTerrain = (v != null); }); // downward compatibility - options.Add("force-parcels", delegate(string v) { forceParcels = (v != null); }); - options.Add("forceparcels", delegate(string v) { forceParcels = (v != null); }); // downward compatibility + options.Add("merge-terrain", delegate(string v) { mergeTerrain = (v != null); }); + options.Add("force-terrain", delegate (string v) { mergeTerrain = (v != null); }); // downward compatibility + options.Add("forceterrain", delegate (string v) { mergeTerrain = (v != null); }); // downward compatibility + options.Add("merge-parcels", delegate(string v) { mergeParcels = (v != null); }); + options.Add("force-parcels", delegate (string v) { mergeParcels = (v != null); }); // downward compatibility + options.Add("forceparcels", delegate (string v) { mergeParcels = (v != null); }); // downward compatibility options.Add("no-objects", delegate(string v) { noObjects = (v != null); }); options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; }); options.Add("displacement=", delegate(string v) @@ -212,8 +216,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver Dictionary archiveOptions = new Dictionary(); if (mergeOar) archiveOptions.Add("merge", null); if (skipAssets) archiveOptions.Add("skipAssets", null); - if (forceTerrain) archiveOptions.Add("force-terrain", null); - if (forceParcels) archiveOptions.Add("force-parcels", null); + if (mergeReplaceObjects) archiveOptions.Add("mReplaceObjects", null); + if (mergeTerrain) archiveOptions.Add("merge-terrain", null); + if (mergeParcels) archiveOptions.Add("merge-parcels", null); if (noObjects) archiveOptions.Add("no-objects", null); if (defaultUser != "") {