aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorOren Hurvitz2013-11-18 12:48:23 +0200
committerOren Hurvitz2014-03-24 18:17:35 +0100
commit5fd94111434c2faa742d4eb7357d7a6b02253988 (patch)
treeee9272cc38a1d2a2afcd6c0b85c38dccc6449315 /OpenSim
parentHGAssetService searches for the "HomeURI" setting in several sections: Startu... (diff)
downloadopensim-SC_OLD-5fd94111434c2faa742d4eb7357d7a6b02253988.zip
opensim-SC_OLD-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.gz
opensim-SC_OLD-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.bz2
opensim-SC_OLD-5fd94111434c2faa742d4eb7357d7a6b02253988.tar.xz
Refactored Load IAR: created a generic mechanism to modify the SOG's as they are being loaded
Resolves http://opensimulator.org/mantis/view.php?id=6942
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs66
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs67
2 files changed, 86 insertions, 47 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index f7057fe..9963521 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -483,52 +483,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
483 { 483 {
484 if (m_creatorIdForAssetId.ContainsKey(assetId)) 484 if (m_creatorIdForAssetId.ContainsKey(assetId))
485 { 485 {
486 string xmlData = Utils.BytesToString(data); 486 data = SceneObjectSerializer.ModifySerializedObject(assetId, data,
487 List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); 487 sog => {
488 bool modified = false;
489
490 foreach (SceneObjectPart sop in sog.Parts)
491 {
492 if (string.IsNullOrEmpty(sop.CreatorData))
493 {
494 sop.CreatorID = m_creatorIdForAssetId[assetId];
495 modified = true;
496 }
497 }
498
499 return modified;
500 });
488 501
489 CoalescedSceneObjects coa = null; 502 if (data == null)
490 if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) 503 return false;
491 {
492// m_log.DebugFormat(
493// "[INVENTORY ARCHIVER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
494
495 if (coa.Objects.Count == 0)
496 {
497 m_log.WarnFormat(
498 "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of coalesced object from asset {0} as it has zero loaded components",
499 assetId);
500 return false;
501 }
502
503 sceneObjects.AddRange(coa.Objects);
504 }
505 else
506 {
507 SceneObjectGroup deserializedObject = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
508
509 if (deserializedObject != null)
510 {
511 sceneObjects.Add(deserializedObject);
512 }
513 else
514 {
515 m_log.WarnFormat(
516 "[INVENTORY ARCHIVE READ REQUEST]: Aborting load of object from asset {0} as deserialization failed",
517 assetId);
518
519 return false;
520 }
521 }
522
523 foreach (SceneObjectGroup sog in sceneObjects)
524 foreach (SceneObjectPart sop in sog.Parts)
525 if (string.IsNullOrEmpty(sop.CreatorData))
526 sop.CreatorID = m_creatorIdForAssetId[assetId];
527
528 if (coa != null)
529 data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
530 else
531 data = Utils.StringToBytes(SceneObjectSerializer.ToOriginalXmlFormat(sceneObjects[0]));
532 } 504 }
533 } 505 }
534 506
@@ -550,7 +522,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
550 return false; 522 return false;
551 } 523 }
552 } 524 }
553 525
554 /// <summary> 526 /// <summary>
555 /// Load control file 527 /// Load control file
556 /// </summary> 528 /// </summary>
@@ -656,4 +628,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
656 m_assetsLoaded = true; 628 m_assetsLoaded = true;
657 } 629 }
658 } 630 }
659} \ No newline at end of file 631}
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index 4deca00..a93f3c8 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -299,6 +299,73 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
299 } 299 }
300 } 300 }
301 301
302
303 /// <summary>
304 /// Modifies a SceneObjectGroup.
305 /// </summary>
306 /// <param name="sog">The object</param>
307 /// <returns>Whether the object was actually modified</returns>
308 public delegate bool SceneObjectModifier(SceneObjectGroup sog);
309
310 /// <summary>
311 /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing.
312 /// </summary>
313 /// <param name="assetId">The object's UUID</param>
314 /// <param name="data">Serialized data</param>
315 /// <param name="modifier">The function to run on each SceneObjectGroup</param>
316 /// <returns>The new serialized object's data, or null if an error occurred</returns>
317 public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
318 {
319 List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
320 CoalescedSceneObjects coa = null;
321
322 string xmlData = Utils.BytesToString(data);
323
324 if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa))
325 {
326 // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
327
328 if (coa.Objects.Count == 0)
329 {
330 m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId);
331 return null;
332 }
333
334 sceneObjects.AddRange(coa.Objects);
335 }
336 else
337 {
338 SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData);
339
340 if (deserializedObject != null)
341 {
342 sceneObjects.Add(deserializedObject);
343 }
344 else
345 {
346 m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId);
347 return null;
348 }
349 }
350
351 bool modified = false;
352 foreach (SceneObjectGroup sog in sceneObjects)
353 {
354 if (modifier(sog))
355 modified = true;
356 }
357
358 if (modified)
359 {
360 if (coa != null)
361 data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
362 else
363 data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0]));
364 }
365
366 return data;
367 }
368
302 369
303 #region manual serialization 370 #region manual serialization
304 371