1
0

SceneObjectSerializer.cs 84 KB

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