SceneObjectSerializer.cs 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Drawing;
  30. using System.IO;
  31. using System.Linq;
  32. using System.Reflection;
  33. using System.Xml;
  34. using log4net;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Serialization.External;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Services.Interfaces;
  41. namespace OpenSim.Region.Framework.Scenes.Serialization
  42. {
  43. /// <summary>
  44. /// Serialize and deserialize scene objects.
  45. /// </summary>
  46. /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
  47. /// right now - hopefully this isn't forever.
  48. public class SceneObjectSerializer
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private static IUserManagement m_UserManagement;
  52. /// <summary>
  53. /// Deserialize a scene object from the original xml format
  54. /// </summary>
  55. /// <param name="xmlData"></param>
  56. /// <returns>The scene object deserialized. Null on failure.</returns>
  57. public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
  58. {
  59. String fixedData = ExternalRepresentationUtils.SanitizeXml(xmlData);
  60. using (XmlTextReader wrappedReader = new XmlTextReader(fixedData, XmlNodeType.Element, null))
  61. {
  62. using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment, ProhibitDtd = true }))
  63. {
  64. try
  65. {
  66. return FromOriginalXmlFormat(reader);
  67. }
  68. catch (Exception e)
  69. {
  70. m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
  71. Util.LogFailedXML("[SERIALIZER]:", fixedData);
  72. return null;
  73. }
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// Deserialize a scene object from the original xml format
  79. /// </summary>
  80. /// <param name="xmlData"></param>
  81. /// <returns>The scene object deserialized. Null on failure.</returns>
  82. public static SceneObjectGroup FromOriginalXmlFormat(XmlReader reader)
  83. {
  84. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  85. //int time = System.Environment.TickCount;
  86. int linkNum;
  87. reader.ReadToFollowing("RootPart");
  88. reader.ReadToFollowing("SceneObjectPart");
  89. SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  90. reader.ReadToFollowing("OtherParts");
  91. if (reader.ReadToDescendant("Part"))
  92. {
  93. do
  94. {
  95. if (reader.ReadToDescendant("SceneObjectPart"))
  96. {
  97. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  98. linkNum = part.LinkNum;
  99. sceneObject.AddPart(part);
  100. part.LinkNum = linkNum;
  101. part.TrimPermissions();
  102. }
  103. }
  104. while (reader.ReadToNextSibling("Part"));
  105. reader.ReadEndElement();
  106. }
  107. if (reader.Name == "KeyframeMotion" && reader.NodeType == XmlNodeType.Element)
  108. {
  109. string innerkeytxt = reader.ReadElementContentAsString();
  110. sceneObject.RootPart.KeyframeMotion =
  111. KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(innerkeytxt));
  112. }
  113. else
  114. sceneObject.RootPart.KeyframeMotion = null;
  115. // Script state may, or may not, exist. Not having any, is NOT
  116. // ever a problem.
  117. sceneObject.LoadScriptState(reader);
  118. sceneObject.InvalidateDeepEffectivePerms();
  119. return sceneObject;
  120. }
  121. /// <summary>
  122. /// Serialize a scene object to the original xml format
  123. /// </summary>
  124. /// <param name="sceneObject"></param>
  125. /// <returns></returns>
  126. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
  127. {
  128. return ToOriginalXmlFormat(sceneObject, true);
  129. }
  130. /// <summary>
  131. /// Serialize a scene object to the original xml format
  132. /// </summary>
  133. /// <param name="sceneObject"></param>
  134. /// <param name="doScriptStates">Control whether script states are also serialized.</para>
  135. /// <returns></returns>
  136. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
  137. {
  138. using (StringWriter sw = new StringWriter())
  139. {
  140. using (XmlTextWriter writer = new XmlTextWriter(sw))
  141. {
  142. ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
  143. }
  144. return sw.ToString();
  145. }
  146. }
  147. /// <summary>
  148. /// Serialize a scene object to the original xml format
  149. /// </summary>
  150. /// <param name="sceneObject"></param>
  151. /// <returns></returns>
  152. public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
  153. {
  154. ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
  155. }
  156. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState)
  157. {
  158. using (StringWriter sw = new StringWriter())
  159. {
  160. using (XmlTextWriter writer = new XmlTextWriter(sw))
  161. {
  162. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  163. ToOriginalXmlFormat(sceneObject, writer, false, true);
  164. writer.WriteRaw(scriptedState);
  165. writer.WriteEndElement();
  166. }
  167. return sw.ToString();
  168. }
  169. }
  170. /// <summary>
  171. /// Serialize a scene object to the original xml format
  172. /// </summary>
  173. /// <param name="sceneObject"></param>
  174. /// <param name="writer"></param>
  175. /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
  176. /// <returns></returns>
  177. public static void ToOriginalXmlFormat(
  178. SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
  179. {
  180. // m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
  181. // int time = System.Environment.TickCount;
  182. if (!noRootElement)
  183. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  184. writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
  185. ToXmlFormat(sceneObject.RootPart, writer);
  186. writer.WriteEndElement();
  187. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  188. SceneObjectPart[] parts = sceneObject.Parts;
  189. for (int i = 0; i < parts.Length; i++)
  190. {
  191. SceneObjectPart part = parts[i];
  192. if (part.UUID != sceneObject.RootPart.UUID)
  193. {
  194. writer.WriteStartElement(String.Empty, "Part", String.Empty);
  195. ToXmlFormat(part, writer);
  196. writer.WriteEndElement();
  197. }
  198. }
  199. writer.WriteEndElement(); // OtherParts
  200. if (sceneObject.RootPart.KeyframeMotion != null)
  201. {
  202. Byte[] data = sceneObject.RootPart.KeyframeMotion.Serialize();
  203. writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
  204. writer.WriteBase64(data, 0, data.Length);
  205. writer.WriteEndElement();
  206. }
  207. if (doScriptStates)
  208. sceneObject.SaveScriptedState(writer);
  209. if (!noRootElement)
  210. writer.WriteEndElement(); // SceneObjectGroup
  211. // m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
  212. }
  213. protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
  214. {
  215. SOPToXml2(writer, part, new Dictionary<string, object>());
  216. }
  217. public static SceneObjectGroup FromXml2Format(string xmlData)
  218. {
  219. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  220. //int time = System.Environment.TickCount;
  221. try
  222. {
  223. XmlDocument doc = new XmlDocument();
  224. doc.XmlResolver=null;
  225. doc.LoadXml(xmlData);
  226. XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart");
  227. if (parts.Count == 0)
  228. {
  229. m_log.Error("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes");
  230. Util.LogFailedXML("[SERIALIZER]:", xmlData);
  231. return null;
  232. }
  233. SceneObjectGroup sceneObject;
  234. using(StringReader sr = new StringReader(parts[0].OuterXml))
  235. {
  236. using(XmlTextReader reader = new XmlTextReader(sr))
  237. {
  238. reader.ProhibitDtd = true;
  239. sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  240. }
  241. }
  242. // Then deal with the rest
  243. SceneObjectPart part;
  244. for (int i = 1; i < parts.Count; i++)
  245. {
  246. using(StringReader sr = new StringReader(parts[i].OuterXml))
  247. {
  248. using(XmlTextReader reader = new XmlTextReader(sr))
  249. {
  250. part = SceneObjectPart.FromXml(reader);
  251. }
  252. }
  253. int originalLinkNum = part.LinkNum;
  254. sceneObject.AddPart(part);
  255. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  256. // We override that here
  257. if (originalLinkNum != 0)
  258. part.LinkNum = originalLinkNum;
  259. }
  260. XmlNodeList keymotion = doc.GetElementsByTagName("KeyframeMotion");
  261. if (keymotion.Count > 0)
  262. sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(keymotion[0].InnerText));
  263. else
  264. sceneObject.RootPart.KeyframeMotion = null;
  265. // Script state may, or may not, exist. Not having any, is NOT
  266. // ever a problem.
  267. sceneObject.LoadScriptState(doc);
  268. // sceneObject.AggregatePerms();
  269. return sceneObject;
  270. }
  271. catch (Exception e)
  272. {
  273. m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
  274. Util.LogFailedXML("[SERIALIZER]:", xmlData);
  275. return null;
  276. }
  277. }
  278. /// <summary>
  279. /// Serialize a scene object to the 'xml2' format.
  280. /// </summary>
  281. /// <param name="sceneObject"></param>
  282. /// <returns></returns>
  283. public static string ToXml2Format(SceneObjectGroup sceneObject)
  284. {
  285. using (StringWriter sw = new StringWriter())
  286. {
  287. using (XmlTextWriter writer = new XmlTextWriter(sw))
  288. {
  289. SOGToXml2(writer, sceneObject, new Dictionary<string,object>());
  290. }
  291. return sw.ToString();
  292. }
  293. }
  294. /// <summary>
  295. /// Modifies a SceneObjectGroup.
  296. /// </summary>
  297. /// <param name="sog">The object</param>
  298. /// <returns>Whether the object was actually modified</returns>
  299. public delegate bool SceneObjectModifier(SceneObjectGroup sog);
  300. /// <summary>
  301. /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing.
  302. /// </summary>
  303. /// <param name="assetId">The object's UUID</param>
  304. /// <param name="data">Serialized data</param>
  305. /// <param name="modifier">The function to run on each SceneObjectGroup</param>
  306. /// <returns>The new serialized object's data, or null if an error occurred</returns>
  307. public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
  308. {
  309. List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
  310. CoalescedSceneObjects coa = null;
  311. string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data));
  312. if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa))
  313. {
  314. // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
  315. if (coa.Objects.Count == 0)
  316. {
  317. m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId);
  318. return null;
  319. }
  320. sceneObjects.AddRange(coa.Objects);
  321. }
  322. else
  323. {
  324. SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData);
  325. if (deserializedObject != null)
  326. {
  327. sceneObjects.Add(deserializedObject);
  328. }
  329. else
  330. {
  331. m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId);
  332. return null;
  333. }
  334. }
  335. bool modified = false;
  336. foreach (SceneObjectGroup sog in sceneObjects)
  337. {
  338. if (modifier(sog))
  339. modified = true;
  340. }
  341. if (modified)
  342. {
  343. if (coa != null)
  344. data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
  345. else
  346. data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0]));
  347. }
  348. return data;
  349. }
  350. #region manual serialization
  351. private static Dictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors
  352. = new Dictionary<string, Action<SceneObjectPart, XmlReader>>();
  353. private static Dictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors
  354. = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>();
  355. private static Dictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors
  356. = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>();
  357. static SceneObjectSerializer()
  358. {
  359. #region SOPXmlProcessors initialization
  360. m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop);
  361. m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID);
  362. m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData);
  363. m_SOPXmlProcessors.Add("FolderID", ProcessFolderID);
  364. m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial);
  365. m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory);
  366. m_SOPXmlProcessors.Add("UUID", ProcessUUID);
  367. m_SOPXmlProcessors.Add("LocalId", ProcessLocalId);
  368. m_SOPXmlProcessors.Add("Name", ProcessName);
  369. m_SOPXmlProcessors.Add("Material", ProcessMaterial);
  370. m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches);
  371. m_SOPXmlProcessors.Add("PassCollisions", ProcessPassCollisions);
  372. m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle);
  373. m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin);
  374. m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition);
  375. m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition);
  376. m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset);
  377. m_SOPXmlProcessors.Add("Velocity", ProcessVelocity);
  378. m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity);
  379. m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration);
  380. m_SOPXmlProcessors.Add("Description", ProcessDescription);
  381. m_SOPXmlProcessors.Add("Color", ProcessColor);
  382. m_SOPXmlProcessors.Add("Text", ProcessText);
  383. m_SOPXmlProcessors.Add("SitName", ProcessSitName);
  384. m_SOPXmlProcessors.Add("TouchName", ProcessTouchName);
  385. m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum);
  386. m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction);
  387. m_SOPXmlProcessors.Add("Shape", ProcessShape);
  388. m_SOPXmlProcessors.Add("Scale", ProcessScale);
  389. m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation);
  390. m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition);
  391. m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL);
  392. m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL);
  393. m_SOPXmlProcessors.Add("ParentID", ProcessParentID);
  394. m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate);
  395. m_SOPXmlProcessors.Add("Category", ProcessCategory);
  396. m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice);
  397. m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType);
  398. m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost);
  399. m_SOPXmlProcessors.Add("GroupID", ProcessGroupID);
  400. m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID);
  401. m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID);
  402. m_SOPXmlProcessors.Add("RezzerID", ProcessRezzerID);
  403. m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask);
  404. m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask);
  405. m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask);
  406. m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask);
  407. m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask);
  408. m_SOPXmlProcessors.Add("Flags", ProcessFlags);
  409. m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound);
  410. m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume);
  411. m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl);
  412. m_SOPXmlProcessors.Add("AttachedPos", ProcessAttachedPos);
  413. m_SOPXmlProcessors.Add("DynAttrs", ProcessDynAttrs);
  414. m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation);
  415. m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem);
  416. m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0);
  417. m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1);
  418. m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
  419. m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
  420. m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
  421. m_SOPXmlProcessors.Add("Buoyancy", ProcessBuoyancy);
  422. m_SOPXmlProcessors.Add("Force", ProcessForce);
  423. m_SOPXmlProcessors.Add("Torque", ProcessTorque);
  424. m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
  425. m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
  426. m_SOPXmlProcessors.Add("PhysicsInertia", ProcessPhysicsInertia);
  427. m_SOPXmlProcessors.Add("RotationAxisLocks", ProcessRotationAxisLocks);
  428. m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
  429. m_SOPXmlProcessors.Add("Density", ProcessDensity);
  430. m_SOPXmlProcessors.Add("Friction", ProcessFriction);
  431. m_SOPXmlProcessors.Add("Bounce", ProcessBounce);
  432. m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier);
  433. m_SOPXmlProcessors.Add("CameraEyeOffset", ProcessCameraEyeOffset);
  434. m_SOPXmlProcessors.Add("CameraAtOffset", ProcessCameraAtOffset);
  435. m_SOPXmlProcessors.Add("SoundID", ProcessSoundID);
  436. m_SOPXmlProcessors.Add("SoundGain", ProcessSoundGain);
  437. m_SOPXmlProcessors.Add("SoundFlags", ProcessSoundFlags);
  438. m_SOPXmlProcessors.Add("SoundRadius", ProcessSoundRadius);
  439. m_SOPXmlProcessors.Add("SoundQueueing", ProcessSoundQueueing);
  440. #endregion
  441. #region TaskInventoryXmlProcessors initialization
  442. m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID);
  443. m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions);
  444. m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate);
  445. m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID);
  446. m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData);
  447. m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription);
  448. m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions);
  449. m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags);
  450. m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID);
  451. m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions);
  452. m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType);
  453. m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID);
  454. m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID);
  455. m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID);
  456. m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName);
  457. m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions);
  458. m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID);
  459. m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions);
  460. m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID);
  461. m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID);
  462. m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter);
  463. m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
  464. m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
  465. m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
  466. #endregion
  467. #region ShapeXmlProcessors initialization
  468. m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve);
  469. m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry);
  470. m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams);
  471. m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin);
  472. m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve);
  473. m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd);
  474. m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset);
  475. m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions);
  476. m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX);
  477. m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY);
  478. m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX);
  479. m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY);
  480. m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew);
  481. m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX);
  482. m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY);
  483. m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist);
  484. m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin);
  485. m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode);
  486. m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin);
  487. m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd);
  488. m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow);
  489. m_ShapeXmlProcessors.Add("Scale", ProcessShpScale);
  490. m_ShapeXmlProcessors.Add("LastAttachPoint", ProcessShpLastAttach);
  491. m_ShapeXmlProcessors.Add("State", ProcessShpState);
  492. m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape);
  493. m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape);
  494. m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture);
  495. m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType);
  496. // Ignore "SculptData"; this element is deprecated
  497. m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness);
  498. m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension);
  499. m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag);
  500. m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity);
  501. m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind);
  502. m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX);
  503. m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY);
  504. m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ);
  505. m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR);
  506. m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG);
  507. m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB);
  508. m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA);
  509. m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius);
  510. m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff);
  511. m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff);
  512. m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity);
  513. m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry);
  514. m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry);
  515. m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry);
  516. m_ShapeXmlProcessors.Add("Media", ProcessShpMedia);
  517. #endregion
  518. }
  519. #region SOPXmlProcessors
  520. private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader)
  521. {
  522. obj.AllowedDrop = Util.ReadBoolean(reader);
  523. }
  524. private static void ProcessCreatorID(SceneObjectPart obj, XmlReader reader)
  525. {
  526. obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
  527. }
  528. private static void ProcessCreatorData(SceneObjectPart obj, XmlReader reader)
  529. {
  530. obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  531. }
  532. private static void ProcessFolderID(SceneObjectPart obj, XmlReader reader)
  533. {
  534. obj.FolderID = Util.ReadUUID(reader, "FolderID");
  535. }
  536. private static void ProcessInventorySerial(SceneObjectPart obj, XmlReader reader)
  537. {
  538. obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty);
  539. }
  540. private static void ProcessTaskInventory(SceneObjectPart obj, XmlReader reader)
  541. {
  542. obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
  543. }
  544. private static void ProcessUUID(SceneObjectPart obj, XmlReader reader)
  545. {
  546. obj.UUID = Util.ReadUUID(reader, "UUID");
  547. }
  548. private static void ProcessLocalId(SceneObjectPart obj, XmlReader reader)
  549. {
  550. obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty);
  551. }
  552. private static void ProcessName(SceneObjectPart obj, XmlReader reader)
  553. {
  554. obj.Name = reader.ReadElementString("Name");
  555. }
  556. private static void ProcessMaterial(SceneObjectPart obj, XmlReader reader)
  557. {
  558. obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty);
  559. }
  560. private static void ProcessPassTouches(SceneObjectPart obj, XmlReader reader)
  561. {
  562. obj.PassTouches = Util.ReadBoolean(reader);
  563. }
  564. private static void ProcessPassCollisions(SceneObjectPart obj, XmlReader reader)
  565. {
  566. obj.PassCollisions = Util.ReadBoolean(reader);
  567. }
  568. private static void ProcessRegionHandle(SceneObjectPart obj, XmlReader reader)
  569. {
  570. obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty);
  571. }
  572. private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlReader reader)
  573. {
  574. obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty);
  575. }
  576. private static void ProcessGroupPosition(SceneObjectPart obj, XmlReader reader)
  577. {
  578. obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
  579. }
  580. private static void ProcessOffsetPosition(SceneObjectPart obj, XmlReader reader)
  581. {
  582. obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
  583. }
  584. private static void ProcessRotationOffset(SceneObjectPart obj, XmlReader reader)
  585. {
  586. obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
  587. }
  588. private static void ProcessVelocity(SceneObjectPart obj, XmlReader reader)
  589. {
  590. obj.Velocity = Util.ReadVector(reader, "Velocity");
  591. }
  592. private static void ProcessAngularVelocity(SceneObjectPart obj, XmlReader reader)
  593. {
  594. obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
  595. }
  596. private static void ProcessAcceleration(SceneObjectPart obj, XmlReader reader)
  597. {
  598. obj.Acceleration = Util.ReadVector(reader, "Acceleration");
  599. }
  600. private static void ProcessDescription(SceneObjectPart obj, XmlReader reader)
  601. {
  602. obj.Description = reader.ReadElementString("Description");
  603. }
  604. private static void ProcessColor(SceneObjectPart obj, XmlReader reader)
  605. {
  606. reader.ReadStartElement("Color");
  607. if (reader.Name == "R")
  608. {
  609. float r = reader.ReadElementContentAsFloat("R", String.Empty);
  610. float g = reader.ReadElementContentAsFloat("G", String.Empty);
  611. float b = reader.ReadElementContentAsFloat("B", String.Empty);
  612. float a = reader.ReadElementContentAsFloat("A", String.Empty);
  613. obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
  614. reader.ReadEndElement();
  615. }
  616. }
  617. private static void ProcessText(SceneObjectPart obj, XmlReader reader)
  618. {
  619. obj.Text = reader.ReadElementString("Text", String.Empty);
  620. }
  621. private static void ProcessSitName(SceneObjectPart obj, XmlReader reader)
  622. {
  623. obj.SitName = reader.ReadElementString("SitName", String.Empty);
  624. }
  625. private static void ProcessTouchName(SceneObjectPart obj, XmlReader reader)
  626. {
  627. obj.TouchName = reader.ReadElementString("TouchName", String.Empty);
  628. }
  629. private static void ProcessLinkNum(SceneObjectPart obj, XmlReader reader)
  630. {
  631. obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty);
  632. }
  633. private static void ProcessClickAction(SceneObjectPart obj, XmlReader reader)
  634. {
  635. obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty);
  636. }
  637. private static void ProcessRotationAxisLocks(SceneObjectPart obj, XmlReader reader)
  638. {
  639. obj.RotationAxisLocks = (byte)reader.ReadElementContentAsInt("RotationAxisLocks", String.Empty);
  640. }
  641. private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlReader reader)
  642. {
  643. obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty);
  644. }
  645. private static void ProcessDensity(SceneObjectPart obj, XmlReader reader)
  646. {
  647. obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty);
  648. }
  649. private static void ProcessFriction(SceneObjectPart obj, XmlReader reader)
  650. {
  651. obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty);
  652. }
  653. private static void ProcessBounce(SceneObjectPart obj, XmlReader reader)
  654. {
  655. obj.Restitution = reader.ReadElementContentAsFloat("Bounce", String.Empty);
  656. }
  657. private static void ProcessGravityModifier(SceneObjectPart obj, XmlReader reader)
  658. {
  659. obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty);
  660. }
  661. private static void ProcessCameraEyeOffset(SceneObjectPart obj, XmlReader reader)
  662. {
  663. obj.SetCameraEyeOffset(Util.ReadVector(reader, "CameraEyeOffset"));
  664. }
  665. private static void ProcessCameraAtOffset(SceneObjectPart obj, XmlReader reader)
  666. {
  667. obj.SetCameraAtOffset(Util.ReadVector(reader, "CameraAtOffset"));
  668. }
  669. private static void ProcessSoundID(SceneObjectPart obj, XmlReader reader)
  670. {
  671. obj.Sound = Util.ReadUUID(reader, "SoundID");
  672. }
  673. private static void ProcessSoundGain(SceneObjectPart obj, XmlReader reader)
  674. {
  675. obj.SoundGain = reader.ReadElementContentAsDouble("SoundGain", String.Empty);
  676. }
  677. private static void ProcessSoundFlags(SceneObjectPart obj, XmlReader reader)
  678. {
  679. obj.SoundFlags = (byte)reader.ReadElementContentAsInt("SoundFlags", String.Empty);
  680. }
  681. private static void ProcessSoundRadius(SceneObjectPart obj, XmlReader reader)
  682. {
  683. obj.SoundRadius = reader.ReadElementContentAsDouble("SoundRadius", String.Empty);
  684. }
  685. private static void ProcessSoundQueueing(SceneObjectPart obj, XmlReader reader)
  686. {
  687. obj.SoundQueueing = Util.ReadBoolean(reader);
  688. }
  689. private static void ProcessVehicle(SceneObjectPart obj, XmlReader reader)
  690. {
  691. SOPVehicle vehicle = SOPVehicle.FromXml2(reader);
  692. if (vehicle == null)
  693. {
  694. obj.VehicleParams = null;
  695. m_log.DebugFormat(
  696. "[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
  697. obj.Name, obj.UUID);
  698. }
  699. else
  700. {
  701. obj.VehicleParams = vehicle;
  702. }
  703. }
  704. private static void ProcessPhysicsInertia(SceneObjectPart obj, XmlReader reader)
  705. {
  706. PhysicsInertiaData pdata = PhysicsInertiaData.FromXml2(reader);
  707. if (pdata == null)
  708. {
  709. obj.PhysicsInertia = null;
  710. m_log.DebugFormat(
  711. "[SceneObjectSerializer]: Parsing PhysicsInertiaData for object part {0} {1} encountered errors. Please see earlier log entries.",
  712. obj.Name, obj.UUID);
  713. }
  714. else
  715. {
  716. obj.PhysicsInertia = pdata;
  717. }
  718. }
  719. private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
  720. {
  721. List<string> errorNodeNames;
  722. obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj);
  723. if (errorNodeNames != null)
  724. {
  725. m_log.DebugFormat(
  726. "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
  727. obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
  728. }
  729. }
  730. private static void ProcessScale(SceneObjectPart obj, XmlReader reader)
  731. {
  732. obj.Scale = Util.ReadVector(reader, "Scale");
  733. }
  734. private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlReader reader)
  735. {
  736. obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
  737. }
  738. private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlReader reader)
  739. {
  740. obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
  741. }
  742. private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlReader reader)
  743. {
  744. obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
  745. }
  746. private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlReader reader)
  747. {
  748. obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
  749. }
  750. private static void ProcessParentID(SceneObjectPart obj, XmlReader reader)
  751. {
  752. string str = reader.ReadElementContentAsString("ParentID", String.Empty);
  753. obj.ParentID = Convert.ToUInt32(str);
  754. }
  755. private static void ProcessCreationDate(SceneObjectPart obj, XmlReader reader)
  756. {
  757. obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
  758. }
  759. private static void ProcessCategory(SceneObjectPart obj, XmlReader reader)
  760. {
  761. obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty);
  762. }
  763. private static void ProcessSalePrice(SceneObjectPart obj, XmlReader reader)
  764. {
  765. obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
  766. }
  767. private static void ProcessObjectSaleType(SceneObjectPart obj, XmlReader reader)
  768. {
  769. obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty);
  770. }
  771. private static void ProcessOwnershipCost(SceneObjectPart obj, XmlReader reader)
  772. {
  773. obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty);
  774. }
  775. private static void ProcessGroupID(SceneObjectPart obj, XmlReader reader)
  776. {
  777. obj.GroupID = Util.ReadUUID(reader, "GroupID");
  778. }
  779. private static void ProcessOwnerID(SceneObjectPart obj, XmlReader reader)
  780. {
  781. obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
  782. }
  783. private static void ProcessLastOwnerID(SceneObjectPart obj, XmlReader reader)
  784. {
  785. obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  786. }
  787. private static void ProcessRezzerID(SceneObjectPart obj, XmlReader reader)
  788. {
  789. obj.RezzerID = Util.ReadUUID(reader, "RezzerID");
  790. }
  791. private static void ProcessBaseMask(SceneObjectPart obj, XmlReader reader)
  792. {
  793. obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty);
  794. }
  795. private static void ProcessOwnerMask(SceneObjectPart obj, XmlReader reader)
  796. {
  797. obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty);
  798. }
  799. private static void ProcessGroupMask(SceneObjectPart obj, XmlReader reader)
  800. {
  801. obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty);
  802. }
  803. private static void ProcessEveryoneMask(SceneObjectPart obj, XmlReader reader)
  804. {
  805. obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty);
  806. }
  807. private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlReader reader)
  808. {
  809. obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty);
  810. }
  811. private static void ProcessFlags(SceneObjectPart obj, XmlReader reader)
  812. {
  813. obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
  814. }
  815. private static void ProcessCollisionSound(SceneObjectPart obj, XmlReader reader)
  816. {
  817. obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
  818. }
  819. private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlReader reader)
  820. {
  821. obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty);
  822. }
  823. private static void ProcessMediaUrl(SceneObjectPart obj, XmlReader reader)
  824. {
  825. obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty);
  826. }
  827. private static void ProcessAttachedPos(SceneObjectPart obj, XmlReader reader)
  828. {
  829. obj.AttachedPos = Util.ReadVector(reader, "AttachedPos");
  830. }
  831. private static void ProcessDynAttrs(SceneObjectPart obj, XmlReader reader)
  832. {
  833. obj.DynAttrs.ReadXml(reader);
  834. }
  835. private static void ProcessTextureAnimation(SceneObjectPart obj, XmlReader reader)
  836. {
  837. obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty));
  838. }
  839. private static void ProcessParticleSystem(SceneObjectPart obj, XmlReader reader)
  840. {
  841. obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty));
  842. }
  843. private static void ProcessPayPrice0(SceneObjectPart obj, XmlReader reader)
  844. {
  845. obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty);
  846. }
  847. private static void ProcessPayPrice1(SceneObjectPart obj, XmlReader reader)
  848. {
  849. obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty);
  850. }
  851. private static void ProcessPayPrice2(SceneObjectPart obj, XmlReader reader)
  852. {
  853. obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty);
  854. }
  855. private static void ProcessPayPrice3(SceneObjectPart obj, XmlReader reader)
  856. {
  857. obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty);
  858. }
  859. private static void ProcessPayPrice4(SceneObjectPart obj, XmlReader reader)
  860. {
  861. obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
  862. }
  863. private static void ProcessBuoyancy(SceneObjectPart obj, XmlReader reader)
  864. {
  865. obj.Buoyancy = (float)reader.ReadElementContentAsFloat("Buoyancy", String.Empty);
  866. }
  867. private static void ProcessForce(SceneObjectPart obj, XmlReader reader)
  868. {
  869. obj.Force = Util.ReadVector(reader, "Force");
  870. }
  871. private static void ProcessTorque(SceneObjectPart obj, XmlReader reader)
  872. {
  873. obj.Torque = Util.ReadVector(reader, "Torque");
  874. }
  875. private static void ProcessVolumeDetectActive(SceneObjectPart obj, XmlReader reader)
  876. {
  877. obj.VolumeDetectActive = Util.ReadBoolean(reader);
  878. }
  879. #endregion
  880. #region TaskInventoryXmlProcessors
  881. private static void ProcessTIAssetID(TaskInventoryItem item, XmlReader reader)
  882. {
  883. item.AssetID = Util.ReadUUID(reader, "AssetID");
  884. }
  885. private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlReader reader)
  886. {
  887. item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
  888. }
  889. private static void ProcessTICreationDate(TaskInventoryItem item, XmlReader reader)
  890. {
  891. item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty);
  892. }
  893. private static void ProcessTICreatorID(TaskInventoryItem item, XmlReader reader)
  894. {
  895. item.CreatorID = Util.ReadUUID(reader, "CreatorID");
  896. }
  897. private static void ProcessTICreatorData(TaskInventoryItem item, XmlReader reader)
  898. {
  899. item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  900. }
  901. private static void ProcessTIDescription(TaskInventoryItem item, XmlReader reader)
  902. {
  903. item.Description = reader.ReadElementContentAsString("Description", String.Empty);
  904. }
  905. private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlReader reader)
  906. {
  907. item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty);
  908. }
  909. private static void ProcessTIFlags(TaskInventoryItem item, XmlReader reader)
  910. {
  911. item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
  912. }
  913. private static void ProcessTIGroupID(TaskInventoryItem item, XmlReader reader)
  914. {
  915. item.GroupID = Util.ReadUUID(reader, "GroupID");
  916. }
  917. private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlReader reader)
  918. {
  919. item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty);
  920. }
  921. private static void ProcessTIInvType(TaskInventoryItem item, XmlReader reader)
  922. {
  923. item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
  924. }
  925. private static void ProcessTIItemID(TaskInventoryItem item, XmlReader reader)
  926. {
  927. item.ItemID = Util.ReadUUID(reader, "ItemID");
  928. }
  929. private static void ProcessTIOldItemID(TaskInventoryItem item, XmlReader reader)
  930. {
  931. item.OldItemID = Util.ReadUUID(reader, "OldItemID");
  932. }
  933. private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlReader reader)
  934. {
  935. item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  936. }
  937. private static void ProcessTIName(TaskInventoryItem item, XmlReader reader)
  938. {
  939. item.Name = reader.ReadElementContentAsString("Name", String.Empty);
  940. }
  941. private static void ProcessTINextPermissions(TaskInventoryItem item, XmlReader reader)
  942. {
  943. item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
  944. }
  945. private static void ProcessTIOwnerID(TaskInventoryItem item, XmlReader reader)
  946. {
  947. item.OwnerID = Util.ReadUUID(reader, "OwnerID");
  948. }
  949. private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlReader reader)
  950. {
  951. item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
  952. }
  953. private static void ProcessTIParentID(TaskInventoryItem item, XmlReader reader)
  954. {
  955. item.ParentID = Util.ReadUUID(reader, "ParentID");
  956. }
  957. private static void ProcessTIParentPartID(TaskInventoryItem item, XmlReader reader)
  958. {
  959. item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
  960. }
  961. private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlReader reader)
  962. {
  963. item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
  964. }
  965. private static void ProcessTIPermsMask(TaskInventoryItem item, XmlReader reader)
  966. {
  967. item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty);
  968. }
  969. private static void ProcessTIType(TaskInventoryItem item, XmlReader reader)
  970. {
  971. item.Type = reader.ReadElementContentAsInt("Type", String.Empty);
  972. }
  973. private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlReader reader)
  974. {
  975. item.OwnerChanged = Util.ReadBoolean(reader);
  976. }
  977. #endregion
  978. #region ShapeXmlProcessors
  979. private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlReader reader)
  980. {
  981. shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty);
  982. }
  983. private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlReader reader)
  984. {
  985. byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
  986. shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
  987. }
  988. private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlReader reader)
  989. {
  990. shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
  991. }
  992. private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlReader reader)
  993. {
  994. shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty);
  995. }
  996. private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlReader reader)
  997. {
  998. shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty);
  999. }
  1000. private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlReader reader)
  1001. {
  1002. shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty);
  1003. }
  1004. private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlReader reader)
  1005. {
  1006. shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty);
  1007. }
  1008. private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlReader reader)
  1009. {
  1010. shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty);
  1011. }
  1012. private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlReader reader)
  1013. {
  1014. shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty);
  1015. }
  1016. private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlReader reader)
  1017. {
  1018. shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty);
  1019. }
  1020. private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlReader reader)
  1021. {
  1022. shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty);
  1023. }
  1024. private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlReader reader)
  1025. {
  1026. shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty);
  1027. }
  1028. private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlReader reader)
  1029. {
  1030. shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty);
  1031. }
  1032. private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlReader reader)
  1033. {
  1034. shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty);
  1035. }
  1036. private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlReader reader)
  1037. {
  1038. shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty);
  1039. }
  1040. private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlReader reader)
  1041. {
  1042. shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty);
  1043. }
  1044. private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlReader reader)
  1045. {
  1046. shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty);
  1047. }
  1048. private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlReader reader)
  1049. {
  1050. shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty);
  1051. }
  1052. private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlReader reader)
  1053. {
  1054. shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty);
  1055. }
  1056. private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlReader reader)
  1057. {
  1058. shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty);
  1059. }
  1060. private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlReader reader)
  1061. {
  1062. shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty);
  1063. }
  1064. private static void ProcessShpScale(PrimitiveBaseShape shp, XmlReader reader)
  1065. {
  1066. shp.Scale = Util.ReadVector(reader, "Scale");
  1067. }
  1068. private static void ProcessShpState(PrimitiveBaseShape shp, XmlReader reader)
  1069. {
  1070. shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty);
  1071. }
  1072. private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlReader reader)
  1073. {
  1074. shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty);
  1075. }
  1076. private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlReader reader)
  1077. {
  1078. shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
  1079. }
  1080. private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlReader reader)
  1081. {
  1082. shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
  1083. }
  1084. private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlReader reader)
  1085. {
  1086. shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
  1087. }
  1088. private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlReader reader)
  1089. {
  1090. shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty);
  1091. }
  1092. private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlReader reader)
  1093. {
  1094. shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty);
  1095. }
  1096. private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlReader reader)
  1097. {
  1098. shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty);
  1099. }
  1100. private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlReader reader)
  1101. {
  1102. shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty);
  1103. }
  1104. private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlReader reader)
  1105. {
  1106. shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty);
  1107. }
  1108. private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlReader reader)
  1109. {
  1110. shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty);
  1111. }
  1112. private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlReader reader)
  1113. {
  1114. shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty);
  1115. }
  1116. private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlReader reader)
  1117. {
  1118. shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty);
  1119. }
  1120. private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlReader reader)
  1121. {
  1122. shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty);
  1123. }
  1124. private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlReader reader)
  1125. {
  1126. shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty);
  1127. }
  1128. private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlReader reader)
  1129. {
  1130. shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty);
  1131. }
  1132. private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlReader reader)
  1133. {
  1134. shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty);
  1135. }
  1136. private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlReader reader)
  1137. {
  1138. shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty);
  1139. }
  1140. private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlReader reader)
  1141. {
  1142. shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty);
  1143. }
  1144. private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlReader reader)
  1145. {
  1146. shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty);
  1147. }
  1148. private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlReader reader)
  1149. {
  1150. shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty);
  1151. }
  1152. private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlReader reader)
  1153. {
  1154. shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty);
  1155. }
  1156. private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlReader reader)
  1157. {
  1158. shp.FlexiEntry = Util.ReadBoolean(reader);
  1159. }
  1160. private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlReader reader)
  1161. {
  1162. shp.LightEntry = Util.ReadBoolean(reader);
  1163. }
  1164. private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlReader reader)
  1165. {
  1166. shp.SculptEntry = Util.ReadBoolean(reader);
  1167. }
  1168. private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlReader reader)
  1169. {
  1170. string value = String.Empty;
  1171. try
  1172. {
  1173. // The STANDARD content of Media elemet is escaped XML string (with &gt; etc).
  1174. value = reader.ReadElementContentAsString("Media", String.Empty);
  1175. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  1176. }
  1177. catch (XmlException)
  1178. {
  1179. // There are versions of OAR files that contain unquoted XML.
  1180. // ie ONE comercial fork that never wanted their oars to be read by our code
  1181. try
  1182. {
  1183. value = reader.ReadInnerXml();
  1184. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  1185. }
  1186. catch
  1187. {
  1188. m_log.ErrorFormat("[SERIALIZER] Failed parsing halcyon MOAP information");
  1189. }
  1190. }
  1191. }
  1192. #endregion
  1193. ////////// Write /////////
  1194. public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
  1195. {
  1196. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  1197. SOPToXml2(writer, sog.RootPart, options);
  1198. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  1199. sog.ForEachPart(delegate(SceneObjectPart sop)
  1200. {
  1201. if (sop.UUID != sog.RootPart.UUID)
  1202. SOPToXml2(writer, sop, options);
  1203. });
  1204. writer.WriteEndElement();
  1205. if (sog.RootPart.KeyframeMotion != null)
  1206. {
  1207. Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
  1208. writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
  1209. writer.WriteBase64(data, 0, data.Length);
  1210. writer.WriteEndElement();
  1211. }
  1212. writer.WriteEndElement();
  1213. }
  1214. public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
  1215. {
  1216. writer.WriteStartElement("SceneObjectPart");
  1217. writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  1218. writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
  1219. writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
  1220. WriteUUID(writer, "CreatorID", sop.CreatorID, options);
  1221. if (!string.IsNullOrEmpty(sop.CreatorData))
  1222. writer.WriteElementString("CreatorData", sop.CreatorData);
  1223. else if (options.ContainsKey("home"))
  1224. {
  1225. if (m_UserManagement == null)
  1226. m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
  1227. string name = m_UserManagement.GetUserName(sop.CreatorID);
  1228. writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
  1229. }
  1230. WriteUUID(writer, "FolderID", sop.FolderID, options);
  1231. writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
  1232. WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
  1233. WriteUUID(writer, "UUID", sop.UUID, options);
  1234. writer.WriteElementString("LocalId", sop.LocalId.ToString());
  1235. writer.WriteElementString("Name", sop.Name);
  1236. writer.WriteElementString("Material", sop.Material.ToString());
  1237. writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
  1238. writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower());
  1239. writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
  1240. writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
  1241. WriteVector(writer, "GroupPosition", sop.GroupPosition);
  1242. WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
  1243. WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
  1244. WriteVector(writer, "Velocity", sop.Velocity);
  1245. WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
  1246. WriteVector(writer, "Acceleration", sop.Acceleration);
  1247. writer.WriteElementString("Description", sop.Description);
  1248. writer.WriteStartElement("Color");
  1249. writer.WriteElementString("R", sop.Color.R.ToString(Culture.FormatProvider));
  1250. writer.WriteElementString("G", sop.Color.G.ToString(Culture.FormatProvider));
  1251. writer.WriteElementString("B", sop.Color.B.ToString(Culture.FormatProvider));
  1252. writer.WriteElementString("A", sop.Color.A.ToString(Culture.FormatProvider));
  1253. writer.WriteEndElement();
  1254. writer.WriteElementString("Text", sop.Text);
  1255. writer.WriteElementString("SitName", sop.SitName);
  1256. writer.WriteElementString("TouchName", sop.TouchName);
  1257. writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
  1258. writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
  1259. WriteShape(writer, sop.Shape, options);
  1260. WriteVector(writer, "Scale", sop.Scale);
  1261. WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
  1262. WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
  1263. WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
  1264. WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
  1265. writer.WriteElementString("ParentID", sop.ParentID.ToString());
  1266. writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
  1267. writer.WriteElementString("Category", sop.Category.ToString());
  1268. writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
  1269. writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
  1270. writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
  1271. UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.GroupID;
  1272. WriteUUID(writer, "GroupID", groupID, options);
  1273. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
  1274. WriteUUID(writer, "OwnerID", ownerID, options);
  1275. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
  1276. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1277. UUID rezzerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.RezzerID;
  1278. WriteUUID(writer, "RezzerID", rezzerID, options);
  1279. writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
  1280. writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
  1281. writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
  1282. writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
  1283. writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
  1284. WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
  1285. WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
  1286. writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString(Culture.FormatProvider));
  1287. if (sop.MediaUrl != null)
  1288. writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
  1289. WriteVector(writer, "AttachedPos", sop.AttachedPos);
  1290. if (sop.DynAttrs.CountNamespaces > 0)
  1291. {
  1292. writer.WriteStartElement("DynAttrs");
  1293. sop.DynAttrs.WriteXml(writer);
  1294. writer.WriteEndElement();
  1295. }
  1296. WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
  1297. WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
  1298. writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
  1299. writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
  1300. writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
  1301. writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
  1302. writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
  1303. writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString(Culture.FormatProvider));
  1304. WriteVector(writer, "Force", sop.Force);
  1305. WriteVector(writer, "Torque", sop.Torque);
  1306. writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
  1307. if (sop.VehicleParams != null)
  1308. sop.VehicleParams.ToXml2(writer);
  1309. if (sop.PhysicsInertia != null)
  1310. sop.PhysicsInertia.ToXml2(writer);
  1311. if(sop.RotationAxisLocks != 0)
  1312. writer.WriteElementString("RotationAxisLocks", sop.RotationAxisLocks.ToString().ToLower());
  1313. writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
  1314. if (sop.Density != 1000.0f)
  1315. writer.WriteElementString("Density", sop.Density.ToString(Culture.FormatProvider));
  1316. if (sop.Friction != 0.6f)
  1317. writer.WriteElementString("Friction", sop.Friction.ToString(Culture.FormatProvider));
  1318. if (sop.Restitution != 0.5f)
  1319. writer.WriteElementString("Bounce", sop.Restitution.ToString(Culture.FormatProvider));
  1320. if (sop.GravityModifier != 1.0f)
  1321. writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString(Culture.FormatProvider));
  1322. WriteVector(writer, "CameraEyeOffset", sop.GetCameraEyeOffset());
  1323. WriteVector(writer, "CameraAtOffset", sop.GetCameraAtOffset());
  1324. // if (sop.Sound != UUID.Zero) force it till sop crossing does clear it on child prim
  1325. {
  1326. WriteUUID(writer, "SoundID", sop.Sound, options);
  1327. writer.WriteElementString("SoundGain", sop.SoundGain.ToString(Culture.FormatProvider));
  1328. writer.WriteElementString("SoundFlags", sop.SoundFlags.ToString().ToLower());
  1329. writer.WriteElementString("SoundRadius", sop.SoundRadius.ToString(Culture.FormatProvider));
  1330. }
  1331. writer.WriteElementString("SoundQueueing", sop.SoundQueueing.ToString().ToLower());
  1332. writer.WriteEndElement();
  1333. }
  1334. static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
  1335. {
  1336. writer.WriteStartElement(name);
  1337. if (options.ContainsKey("old-guids"))
  1338. writer.WriteElementString("Guid", id.ToString());
  1339. else
  1340. writer.WriteElementString("UUID", id.ToString());
  1341. writer.WriteEndElement();
  1342. }
  1343. static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
  1344. {
  1345. writer.WriteStartElement(name);
  1346. writer.WriteElementString("X", vec.X.ToString(Culture.FormatProvider));
  1347. writer.WriteElementString("Y", vec.Y.ToString(Culture.FormatProvider));
  1348. writer.WriteElementString("Z", vec.Z.ToString(Culture.FormatProvider));
  1349. writer.WriteEndElement();
  1350. }
  1351. static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
  1352. {
  1353. writer.WriteStartElement(name);
  1354. writer.WriteElementString("X", quat.X.ToString(Culture.FormatProvider));
  1355. writer.WriteElementString("Y", quat.Y.ToString(Culture.FormatProvider));
  1356. writer.WriteElementString("Z", quat.Z.ToString(Culture.FormatProvider));
  1357. writer.WriteElementString("W", quat.W.ToString(Culture.FormatProvider));
  1358. writer.WriteEndElement();
  1359. }
  1360. static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
  1361. {
  1362. writer.WriteStartElement(name);
  1363. byte[] d;
  1364. if (data != null)
  1365. d = data;
  1366. else
  1367. d = Utils.EmptyBytes;
  1368. writer.WriteBase64(d, 0, d.Length);
  1369. writer.WriteEndElement(); // name
  1370. }
  1371. static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
  1372. {
  1373. // Older versions of serialization can't cope with commas, so we eliminate the commas
  1374. writer.WriteElementString(name, flagsStr.Replace(",", ""));
  1375. }
  1376. public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
  1377. {
  1378. if (tinv.Count > 0) // otherwise skip this
  1379. {
  1380. writer.WriteStartElement("TaskInventory");
  1381. foreach (TaskInventoryItem item in tinv.Values)
  1382. {
  1383. writer.WriteStartElement("TaskInventoryItem");
  1384. WriteUUID(writer, "AssetID", item.AssetID, options);
  1385. writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
  1386. writer.WriteElementString("CreationDate", item.CreationDate.ToString());
  1387. WriteUUID(writer, "CreatorID", item.CreatorID, options);
  1388. if (!string.IsNullOrEmpty(item.CreatorData))
  1389. writer.WriteElementString("CreatorData", item.CreatorData);
  1390. else if (options.ContainsKey("home"))
  1391. {
  1392. if (m_UserManagement == null)
  1393. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  1394. string name = m_UserManagement.GetUserName(item.CreatorID);
  1395. writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
  1396. }
  1397. writer.WriteElementString("Description", item.Description);
  1398. writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
  1399. writer.WriteElementString("Flags", item.Flags.ToString());
  1400. UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.GroupID;
  1401. WriteUUID(writer, "GroupID", groupID, options);
  1402. writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
  1403. writer.WriteElementString("InvType", item.InvType.ToString());
  1404. WriteUUID(writer, "ItemID", item.ItemID, options);
  1405. WriteUUID(writer, "OldItemID", item.OldItemID, options);
  1406. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
  1407. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1408. writer.WriteElementString("Name", item.Name);
  1409. writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
  1410. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
  1411. WriteUUID(writer, "OwnerID", ownerID, options);
  1412. writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
  1413. WriteUUID(writer, "ParentID", item.ParentID, options);
  1414. WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
  1415. WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
  1416. writer.WriteElementString("PermsMask", item.PermsMask.ToString());
  1417. writer.WriteElementString("Type", item.Type.ToString());
  1418. bool ownerChanged = options.ContainsKey("wipe-owners") ? false : item.OwnerChanged;
  1419. writer.WriteElementString("OwnerChanged", ownerChanged.ToString().ToLower());
  1420. writer.WriteEndElement(); // TaskInventoryItem
  1421. }
  1422. writer.WriteEndElement(); // TaskInventory
  1423. }
  1424. }
  1425. public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
  1426. {
  1427. if (shp != null)
  1428. {
  1429. writer.WriteStartElement("Shape");
  1430. writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
  1431. writer.WriteStartElement("TextureEntry");
  1432. byte[] te;
  1433. if (shp.TextureEntry != null)
  1434. te = shp.TextureEntry;
  1435. else
  1436. te = Utils.EmptyBytes;
  1437. writer.WriteBase64(te, 0, te.Length);
  1438. writer.WriteEndElement(); // TextureEntry
  1439. writer.WriteStartElement("ExtraParams");
  1440. byte[] ep;
  1441. if (shp.ExtraParams != null)
  1442. ep = shp.ExtraParams;
  1443. else
  1444. ep = Utils.EmptyBytes;
  1445. writer.WriteBase64(ep, 0, ep.Length);
  1446. writer.WriteEndElement(); // ExtraParams
  1447. writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
  1448. writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
  1449. writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
  1450. writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
  1451. writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
  1452. writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
  1453. writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
  1454. writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
  1455. writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
  1456. writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
  1457. writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
  1458. writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
  1459. writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
  1460. writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
  1461. writer.WriteElementString("PCode", shp.PCode.ToString());
  1462. writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
  1463. writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
  1464. writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
  1465. writer.WriteElementString("State", shp.State.ToString());
  1466. writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString());
  1467. WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
  1468. WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
  1469. WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
  1470. writer.WriteElementString("SculptType", shp.SculptType.ToString());
  1471. // Don't serialize SculptData. It's just a copy of the asset, which can be loaded separately using 'SculptTexture'.
  1472. writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
  1473. writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString(Culture.FormatProvider));
  1474. writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString(Culture.FormatProvider));
  1475. writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString(Culture.FormatProvider));
  1476. writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString(Culture.FormatProvider));
  1477. writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString(Culture.FormatProvider));
  1478. writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString(Culture.FormatProvider));
  1479. writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString(Culture.FormatProvider));
  1480. writer.WriteElementString("LightColorR", shp.LightColorR.ToString(Culture.FormatProvider));
  1481. writer.WriteElementString("LightColorG", shp.LightColorG.ToString(Culture.FormatProvider));
  1482. writer.WriteElementString("LightColorB", shp.LightColorB.ToString(Culture.FormatProvider));
  1483. writer.WriteElementString("LightColorA", shp.LightColorA.ToString(Culture.FormatProvider));
  1484. writer.WriteElementString("LightRadius", shp.LightRadius.ToString(Culture.FormatProvider));
  1485. writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString(Culture.FormatProvider));
  1486. writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString(Culture.FormatProvider));
  1487. writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString(Culture.FormatProvider));
  1488. writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
  1489. writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
  1490. writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
  1491. if (shp.Media != null)
  1492. writer.WriteElementString("Media", shp.Media.ToXml());
  1493. writer.WriteEndElement(); // Shape
  1494. }
  1495. }
  1496. public static SceneObjectPart Xml2ToSOP(XmlReader reader)
  1497. {
  1498. SceneObjectPart obj = new SceneObjectPart();
  1499. reader.ReadStartElement("SceneObjectPart");
  1500. bool errors = ExternalRepresentationUtils.ExecuteReadProcessors(
  1501. obj,
  1502. m_SOPXmlProcessors,
  1503. reader,
  1504. (o, nodeName, e) => {
  1505. m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in object {1} {2} ",
  1506. nodeName, ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID), e);
  1507. });
  1508. if (errors)
  1509. throw new XmlException(string.Format("Error parsing object {0} {1}", obj.Name, obj.UUID));
  1510. reader.ReadEndElement(); // SceneObjectPart
  1511. obj.AggregateInnerPerms();
  1512. // m_log.DebugFormat("[SceneObjectSerializer]: parsed SOP {0} {1}", obj.Name, obj.UUID);
  1513. return obj;
  1514. }
  1515. public static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name)
  1516. {
  1517. TaskInventoryDictionary tinv = new TaskInventoryDictionary();
  1518. reader.ReadStartElement(name, String.Empty);
  1519. while (reader.Name == "TaskInventoryItem")
  1520. {
  1521. reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
  1522. TaskInventoryItem item = new TaskInventoryItem();
  1523. ExternalRepresentationUtils.ExecuteReadProcessors(
  1524. item,
  1525. m_TaskInventoryXmlProcessors,
  1526. reader);
  1527. reader.ReadEndElement(); // TaskInventoryItem
  1528. tinv.Add(item.ItemID, item);
  1529. }
  1530. if (reader.NodeType == XmlNodeType.EndElement)
  1531. reader.ReadEndElement(); // TaskInventory
  1532. return tinv;
  1533. }
  1534. /// <summary>
  1535. /// Read a shape from xml input
  1536. /// </summary>
  1537. /// <param name="reader"></param>
  1538. /// <param name="name">The name of the xml element containing the shape</param>
  1539. /// <param name="errors">a list containing the failing node names. If no failures then null.</param>
  1540. /// <returns>The shape parsed</returns>
  1541. public static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List<string> errorNodeNames, SceneObjectPart obj)
  1542. {
  1543. List<string> internalErrorNodeNames = null;
  1544. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  1545. if (reader.IsEmptyElement)
  1546. {
  1547. reader.Read();
  1548. errorNodeNames = null;
  1549. return shape;
  1550. }
  1551. reader.ReadStartElement(name, String.Empty); // Shape
  1552. ExternalRepresentationUtils.ExecuteReadProcessors(
  1553. shape,
  1554. m_ShapeXmlProcessors,
  1555. reader,
  1556. (o, nodeName, e) => {
  1557. m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in Shape property of object {1} {2} ",
  1558. nodeName, obj.Name, obj.UUID), e);
  1559. if (internalErrorNodeNames == null)
  1560. internalErrorNodeNames = new List<string>();
  1561. internalErrorNodeNames.Add(nodeName);
  1562. });
  1563. reader.ReadEndElement(); // Shape
  1564. errorNodeNames = internalErrorNodeNames;
  1565. return shape;
  1566. }
  1567. #endregion
  1568. }
  1569. }