aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs')
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs289
1 files changed, 199 insertions, 90 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index efc4998..5d41125 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -100,10 +100,37 @@ namespace OpenSim.Region.CoreModules.World.Archiver
100 protected bool m_merge; 100 protected bool m_merge;
101 101
102 /// <value> 102 /// <value>
103 /// If true, force the loading of terrain from the oar file
104 /// </value>
105 protected bool m_forceTerrain;
106
107 /// <value>
108 /// If true, force the loading of parcels from the oar file
109 /// </value>
110 protected bool m_forceParcels;
111
112 /// <value>
103 /// Should we ignore any assets when reloading the archive? 113 /// Should we ignore any assets when reloading the archive?
104 /// </value> 114 /// </value>
105 protected bool m_skipAssets; 115 protected bool m_skipAssets;
106 116
117 /// <value>
118 /// Displacement added to each object as it is added to the world
119 /// </value>
120 protected Vector3 m_displacement = Vector3.Zero;
121
122 /// <value>
123 /// Rotation (in radians) to apply to the objects as they are loaded.
124 /// </value>
125 protected float m_rotation = 0f;
126
127 /// <value>
128 /// Center around which to apply the rotation relative to the origional oar position
129 /// </value>
130 protected Vector3 m_rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0f);
131
132 protected bool m_noObjects = false;
133
107 /// <summary> 134 /// <summary>
108 /// Used to cache lookups for valid uuids. 135 /// Used to cache lookups for valid uuids.
109 /// </summary> 136 /// </summary>
@@ -131,11 +158,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver
131 158
132 private IAssetService m_assetService = null; 159 private IAssetService m_assetService = null;
133 160
161 private UUID m_defaultUser;
134 162
135 public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId) 163 public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string, object> options)
136 { 164 {
137 m_rootScene = scene; 165 m_rootScene = scene;
138 166
167 if (options.ContainsKey("default-user"))
168 {
169 m_defaultUser = (UUID)options["default-user"];
170 m_log.InfoFormat("Using User {0} as default user", m_defaultUser.ToString());
171 }
172 else
173 {
174 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
175 }
176
139 m_loadPath = loadPath; 177 m_loadPath = loadPath;
140 try 178 try
141 { 179 {
@@ -148,28 +186,42 @@ namespace OpenSim.Region.CoreModules.World.Archiver
148 + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); 186 + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
149 m_log.Error(e); 187 m_log.Error(e);
150 } 188 }
151 189
152 m_errorMessage = String.Empty; 190 m_errorMessage = String.Empty;
153 m_merge = merge; 191
154 m_skipAssets = skipAssets; 192 m_merge = options.ContainsKey("merge");
193 m_forceTerrain = options.ContainsKey("force-terrain");
194 m_forceParcels = options.ContainsKey("force-parcels");
195 m_noObjects = options.ContainsKey("no-objects");
196 m_skipAssets = options.ContainsKey("skipAssets");
155 m_requestId = requestId; 197 m_requestId = requestId;
198 m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero;
199 m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f;
200 m_rotationCenter = options.ContainsKey("rotation-center") ? (Vector3)options["rotation-center"]
201 : new Vector3(scene.RegionInfo.RegionSizeX / 2f, scene.RegionInfo.RegionSizeY / 2f, 0f);
156 202
157 // Zero can never be a valid user id 203 m_requestId = requestId;
204
205 // Zero can never be a valid user id (or group)
158 m_validUserUuids[UUID.Zero] = false; 206 m_validUserUuids[UUID.Zero] = false;
207 m_validGroupUuids[UUID.Zero] = false;
208
159 209
160 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>(); 210 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
161 m_assetService = m_rootScene.AssetService; 211 m_assetService = m_rootScene.AssetService;
162 } 212 }
163 213
164 public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId) 214 public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object> options)
165 { 215 {
166 m_rootScene = scene; 216 m_rootScene = scene;
167 m_loadPath = null; 217 m_loadPath = null;
168 m_loadStream = loadStream; 218 m_loadStream = loadStream;
169 m_merge = merge; 219 m_skipAssets = options.ContainsKey("skipAssets");
170 m_skipAssets = skipAssets; 220 m_merge = options.ContainsKey("merge");
171 m_requestId = requestId; 221 m_requestId = requestId;
172 222
223 m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
224
173 // Zero can never be a valid user id 225 // Zero can never be a valid user id
174 m_validUserUuids[UUID.Zero] = false; 226 m_validUserUuids[UUID.Zero] = false;
175 227
@@ -229,7 +281,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
229 281
230 // Process the file 282 // Process the file
231 283
232 if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) 284 if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH) && !m_noObjects)
233 { 285 {
234 sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data)); 286 sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
235 } 287 }
@@ -243,15 +295,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
243 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) 295 if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
244 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); 296 m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
245 } 297 }
246 else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH)) 298 else if ((!m_merge || m_forceTerrain) && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
247 { 299 {
248 LoadTerrain(scene, filePath, data); 300 LoadTerrain(scene, filePath, data);
249 } 301 }
250 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) 302 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
251 { 303 {
252 LoadRegionSettings(scene, filePath, data, dearchivedScenes); 304 LoadRegionSettings(scene, filePath, data, dearchivedScenes);
253 } 305 }
254 else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH)) 306 else if ((!m_merge || m_forceParcels) && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
255 { 307 {
256 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); 308 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data));
257 } 309 }
@@ -422,6 +474,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
422 // Reload serialized prims 474 // Reload serialized prims
423 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); 475 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
424 476
477 OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, m_rotation);
478
425 UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject; 479 UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject;
426 480
427 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>(); 481 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>();
@@ -445,6 +499,31 @@ namespace OpenSim.Region.CoreModules.World.Archiver
445 499
446 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject); 500 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
447 501
502 // Happily this does not do much to the object since it hasn't been added to the scene yet
503 if (!sceneObject.IsAttachment)
504 {
505 if (m_displacement != Vector3.Zero || m_rotation != 0f)
506 {
507 Vector3 pos = sceneObject.AbsolutePosition;
508 if (m_rotation != 0f)
509 {
510 // Rotate the object
511 sceneObject.RootPart.RotationOffset = rot * sceneObject.GroupRotation;
512 // Get object position relative to rotation axis
513 Vector3 offset = pos - m_rotationCenter;
514 // Rotate the object position
515 offset *= rot;
516 // Restore the object position back to relative to the region
517 pos = m_rotationCenter + offset;
518 }
519 if (m_displacement != Vector3.Zero)
520 {
521 pos += m_displacement;
522 }
523 sceneObject.AbsolutePosition = pos;
524 }
525 }
526
448 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero); 527 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero);
449 528
450 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned 529 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
@@ -460,76 +539,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
460 oldTelehubUUID = UUID.Zero; 539 oldTelehubUUID = UUID.Zero;
461 } 540 }
462 541
463 // Try to retain the original creator/owner/lastowner if their uuid is present on this grid 542 ModifySceneObject(scene, sceneObject);
464 // or creator data is present. Otherwise, use the estate owner instead.
465 foreach (SceneObjectPart part in sceneObject.Parts)
466 {
467 if (string.IsNullOrEmpty(part.CreatorData))
468 {
469 if (!ResolveUserUuid(scene, part.CreatorID))
470 part.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner;
471 }
472 if (UserManager != null)
473 UserManager.AddUser(part.CreatorID, part.CreatorData);
474
475 if (!ResolveUserUuid(scene, part.OwnerID))
476 part.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
477 543
478 if (!ResolveUserUuid(scene, part.LastOwnerID))
479 part.LastOwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
480
481 if (!ResolveGroupUuid(part.GroupID))
482 part.GroupID = UUID.Zero;
483
484 // And zap any troublesome sit target information
485// part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
486// part.SitTargetPosition = new Vector3(0, 0, 0);
487
488 // Fix ownership/creator of inventory items
489 // Not doing so results in inventory items
490 // being no copy/no mod for everyone
491 lock (part.TaskInventory)
492 {
493 if (!ResolveUserUuid(scene, part.CreatorID))
494 part.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner;
495
496 if (!ResolveUserUuid(scene, part.OwnerID))
497 part.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
498
499 if (!ResolveUserUuid(scene, part.LastOwnerID))
500 part.LastOwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
501
502 // And zap any troublesome sit target information
503 part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
504 part.SitTargetPosition = new Vector3(0, 0, 0);
505
506 // Fix ownership/creator of inventory items
507 // Not doing so results in inventory items
508 // being no copy/no mod for everyone
509 part.TaskInventory.LockItemsForRead(true);
510 TaskInventoryDictionary inv = part.TaskInventory;
511 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
512 {
513 if (!ResolveUserUuid(scene, kvp.Value.OwnerID))
514 {
515 kvp.Value.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
516 }
517
518 if (string.IsNullOrEmpty(kvp.Value.CreatorData))
519 {
520 if (!ResolveUserUuid(scene, kvp.Value.CreatorID))
521 kvp.Value.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner;
522 }
523
524 if (UserManager != null)
525 UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
526
527 if (!ResolveGroupUuid(kvp.Value.GroupID))
528 kvp.Value.GroupID = UUID.Zero;
529 }
530 part.TaskInventory.LockItemsForRead(false);
531 }
532 }
533 544
534 if (scene.AddRestoredSceneObject(sceneObject, true, false)) 545 if (scene.AddRestoredSceneObject(sceneObject, true, false))
535 { 546 {
@@ -553,7 +564,76 @@ namespace OpenSim.Region.CoreModules.World.Archiver
553 scene.RegionInfo.RegionSettings.ClearSpawnPoints(); 564 scene.RegionInfo.RegionSettings.ClearSpawnPoints();
554 } 565 }
555 } 566 }
556 567
568 /// <summary>
569 /// Optionally modify a loaded SceneObjectGroup. Currently this just ensures that the
570 /// User IDs and Group IDs are valid, but other manipulations could be done as well.
571 /// </summary>
572 private void ModifySceneObject(Scene scene, SceneObjectGroup sceneObject)
573 {
574 // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
575 // or creator data is present. Otherwise, use the estate owner instead.
576 foreach (SceneObjectPart part in sceneObject.Parts)
577 {
578 if (string.IsNullOrEmpty(part.CreatorData))
579 {
580 if (!ResolveUserUuid(scene, part.CreatorID))
581 part.CreatorID = m_defaultUser;
582 }
583 if (UserManager != null)
584 UserManager.AddUser(part.CreatorID, part.CreatorData);
585
586 if (!(ResolveUserUuid(scene, part.OwnerID) || ResolveGroupUuid(part.OwnerID)))
587 part.OwnerID = m_defaultUser;
588
589 if (!(ResolveUserUuid(scene, part.LastOwnerID) || ResolveGroupUuid(part.LastOwnerID)))
590 part.LastOwnerID = m_defaultUser;
591
592 if (!ResolveGroupUuid(part.GroupID))
593 part.GroupID = UUID.Zero;
594
595 // And zap any troublesome sit target information
596 // part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
597 // part.SitTargetPosition = new Vector3(0, 0, 0);
598
599 // Fix ownership/creator of inventory items
600 // Not doing so results in inventory items
601 // being no copy/no mod for everyone
602 lock (part.TaskInventory)
603 {
604 // And zap any troublesome sit target information
605 part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
606 part.SitTargetPosition = new Vector3(0, 0, 0);
607
608 // Fix ownership/creator of inventory items
609 // Not doing so results in inventory items
610 // being no copy/no mod for everyone
611 part.TaskInventory.LockItemsForRead(true);
612 TaskInventoryDictionary inv = part.TaskInventory;
613 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
614 {
615 if (!(ResolveUserUuid(scene, kvp.Value.OwnerID) || ResolveGroupUuid(kvp.Value.OwnerID)))
616 {
617 kvp.Value.OwnerID = m_defaultUser;
618 }
619
620 if (string.IsNullOrEmpty(kvp.Value.CreatorData))
621 {
622 if (!ResolveUserUuid(scene, kvp.Value.CreatorID))
623 kvp.Value.CreatorID = m_defaultUser;
624 }
625
626 if (UserManager != null)
627 UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
628
629 if (!ResolveGroupUuid(kvp.Value.GroupID))
630 kvp.Value.GroupID = UUID.Zero;
631 }
632 part.TaskInventory.LockItemsForRead(false);
633 }
634 }
635 }
636
557 /// <summary> 637 /// <summary>
558 /// Load serialized parcels. 638 /// Load serialized parcels.
559 /// </summary> 639 /// </summary>
@@ -567,14 +647,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver
567 foreach (string serialisedParcel in serialisedParcels) 647 foreach (string serialisedParcel in serialisedParcels)
568 { 648 {
569 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); 649 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
570 650
651 if (m_displacement != Vector3.Zero)
652 {
653 Vector3 parcelDisp = new Vector3(m_displacement.X, m_displacement.Y, 0f);
654 parcel.AABBMin += parcelDisp;
655 parcel.AABBMax += parcelDisp;
656 }
657
571 // Validate User and Group UUID's 658 // Validate User and Group UUID's
572 659
573 if (parcel.IsGroupOwned) 660 if (parcel.IsGroupOwned)
574 { 661 {
575 if (!ResolveGroupUuid(parcel.GroupID)) 662 if (!ResolveGroupUuid(parcel.GroupID))
576 { 663 {
577 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; 664 parcel.OwnerID = m_defaultUser;
578 parcel.GroupID = UUID.Zero; 665 parcel.GroupID = UUID.Zero;
579 parcel.IsGroupOwned = false; 666 parcel.IsGroupOwned = false;
580 } 667 }
@@ -582,7 +669,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
582 else 669 else
583 { 670 {
584 if (!ResolveUserUuid(scene, parcel.OwnerID)) 671 if (!ResolveUserUuid(scene, parcel.OwnerID))
585 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; 672 parcel.OwnerID = m_defaultUser;
586 673
587 if (!ResolveGroupUuid(parcel.GroupID)) 674 if (!ResolveGroupUuid(parcel.GroupID))
588 parcel.GroupID = UUID.Zero; 675 parcel.GroupID = UUID.Zero;
@@ -702,8 +789,21 @@ namespace OpenSim.Region.CoreModules.World.Archiver
702 sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; 789 sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
703 790
704 if (assetType == (sbyte)AssetType.Unknown) 791 if (assetType == (sbyte)AssetType.Unknown)
792 {
705 m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid); 793 m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
706 794 }
795 else if (assetType == (sbyte)AssetType.Object)
796 {
797 data = SceneObjectSerializer.ModifySerializedObject(UUID.Parse(uuid), data,
798 sog =>
799 {
800 ModifySceneObject(m_rootScene, sog);
801 return true;
802 });
803
804 if (data == null)
805 return false;
806 }
707 //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); 807 //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
708 808
709 AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString()); 809 AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString());
@@ -825,10 +925,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver
825 private bool LoadTerrain(Scene scene, string terrainPath, byte[] data) 925 private bool LoadTerrain(Scene scene, string terrainPath, byte[] data)
826 { 926 {
827 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); 927 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
828 928
829 MemoryStream ms = new MemoryStream(data); 929 using (MemoryStream ms = new MemoryStream(data))
830 terrainModule.LoadFromStream(terrainPath, ms); 930 {
831 ms.Close(); 931 if (m_displacement != Vector3.Zero || m_rotation != 0f)
932 {
933 Vector2 rotationCenter = new Vector2(m_rotationCenter.X, m_rotationCenter.Y);
934 terrainModule.LoadFromStream(terrainPath, m_displacement, m_rotation, rotationCenter, ms);
935 }
936 else
937 {
938 terrainModule.LoadFromStream(terrainPath, ms);
939 }
940 }
832 941
833 m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath); 942 m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);
834 943