diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index f07dee9..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 | ||
@@ -1230,7 +1297,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
1230 | if (m_UserManagement == null) | 1297 | if (m_UserManagement == null) |
1231 | m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>(); | 1298 | m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>(); |
1232 | string name = m_UserManagement.GetUserName(sop.CreatorID); | 1299 | string name = m_UserManagement.GetUserName(sop.CreatorID); |
1233 | writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name); | 1300 | writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name)); |
1234 | } | 1301 | } |
1235 | 1302 | ||
1236 | WriteUUID(writer, "FolderID", sop.FolderID, options); | 1303 | WriteUUID(writer, "FolderID", sop.FolderID, options); |
@@ -1403,7 +1470,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization | |||
1403 | if (m_UserManagement == null) | 1470 | if (m_UserManagement == null) |
1404 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); | 1471 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); |
1405 | string name = m_UserManagement.GetUserName(item.CreatorID); | 1472 | string name = m_UserManagement.GetUserName(item.CreatorID); |
1406 | writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name); | 1473 | writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name)); |
1407 | } | 1474 | } |
1408 | 1475 | ||
1409 | writer.WriteElementString("Description", item.Description); | 1476 | writer.WriteElementString("Description", item.Description); |