aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs434
1 files changed, 87 insertions, 347 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index ade5e76..619550c 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -43,7 +43,6 @@ using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes; 43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Region.Framework.Scenes.Serialization; 44using OpenSim.Region.Framework.Scenes.Serialization;
45using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
46using System.Threading;
47 46
48namespace OpenSim.Region.CoreModules.World.Archiver 47namespace OpenSim.Region.CoreModules.World.Archiver
49{ 48{
@@ -53,30 +52,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
53 public class ArchiveReadRequest 52 public class ArchiveReadRequest
54 { 53 {
55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56
57 /// <summary>
58 /// Contains data used while dearchiving a single scene.
59 /// </summary>
60 private class DearchiveContext
61 {
62 public Scene Scene { get; set; }
63
64 public List<string> SerialisedSceneObjects { get; set; }
65
66 public List<string> SerialisedParcels { get; set; }
67
68 public List<SceneObjectGroup> SceneObjects { get; set; }
69
70 public DearchiveContext(Scene scene)
71 {
72 Scene = scene;
73 SerialisedSceneObjects = new List<string>();
74 SerialisedParcels = new List<string>();
75 SceneObjects = new List<SceneObjectGroup>();
76 }
77 }
78 55
79
80 /// <summary> 56 /// <summary>
81 /// The maximum major version of OAR that we can read. Minor versions shouldn't need a max number since version 57 /// The maximum major version of OAR that we can read. Minor versions shouldn't need a max number since version
82 /// bumps here should be compatible. 58 /// bumps here should be compatible.
@@ -86,10 +62,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
86 /// <summary> 62 /// <summary>
87 /// Has the control file been loaded for this archive? 63 /// Has the control file been loaded for this archive?
88 /// </summary> 64 /// </summary>
89 public bool ControlFileLoaded { get; private set; } 65 public bool ControlFileLoaded { get; private set; }
90 66
91 protected string m_loadPath; 67 protected Scene m_scene;
92 protected Scene m_rootScene;
93 protected Stream m_loadStream; 68 protected Stream m_loadStream;
94 protected Guid m_requestId; 69 protected Guid m_requestId;
95 protected string m_errorMessage; 70 protected string m_errorMessage;
@@ -116,27 +91,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
116 { 91 {
117 if (m_UserMan == null) 92 if (m_UserMan == null)
118 { 93 {
119 m_UserMan = m_rootScene.RequestModuleInterface<IUserManagement>(); 94 m_UserMan = m_scene.RequestModuleInterface<IUserManagement>();
120 } 95 }
121 return m_UserMan; 96 return m_UserMan;
122 } 97 }
123 } 98 }
124 99
125 /// <summary>
126 /// Used to cache lookups for valid groups.
127 /// </summary>
128 private IDictionary<UUID, bool> m_validGroupUuids = new Dictionary<UUID, bool>();
129
130 private IGroupsModule m_groupsModule;
131
132 private IAssetService m_assetService = null;
133
134
135 public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId) 100 public ArchiveReadRequest(Scene scene, string loadPath, bool merge, bool skipAssets, Guid requestId)
136 { 101 {
137 m_rootScene = scene; 102 m_scene = scene;
138 103
139 m_loadPath = loadPath;
140 try 104 try
141 { 105 {
142 m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress); 106 m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress);
@@ -156,15 +120,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
156 120
157 // Zero can never be a valid user id 121 // Zero can never be a valid user id
158 m_validUserUuids[UUID.Zero] = false; 122 m_validUserUuids[UUID.Zero] = false;
159
160 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
161 m_assetService = m_rootScene.AssetService;
162 } 123 }
163 124
164 public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId) 125 public ArchiveReadRequest(Scene scene, Stream loadStream, bool merge, bool skipAssets, Guid requestId)
165 { 126 {
166 m_rootScene = scene; 127 m_scene = scene;
167 m_loadPath = null;
168 m_loadStream = loadStream; 128 m_loadStream = loadStream;
169 m_merge = merge; 129 m_merge = merge;
170 m_skipAssets = skipAssets; 130 m_skipAssets = skipAssets;
@@ -172,9 +132,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver
172 132
173 // Zero can never be a valid user id 133 // Zero can never be a valid user id
174 m_validUserUuids[UUID.Zero] = false; 134 m_validUserUuids[UUID.Zero] = false;
175
176 m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
177 m_assetService = m_rootScene.AssetService;
178 } 135 }
179 136
180 /// <summary> 137 /// <summary>
@@ -182,25 +139,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver
182 /// </summary> 139 /// </summary>
183 public void DearchiveRegion() 140 public void DearchiveRegion()
184 { 141 {
142 // The same code can handle dearchiving 0.1 and 0.2 OpenSim Archive versions
143 DearchiveRegion0DotStar();
144 }
145
146 private void DearchiveRegion0DotStar()
147 {
185 int successfulAssetRestores = 0; 148 int successfulAssetRestores = 0;
186 int failedAssetRestores = 0; 149 int failedAssetRestores = 0;
150 List<string> serialisedSceneObjects = new List<string>();
151 List<string> serialisedParcels = new List<string>();
152 string filePath = "NONE";
187 153
188 DearchiveScenesInfo dearchivedScenes; 154 TarArchiveReader archive = new TarArchiveReader(m_loadStream);
189
190 // We dearchive all the scenes at once, because the files in the TAR archive might be mixed.
191 // Therefore, we have to keep track of the dearchive context of all the scenes.
192 Dictionary<UUID, DearchiveContext> sceneContexts = new Dictionary<UUID, DearchiveContext>();
193
194 string fullPath = "NONE";
195 TarArchiveReader archive = null;
196 byte[] data; 155 byte[] data;
197 TarArchiveReader.TarEntryType entryType; 156 TarArchiveReader.TarEntryType entryType;
198 157
199 try 158 try
200 { 159 {
201 FindAndLoadControlFile(out archive, out dearchivedScenes); 160 while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
202
203 while ((data = archive.ReadEntry(out fullPath, out entryType)) != null)
204 { 161 {
205 //m_log.DebugFormat( 162 //m_log.DebugFormat(
206 // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length); 163 // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length);
@@ -208,30 +165,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
208 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType) 165 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
209 continue; 166 continue;
210 167
211
212 // Find the scene that this file belongs to
213
214 Scene scene;
215 string filePath;
216 if (!dearchivedScenes.GetRegionFromPath(fullPath, out scene, out filePath))
217 continue; // this file belongs to a region that we're not loading
218
219 DearchiveContext sceneContext = null;
220 if (scene != null)
221 {
222 if (!sceneContexts.TryGetValue(scene.RegionInfo.RegionID, out sceneContext))
223 {
224 sceneContext = new DearchiveContext(scene);
225 sceneContexts.Add(scene.RegionInfo.RegionID, sceneContext);
226 }
227 }
228
229
230 // Process the file
231
232 if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) 168 if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
233 { 169 {
234 sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data)); 170 serialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
235 } 171 }
236 else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets) 172 else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
237 { 173 {
@@ -245,19 +181,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver
245 } 181 }
246 else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH)) 182 else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
247 { 183 {
248 LoadTerrain(scene, filePath, data); 184 LoadTerrain(filePath, data);
249 } 185 }
250 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) 186 else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
251 { 187 {
252 LoadRegionSettings(scene, filePath, data, dearchivedScenes); 188 LoadRegionSettings(filePath, data);
253 } 189 }
254 else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH)) 190 else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
255 { 191 {
256 sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); 192 serialisedParcels.Add(Encoding.UTF8.GetString(data));
257 } 193 }
258 else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) 194 else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
259 { 195 {
260 // Ignore, because we already read the control file 196 LoadControlFile(filePath, data);
261 } 197 }
262 } 198 }
263 199
@@ -265,16 +201,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
265 } 201 }
266 catch (Exception e) 202 catch (Exception e)
267 { 203 {
268 m_log.Error( 204 m_log.ErrorFormat(
269 String.Format("[ARCHIVER]: Aborting load with error in archive file {0} ", fullPath), e); 205 "[ARCHIVER]: Aborting load with error in archive file {0}. {1}", filePath, e);
270 m_errorMessage += e.ToString(); 206 m_errorMessage += e.ToString();
271 m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage); 207 m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
272 return; 208 return;
273 } 209 }
274 finally 210 finally
275 { 211 {
276 if (archive != null) 212 archive.Close();
277 archive.Close();
278 } 213 }
279 214
280 if (!m_skipAssets) 215 if (!m_skipAssets)
@@ -288,143 +223,32 @@ namespace OpenSim.Region.CoreModules.World.Archiver
288 } 223 }
289 } 224 }
290 225
291 foreach (DearchiveContext sceneContext in sceneContexts.Values) 226 if (!m_merge)
292 { 227 {
293 m_log.InfoFormat("[ARCHIVER]: Loading region {0}", sceneContext.Scene.RegionInfo.RegionName); 228 m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
294 229 m_scene.DeleteAllSceneObjects();
295 if (!m_merge)
296 {
297 m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
298 sceneContext.Scene.DeleteAllSceneObjects();
299 }
300
301 try
302 {
303 LoadParcels(sceneContext.Scene, sceneContext.SerialisedParcels);
304 LoadObjects(sceneContext.Scene, sceneContext.SerialisedSceneObjects, sceneContext.SceneObjects);
305
306 // Inform any interested parties that the region has changed. We waited until now so that all
307 // of the region's objects will be loaded when we send this notification.
308 IEstateModule estateModule = sceneContext.Scene.RequestModuleInterface<IEstateModule>();
309 if (estateModule != null)
310 estateModule.TriggerRegionInfoChange();
311 }
312 catch (Exception e)
313 {
314 m_log.Error("[ARCHIVER]: Error loading parcels or objects ", e);
315 m_errorMessage += e.ToString();
316 m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage);
317 return;
318 }
319 } 230 }
320 231
321 // Start the scripts. We delayed this because we want the OAR to finish loading ASAP, so 232 LoadParcels(serialisedParcels);
322 // that users can enter the scene. If we allow the scripts to start in the loop above 233 LoadObjects(serialisedSceneObjects);
323 // then they significantly increase the time until the OAR finishes loading.
324 Util.FireAndForget(delegate(object o)
325 {
326 Thread.Sleep(15000);
327 m_log.Info("[ARCHIVER]: Starting scripts in scene objects");
328
329 foreach (DearchiveContext sceneContext in sceneContexts.Values)
330 {
331 foreach (SceneObjectGroup sceneObject in sceneContext.SceneObjects)
332 {
333 sceneObject.CreateScriptInstances(0, false, sceneContext.Scene.DefaultScriptEngine, 0); // StateSource.RegionStart
334 sceneObject.ResumeScripts();
335 }
336
337 sceneContext.SceneObjects.Clear();
338 }
339 });
340 234
341 m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); 235 m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");
342 236
343 m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, dearchivedScenes.GetLoadedScenes(), m_errorMessage); 237 m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
344 }
345
346 /// <summary>
347 /// Searches through the files in the archive for the control file, and reads it.
348 /// We must read the control file first, in order to know which regions are available.
349 /// </summary>
350 /// <remarks>
351 /// In most cases the control file *is* first, since that's how we create archives. However,
352 /// it's possible that someone rewrote the archive externally so we can't rely on this fact.
353 /// </remarks>
354 /// <param name="archive"></param>
355 /// <param name="dearchivedScenes"></param>
356 private void FindAndLoadControlFile(out TarArchiveReader archive, out DearchiveScenesInfo dearchivedScenes)
357 {
358 archive = new TarArchiveReader(m_loadStream);
359 dearchivedScenes = new DearchiveScenesInfo();
360
361 string filePath;
362 byte[] data;
363 TarArchiveReader.TarEntryType entryType;
364 bool firstFile = true;
365
366 while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
367 {
368 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
369 continue;
370
371 if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
372 {
373 LoadControlFile(filePath, data, dearchivedScenes);
374
375 // Find which scenes are available in the simulator
376 ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup();
377 SceneManager.Instance.ForEachScene(delegate(Scene scene2)
378 {
379 simulatorScenes.AddScene(scene2);
380 });
381 simulatorScenes.CalcSceneLocations();
382 dearchivedScenes.SetSimulatorScenes(m_rootScene, simulatorScenes);
383
384 // If the control file wasn't the first file then reset the read pointer
385 if (!firstFile)
386 {
387 m_log.Warn("Control file wasn't the first file in the archive");
388 if (m_loadStream.CanSeek)
389 {
390 m_loadStream.Seek(0, SeekOrigin.Begin);
391 }
392 else if (m_loadPath != null)
393 {
394 archive.Close();
395 archive = null;
396 m_loadStream.Close();
397 m_loadStream = null;
398 m_loadStream = new GZipStream(ArchiveHelpers.GetStream(m_loadPath), CompressionMode.Decompress);
399 archive = new TarArchiveReader(m_loadStream);
400 }
401 else
402 {
403 // There isn't currently a scenario where this happens, but it's best to add a check just in case
404 throw new Exception("Error reading archive: control file wasn't the first file, and the input stream doesn't allow seeking");
405 }
406 }
407
408 return;
409 }
410
411 firstFile = false;
412 }
413
414 throw new Exception("Control file not found");
415 } 238 }
416 239
417 /// <summary> 240 /// <summary>
418 /// Load serialized scene objects. 241 /// Load serialized scene objects.
419 /// </summary> 242 /// </summary>
420 protected void LoadObjects(Scene scene, List<string> serialisedSceneObjects, List<SceneObjectGroup> sceneObjects) 243 /// <param name="serialisedSceneObjects"></param>
244 protected void LoadObjects(List<string> serialisedSceneObjects)
421 { 245 {
422 // Reload serialized prims 246 // Reload serialized prims
423 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); 247 m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
424 248
425 UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject; 249 UUID oldTelehubUUID = m_scene.RegionInfo.RegionSettings.TelehubObject;
426 250
427 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>(); 251 IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface<IRegionSerialiserModule>();
428 int sceneObjectsLoadedCount = 0; 252 int sceneObjectsLoadedCount = 0;
429 253
430 foreach (string serialisedSceneObject in serialisedSceneObjects) 254 foreach (string serialisedSceneObject in serialisedSceneObjects)
@@ -445,7 +269,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
445 269
446 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject); 270 SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
447 271
448 bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero); 272 bool isTelehub = (sceneObject.UUID == oldTelehubUUID);
449 273
450 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned 274 // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
451 // on the same region server and multiple examples a single object archive to be imported 275 // on the same region server and multiple examples a single object archive to be imported
@@ -455,8 +279,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
455 if (isTelehub) 279 if (isTelehub)
456 { 280 {
457 // Change the Telehub Object to the new UUID 281 // Change the Telehub Object to the new UUID
458 scene.RegionInfo.RegionSettings.TelehubObject = sceneObject.UUID; 282 m_scene.RegionInfo.RegionSettings.TelehubObject = sceneObject.UUID;
459 scene.RegionInfo.RegionSettings.Save(); 283 m_scene.RegionInfo.RegionSettings.Save();
460 oldTelehubUUID = UUID.Zero; 284 oldTelehubUUID = UUID.Zero;
461 } 285 }
462 286
@@ -466,20 +290,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver
466 { 290 {
467 if (part.CreatorData == null || part.CreatorData == string.Empty) 291 if (part.CreatorData == null || part.CreatorData == string.Empty)
468 { 292 {
469 if (!ResolveUserUuid(scene, part.CreatorID)) 293 if (!ResolveUserUuid(part.CreatorID))
470 part.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner; 294 part.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
471 } 295 }
472 if (UserManager != null) 296 if (UserManager != null)
473 UserManager.AddUser(part.CreatorID, part.CreatorData); 297 UserManager.AddUser(part.CreatorID, part.CreatorData);
474 298
475 if (!ResolveUserUuid(scene, part.OwnerID)) 299 if (!ResolveUserUuid(part.OwnerID))
476 part.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner; 300 part.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
477
478 if (!ResolveUserUuid(scene, part.LastOwnerID))
479 part.LastOwnerID = scene.RegionInfo.EstateSettings.EstateOwner;
480 301
481 if (!ResolveGroupUuid(part.GroupID)) 302 if (!ResolveUserUuid(part.LastOwnerID))
482 part.GroupID = UUID.Zero; 303 part.LastOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
483 304
484 // And zap any troublesome sit target information 305 // And zap any troublesome sit target information
485// part.SitTargetOrientation = new Quaternion(0, 0, 0, 1); 306// part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
@@ -490,14 +311,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
490 // being no copy/no mod for everyone 311 // being no copy/no mod for everyone
491 lock (part.TaskInventory) 312 lock (part.TaskInventory)
492 { 313 {
493 if (!ResolveUserUuid(scene, part.CreatorID)) 314 if (!ResolveUserUuid(part.CreatorID))
494 part.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner; 315 part.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
495 316
496 if (!ResolveUserUuid(scene, part.OwnerID)) 317 if (!ResolveUserUuid(part.OwnerID))
497 part.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner; 318 part.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
498 319
499 if (!ResolveUserUuid(scene, part.LastOwnerID)) 320 if (!ResolveUserUuid(part.LastOwnerID))
500 part.LastOwnerID = scene.RegionInfo.EstateSettings.EstateOwner; 321 part.LastOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
501 322
502 // And zap any troublesome sit target information 323 // And zap any troublesome sit target information
503 part.SitTargetOrientation = new Quaternion(0, 0, 0, 1); 324 part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
@@ -510,31 +331,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver
510 TaskInventoryDictionary inv = part.TaskInventory; 331 TaskInventoryDictionary inv = part.TaskInventory;
511 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv) 332 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
512 { 333 {
513 if (!ResolveUserUuid(scene, kvp.Value.OwnerID)) 334 if (!ResolveUserUuid(kvp.Value.OwnerID))
514 { 335 {
515 kvp.Value.OwnerID = scene.RegionInfo.EstateSettings.EstateOwner; 336 kvp.Value.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
516 } 337 }
517
518 if (kvp.Value.CreatorData == null || kvp.Value.CreatorData == string.Empty) 338 if (kvp.Value.CreatorData == null || kvp.Value.CreatorData == string.Empty)
519 { 339 {
520 if (!ResolveUserUuid(scene, kvp.Value.CreatorID)) 340 if (!ResolveUserUuid(kvp.Value.CreatorID))
521 kvp.Value.CreatorID = scene.RegionInfo.EstateSettings.EstateOwner; 341 kvp.Value.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
522 } 342 }
523
524 if (UserManager != null) 343 if (UserManager != null)
525 UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData); 344 UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
526
527 if (!ResolveGroupUuid(kvp.Value.GroupID))
528 kvp.Value.GroupID = UUID.Zero;
529 } 345 }
530 part.TaskInventory.LockItemsForRead(false); 346 part.TaskInventory.LockItemsForRead(false);
531 } 347 }
532 } 348 }
533 349
534 if (scene.AddRestoredSceneObject(sceneObject, true, false)) 350 if (m_scene.AddRestoredSceneObject(sceneObject, true, false))
535 { 351 {
536 sceneObjectsLoadedCount++; 352 sceneObjectsLoadedCount++;
537 sceneObject.CreateScriptInstances(0, false, scene.DefaultScriptEngine, 0); 353 sceneObject.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, 0);
538 sceneObject.ResumeScripts(); 354 sceneObject.ResumeScripts();
539 } 355 }
540 } 356 }
@@ -549,17 +365,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
549 if (oldTelehubUUID != UUID.Zero) 365 if (oldTelehubUUID != UUID.Zero)
550 { 366 {
551 m_log.WarnFormat("Telehub object not found: {0}", oldTelehubUUID); 367 m_log.WarnFormat("Telehub object not found: {0}", oldTelehubUUID);
552 scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero; 368 m_scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero;
553 scene.RegionInfo.RegionSettings.ClearSpawnPoints(); 369 m_scene.RegionInfo.RegionSettings.ClearSpawnPoints();
554 } 370 }
555 } 371 }
556 372
557 /// <summary> 373 /// <summary>
558 /// Load serialized parcels. 374 /// Load serialized parcels.
559 /// </summary> 375 /// </summary>
560 /// <param name="scene"></param>
561 /// <param name="serialisedParcels"></param> 376 /// <param name="serialisedParcels"></param>
562 protected void LoadParcels(Scene scene, List<string> serialisedParcels) 377 protected void LoadParcels(List<string> serialisedParcels)
563 { 378 {
564 // Reload serialized parcels 379 // Reload serialized parcels
565 m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count); 380 m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count);
@@ -567,27 +382,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
567 foreach (string serialisedParcel in serialisedParcels) 382 foreach (string serialisedParcel in serialisedParcels)
568 { 383 {
569 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); 384 LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
385 if (!ResolveUserUuid(parcel.OwnerID))
386 parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
570 387
571 // Validate User and Group UUID's
572
573 if (!ResolveUserUuid(scene, parcel.OwnerID))
574 parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
575
576 if (!ResolveGroupUuid(parcel.GroupID))
577 {
578 parcel.GroupID = UUID.Zero;
579 parcel.IsGroupOwned = false;
580 }
581
582 List<LandAccessEntry> accessList = new List<LandAccessEntry>();
583 foreach (LandAccessEntry entry in parcel.ParcelAccessList)
584 {
585 if (ResolveUserUuid(scene, entry.AgentID))
586 accessList.Add(entry);
587 // else, drop this access rule
588 }
589 parcel.ParcelAccessList = accessList;
590
591// m_log.DebugFormat( 388// m_log.DebugFormat(
592// "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}", 389// "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}",
593// parcel.Name, parcel.LocalID, parcel.Area); 390// parcel.Name, parcel.LocalID, parcel.Area);
@@ -598,24 +395,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
598 if (!m_merge) 395 if (!m_merge)
599 { 396 {
600 bool setupDefaultParcel = (landData.Count == 0); 397 bool setupDefaultParcel = (landData.Count == 0);
601 scene.LandChannel.Clear(setupDefaultParcel); 398 m_scene.LandChannel.Clear(setupDefaultParcel);
602 } 399 }
603 400
604 scene.EventManager.TriggerIncomingLandDataFromStorage(landData); 401 m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
605 m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count); 402 m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);
606 } 403 }
607 404
608 /// <summary> 405 /// <summary>
609 /// Look up the given user id to check whether it's one that is valid for this grid. 406 /// Look up the given user id to check whether it's one that is valid for this grid.
610 /// </summary> 407 /// </summary>
611 /// <param name="scene"></param>
612 /// <param name="uuid"></param> 408 /// <param name="uuid"></param>
613 /// <returns></returns> 409 /// <returns></returns>
614 private bool ResolveUserUuid(Scene scene, UUID uuid) 410 private bool ResolveUserUuid(UUID uuid)
615 { 411 {
616 if (!m_validUserUuids.ContainsKey(uuid)) 412 if (!m_validUserUuids.ContainsKey(uuid))
617 { 413 {
618 UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, uuid); 414 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid);
619 m_validUserUuids.Add(uuid, account != null); 415 m_validUserUuids.Add(uuid, account != null);
620 } 416 }
621 417
@@ -623,30 +419,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver
623 } 419 }
624 420
625 /// <summary> 421 /// <summary>
626 /// Look up the given group id to check whether it's one that is valid for this grid.
627 /// </summary>
628 /// <param name="uuid"></param>
629 /// <returns></returns>
630 private bool ResolveGroupUuid(UUID uuid)
631 {
632 if (uuid == UUID.Zero)
633 return true; // this means the object has no group
634
635 if (!m_validGroupUuids.ContainsKey(uuid))
636 {
637 bool exists;
638
639 if (m_groupsModule == null)
640 exists = false;
641 else
642 exists = (m_groupsModule.GetGroupRecord(uuid) != null);
643
644 m_validGroupUuids.Add(uuid, exists);
645 }
646
647 return m_validGroupUuids[uuid];
648 }
649
650 /// Load an asset 422 /// Load an asset
651 /// </summary> 423 /// </summary>
652 /// <param name="assetFilename"></param> 424 /// <param name="assetFilename"></param>
@@ -670,7 +442,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
670 string extension = filename.Substring(i); 442 string extension = filename.Substring(i);
671 string uuid = filename.Remove(filename.Length - extension.Length); 443 string uuid = filename.Remove(filename.Length - extension.Length);
672 444
673 if (m_assetService.GetMetadata(uuid) != null) 445 if (m_scene.AssetService.GetMetadata(uuid) != null)
674 { 446 {
675 // m_log.DebugFormat("[ARCHIVER]: found existing asset {0}",uuid); 447 // m_log.DebugFormat("[ARCHIVER]: found existing asset {0}",uuid);
676 return true; 448 return true;
@@ -690,7 +462,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
690 462
691 // We're relying on the asset service to do the sensible thing and not store the asset if it already 463 // We're relying on the asset service to do the sensible thing and not store the asset if it already
692 // exists. 464 // exists.
693 m_assetService.Store(asset); 465 m_scene.AssetService.Store(asset);
694 466
695 /** 467 /**
696 * Create layers on decode for image assets. This is likely to significantly increase the time to load archives so 468 * Create layers on decode for image assets. This is likely to significantly increase the time to load archives so
@@ -718,14 +490,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
718 /// <summary> 490 /// <summary>
719 /// Load region settings data 491 /// Load region settings data
720 /// </summary> 492 /// </summary>
721 /// <param name="scene"></param>
722 /// <param name="settingsPath"></param> 493 /// <param name="settingsPath"></param>
723 /// <param name="data"></param> 494 /// <param name="data"></param>
724 /// <param name="dearchivedScenes"></param>
725 /// <returns> 495 /// <returns>
726 /// true if settings were loaded successfully, false otherwise 496 /// true if settings were loaded successfully, false otherwise
727 /// </returns> 497 /// </returns>
728 private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes) 498 private bool LoadRegionSettings(string settingsPath, byte[] data)
729 { 499 {
730 RegionSettings loadedRegionSettings; 500 RegionSettings loadedRegionSettings;
731 501
@@ -741,7 +511,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
741 return false; 511 return false;
742 } 512 }
743 513
744 RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings; 514 RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings;
745 515
746 currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit; 516 currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit;
747 currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage; 517 currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage;
@@ -778,14 +548,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
778 foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints()) 548 foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints())
779 currentRegionSettings.AddSpawnPoint(sp); 549 currentRegionSettings.AddSpawnPoint(sp);
780 550
781 currentRegionSettings.LoadedCreationDateTime = dearchivedScenes.LoadedCreationDateTime;
782 currentRegionSettings.LoadedCreationID = dearchivedScenes.GetOriginalRegionID(scene.RegionInfo.RegionID).ToString();
783
784 currentRegionSettings.Save(); 551 currentRegionSettings.Save();
785 552
786 scene.TriggerEstateSunUpdate(); 553 m_scene.TriggerEstateSunUpdate();
787 554
788 IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>(); 555 IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
556
789 if (estateModule != null) 557 if (estateModule != null)
790 estateModule.sendRegionHandshakeToAll(); 558 estateModule.sendRegionHandshakeToAll();
791 559
@@ -795,15 +563,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
795 /// <summary> 563 /// <summary>
796 /// Load terrain data 564 /// Load terrain data
797 /// </summary> 565 /// </summary>
798 /// <param name="scene"></param>
799 /// <param name="terrainPath"></param> 566 /// <param name="terrainPath"></param>
800 /// <param name="data"></param> 567 /// <param name="data"></param>
801 /// <returns> 568 /// <returns>
802 /// true if terrain was resolved successfully, false otherwise. 569 /// true if terrain was resolved successfully, false otherwise.
803 /// </returns> 570 /// </returns>
804 private bool LoadTerrain(Scene scene, string terrainPath, byte[] data) 571 private bool LoadTerrain(string terrainPath, byte[] data)
805 { 572 {
806 ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); 573 ITerrainModule terrainModule = m_scene.RequestModuleInterface<ITerrainModule>();
807 574
808 MemoryStream ms = new MemoryStream(data); 575 MemoryStream ms = new MemoryStream(data);
809 terrainModule.LoadFromStream(terrainPath, ms); 576 terrainModule.LoadFromStream(terrainPath, ms);
@@ -819,18 +586,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver
819 /// </summary> 586 /// </summary>
820 /// <param name="path"></param> 587 /// <param name="path"></param>
821 /// <param name="data"></param> 588 /// <param name="data"></param>
822 /// <param name="dearchivedScenes"></param> 589 public void LoadControlFile(string path, byte[] data)
823 public DearchiveScenesInfo LoadControlFile(string path, byte[] data, DearchiveScenesInfo dearchivedScenes)
824 { 590 {
825 XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); 591 XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
826 XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); 592 XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
827 XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context); 593 XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);
828 594
829 // Loaded metadata will be empty if no information exists in the archive 595 RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings;
830 dearchivedScenes.LoadedCreationDateTime = 0;
831 dearchivedScenes.DefaultOriginalID = "";
832 596
833 bool multiRegion = false; 597 // Loaded metadata will empty if no information exists in the archive
598 currentRegionSettings.LoadedCreationDateTime = 0;
599 currentRegionSettings.LoadedCreationID = "";
834 600
835 while (xtr.Read()) 601 while (xtr.Read())
836 { 602 {
@@ -856,44 +622,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver
856 { 622 {
857 int value; 623 int value;
858 if (Int32.TryParse(xtr.ReadElementContentAsString(), out value)) 624 if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
859 dearchivedScenes.LoadedCreationDateTime = value; 625 currentRegionSettings.LoadedCreationDateTime = value;
860 } 626 }
861 else if (xtr.Name.ToString() == "row") 627 else if (xtr.Name.ToString() == "id")
862 {
863 multiRegion = true;
864 dearchivedScenes.StartRow();
865 }
866 else if (xtr.Name.ToString() == "region")
867 {
868 dearchivedScenes.StartRegion();
869 }
870 else if (xtr.Name.ToString() == "id")
871 {
872 string id = xtr.ReadElementContentAsString();
873 dearchivedScenes.DefaultOriginalID = id;
874 if (multiRegion)
875 dearchivedScenes.SetRegionOriginalID(id);
876 }
877 else if (xtr.Name.ToString() == "dir")
878 { 628 {
879 dearchivedScenes.SetRegionDirectory(xtr.ReadElementContentAsString()); 629 currentRegionSettings.LoadedCreationID = xtr.ReadElementContentAsString();
880 } 630 }
881 } 631 }
882 } 632 }
883 633
884 dearchivedScenes.MultiRegionFormat = multiRegion; 634 currentRegionSettings.Save();
885 if (!multiRegion) 635
886 {
887 // Add the single scene
888 dearchivedScenes.StartRow();
889 dearchivedScenes.StartRegion();
890 dearchivedScenes.SetRegionOriginalID(dearchivedScenes.DefaultOriginalID);
891 dearchivedScenes.SetRegionDirectory("");
892 }
893
894 ControlFileLoaded = true; 636 ControlFileLoaded = true;
895
896 return dearchivedScenes;
897 } 637 }
898 } 638 }
899} 639} \ No newline at end of file