SceneObjectSerializer.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635
  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. namespace OpenSim.Region.Framework.Scenes.Serialization
  41. {
  42. /// <summary>
  43. /// Serialize and deserialize scene objects.
  44. /// </summary>
  45. /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
  46. /// right now - hopefully this isn't forever.
  47. public class SceneObjectSerializer
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private static IUserManagement m_UserManagement;
  51. /// <summary>
  52. /// Deserialize a scene object from the original xml format
  53. /// </summary>
  54. /// <param name="xmlData"></param>
  55. /// <returns>The scene object deserialized. Null on failure.</returns>
  56. public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
  57. {
  58. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  59. //int time = System.Environment.TickCount;
  60. try
  61. {
  62. StringReader sr;
  63. XmlTextReader reader;
  64. XmlNodeList parts;
  65. XmlDocument doc;
  66. int linkNum;
  67. doc = new XmlDocument();
  68. doc.LoadXml(xmlData);
  69. parts = doc.GetElementsByTagName("RootPart");
  70. if (parts.Count == 0)
  71. throw new Exception("Invalid Xml format - no root part");
  72. sr = new StringReader(parts[0].InnerXml);
  73. reader = new XmlTextReader(sr);
  74. SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  75. reader.Close();
  76. sr.Close();
  77. parts = doc.GetElementsByTagName("Part");
  78. for (int i = 0; i < parts.Count; i++)
  79. {
  80. sr = new StringReader(parts[i].InnerXml);
  81. reader = new XmlTextReader(sr);
  82. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  83. linkNum = part.LinkNum;
  84. sceneObject.AddPart(part);
  85. part.LinkNum = linkNum;
  86. part.TrimPermissions();
  87. reader.Close();
  88. sr.Close();
  89. }
  90. // Script state may, or may not, exist. Not having any, is NOT
  91. // ever a problem.
  92. sceneObject.LoadScriptState(doc);
  93. return sceneObject;
  94. }
  95. catch (Exception e)
  96. {
  97. m_log.ErrorFormat(
  98. "[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
  99. return null;
  100. }
  101. }
  102. /// <summary>
  103. /// Serialize a scene object to the original xml format
  104. /// </summary>
  105. /// <param name="sceneObject"></param>
  106. /// <returns></returns>
  107. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
  108. {
  109. return ToOriginalXmlFormat(sceneObject, true);
  110. }
  111. /// <summary>
  112. /// Serialize a scene object to the original xml format
  113. /// </summary>
  114. /// <param name="sceneObject"></param>
  115. /// <param name="doScriptStates">Control whether script states are also serialized.</para>
  116. /// <returns></returns>
  117. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
  118. {
  119. using (StringWriter sw = new StringWriter())
  120. {
  121. using (XmlTextWriter writer = new XmlTextWriter(sw))
  122. {
  123. ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
  124. }
  125. return sw.ToString();
  126. }
  127. }
  128. /// <summary>
  129. /// Serialize a scene object to the original xml format
  130. /// </summary>
  131. /// <param name="sceneObject"></param>
  132. /// <returns></returns>
  133. public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
  134. {
  135. ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
  136. }
  137. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState)
  138. {
  139. using (StringWriter sw = new StringWriter())
  140. {
  141. using (XmlTextWriter writer = new XmlTextWriter(sw))
  142. {
  143. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  144. ToOriginalXmlFormat(sceneObject, writer, false, true);
  145. writer.WriteRaw(scriptedState);
  146. writer.WriteEndElement();
  147. }
  148. return sw.ToString();
  149. }
  150. }
  151. /// <summary>
  152. /// Serialize a scene object to the original xml format
  153. /// </summary>
  154. /// <param name="sceneObject"></param>
  155. /// <param name="writer"></param>
  156. /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
  157. /// <returns></returns>
  158. public static void ToOriginalXmlFormat(
  159. SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
  160. {
  161. // m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
  162. // int time = System.Environment.TickCount;
  163. if (!noRootElement)
  164. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  165. writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
  166. ToXmlFormat(sceneObject.RootPart, writer);
  167. writer.WriteEndElement();
  168. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  169. SceneObjectPart[] parts = sceneObject.Parts;
  170. for (int i = 0; i < parts.Length; i++)
  171. {
  172. SceneObjectPart part = parts[i];
  173. if (part.UUID != sceneObject.RootPart.UUID)
  174. {
  175. writer.WriteStartElement(String.Empty, "Part", String.Empty);
  176. ToXmlFormat(part, writer);
  177. writer.WriteEndElement();
  178. }
  179. }
  180. writer.WriteEndElement(); // OtherParts
  181. if (doScriptStates)
  182. sceneObject.SaveScriptedState(writer);
  183. if (!noRootElement)
  184. writer.WriteEndElement(); // SceneObjectGroup
  185. // m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
  186. }
  187. protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
  188. {
  189. SOPToXml2(writer, part, new Dictionary<string, object>());
  190. }
  191. public static SceneObjectGroup FromXml2Format(string xmlData)
  192. {
  193. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  194. //int time = System.Environment.TickCount;
  195. try
  196. {
  197. XmlDocument doc = new XmlDocument();
  198. doc.LoadXml(xmlData);
  199. XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart");
  200. if (parts.Count == 0)
  201. {
  202. m_log.ErrorFormat("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes. xml was " + xmlData);
  203. return null;
  204. }
  205. StringReader sr = new StringReader(parts[0].OuterXml);
  206. XmlTextReader reader = new XmlTextReader(sr);
  207. SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  208. reader.Close();
  209. sr.Close();
  210. // Then deal with the rest
  211. for (int i = 1; i < parts.Count; i++)
  212. {
  213. sr = new StringReader(parts[i].OuterXml);
  214. reader = new XmlTextReader(sr);
  215. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  216. int originalLinkNum = part.LinkNum;
  217. sceneObject.AddPart(part);
  218. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  219. // We override that here
  220. if (originalLinkNum != 0)
  221. part.LinkNum = originalLinkNum;
  222. reader.Close();
  223. sr.Close();
  224. }
  225. XmlNodeList keymotion = doc.GetElementsByTagName("KeyframeMotion");
  226. if (keymotion.Count > 0)
  227. sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(keymotion[0].InnerText));
  228. else
  229. sceneObject.RootPart.KeyframeMotion = null;
  230. // Script state may, or may not, exist. Not having any, is NOT
  231. // ever a problem.
  232. sceneObject.LoadScriptState(doc);
  233. return sceneObject;
  234. }
  235. catch (Exception e)
  236. {
  237. m_log.ErrorFormat("[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
  238. return null;
  239. }
  240. }
  241. /// <summary>
  242. /// Serialize a scene object to the 'xml2' format.
  243. /// </summary>
  244. /// <param name="sceneObject"></param>
  245. /// <returns></returns>
  246. public static string ToXml2Format(SceneObjectGroup sceneObject)
  247. {
  248. using (StringWriter sw = new StringWriter())
  249. {
  250. using (XmlTextWriter writer = new XmlTextWriter(sw))
  251. {
  252. SOGToXml2(writer, sceneObject, new Dictionary<string,object>());
  253. }
  254. return sw.ToString();
  255. }
  256. }
  257. #region manual serialization
  258. private static Dictionary<string, Action<SceneObjectPart, XmlTextReader>> m_SOPXmlProcessors
  259. = new Dictionary<string, Action<SceneObjectPart, XmlTextReader>>();
  260. private static Dictionary<string, Action<TaskInventoryItem, XmlTextReader>> m_TaskInventoryXmlProcessors
  261. = new Dictionary<string, Action<TaskInventoryItem, XmlTextReader>>();
  262. private static Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>> m_ShapeXmlProcessors
  263. = new Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>>();
  264. static SceneObjectSerializer()
  265. {
  266. #region SOPXmlProcessors initialization
  267. m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop);
  268. m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID);
  269. m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData);
  270. m_SOPXmlProcessors.Add("FolderID", ProcessFolderID);
  271. m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial);
  272. m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory);
  273. m_SOPXmlProcessors.Add("UUID", ProcessUUID);
  274. m_SOPXmlProcessors.Add("LocalId", ProcessLocalId);
  275. m_SOPXmlProcessors.Add("Name", ProcessName);
  276. m_SOPXmlProcessors.Add("Material", ProcessMaterial);
  277. m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches);
  278. m_SOPXmlProcessors.Add("PassCollisions", ProcessPassCollisions);
  279. m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle);
  280. m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin);
  281. m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition);
  282. m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition);
  283. m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset);
  284. m_SOPXmlProcessors.Add("Velocity", ProcessVelocity);
  285. m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity);
  286. m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration);
  287. m_SOPXmlProcessors.Add("Description", ProcessDescription);
  288. m_SOPXmlProcessors.Add("Color", ProcessColor);
  289. m_SOPXmlProcessors.Add("Text", ProcessText);
  290. m_SOPXmlProcessors.Add("SitName", ProcessSitName);
  291. m_SOPXmlProcessors.Add("TouchName", ProcessTouchName);
  292. m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum);
  293. m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction);
  294. m_SOPXmlProcessors.Add("Shape", ProcessShape);
  295. m_SOPXmlProcessors.Add("Scale", ProcessScale);
  296. m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation);
  297. m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition);
  298. m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL);
  299. m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL);
  300. m_SOPXmlProcessors.Add("ParentID", ProcessParentID);
  301. m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate);
  302. m_SOPXmlProcessors.Add("Category", ProcessCategory);
  303. m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice);
  304. m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType);
  305. m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost);
  306. m_SOPXmlProcessors.Add("GroupID", ProcessGroupID);
  307. m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID);
  308. m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID);
  309. m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask);
  310. m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask);
  311. m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask);
  312. m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask);
  313. m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask);
  314. m_SOPXmlProcessors.Add("Flags", ProcessFlags);
  315. m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound);
  316. m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume);
  317. m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl);
  318. m_SOPXmlProcessors.Add("AttachedPos", ProcessAttachedPos);
  319. m_SOPXmlProcessors.Add("DynAttrs", ProcessDynAttrs);
  320. m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation);
  321. m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem);
  322. m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0);
  323. m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1);
  324. m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
  325. m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
  326. m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
  327. m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
  328. m_SOPXmlProcessors.Add("Density", ProcessDensity);
  329. m_SOPXmlProcessors.Add("Friction", ProcessFriction);
  330. m_SOPXmlProcessors.Add("Bounce", ProcessBounce);
  331. m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier);
  332. #endregion
  333. #region TaskInventoryXmlProcessors initialization
  334. m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID);
  335. m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions);
  336. m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate);
  337. m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID);
  338. m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData);
  339. m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription);
  340. m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions);
  341. m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags);
  342. m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID);
  343. m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions);
  344. m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType);
  345. m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID);
  346. m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID);
  347. m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID);
  348. m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName);
  349. m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions);
  350. m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID);
  351. m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions);
  352. m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID);
  353. m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID);
  354. m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter);
  355. m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
  356. m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
  357. m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
  358. #endregion
  359. #region ShapeXmlProcessors initialization
  360. m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve);
  361. m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry);
  362. m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams);
  363. m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin);
  364. m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve);
  365. m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd);
  366. m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset);
  367. m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions);
  368. m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX);
  369. m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY);
  370. m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX);
  371. m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY);
  372. m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew);
  373. m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX);
  374. m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY);
  375. m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist);
  376. m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin);
  377. m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode);
  378. m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin);
  379. m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd);
  380. m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow);
  381. m_ShapeXmlProcessors.Add("Scale", ProcessShpScale);
  382. m_ShapeXmlProcessors.Add("LastAttachPoint", ProcessShpLastAttach);
  383. m_ShapeXmlProcessors.Add("State", ProcessShpState);
  384. m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape);
  385. m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape);
  386. m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture);
  387. m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType);
  388. m_ShapeXmlProcessors.Add("SculptData", ProcessShpSculptData);
  389. m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness);
  390. m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension);
  391. m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag);
  392. m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity);
  393. m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind);
  394. m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX);
  395. m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY);
  396. m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ);
  397. m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR);
  398. m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG);
  399. m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB);
  400. m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA);
  401. m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius);
  402. m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff);
  403. m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff);
  404. m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity);
  405. m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry);
  406. m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry);
  407. m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry);
  408. m_ShapeXmlProcessors.Add("Media", ProcessShpMedia);
  409. #endregion
  410. }
  411. #region SOPXmlProcessors
  412. private static void ProcessAllowedDrop(SceneObjectPart obj, XmlTextReader reader)
  413. {
  414. obj.AllowedDrop = Util.ReadBoolean(reader);
  415. }
  416. private static void ProcessCreatorID(SceneObjectPart obj, XmlTextReader reader)
  417. {
  418. obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
  419. }
  420. private static void ProcessCreatorData(SceneObjectPart obj, XmlTextReader reader)
  421. {
  422. obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  423. }
  424. private static void ProcessFolderID(SceneObjectPart obj, XmlTextReader reader)
  425. {
  426. obj.FolderID = Util.ReadUUID(reader, "FolderID");
  427. }
  428. private static void ProcessInventorySerial(SceneObjectPart obj, XmlTextReader reader)
  429. {
  430. obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty);
  431. }
  432. private static void ProcessTaskInventory(SceneObjectPart obj, XmlTextReader reader)
  433. {
  434. obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
  435. }
  436. private static void ProcessUUID(SceneObjectPart obj, XmlTextReader reader)
  437. {
  438. obj.UUID = Util.ReadUUID(reader, "UUID");
  439. }
  440. private static void ProcessLocalId(SceneObjectPart obj, XmlTextReader reader)
  441. {
  442. obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty);
  443. }
  444. private static void ProcessName(SceneObjectPart obj, XmlTextReader reader)
  445. {
  446. obj.Name = reader.ReadElementString("Name");
  447. }
  448. private static void ProcessMaterial(SceneObjectPart obj, XmlTextReader reader)
  449. {
  450. obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty);
  451. }
  452. private static void ProcessPassTouches(SceneObjectPart obj, XmlTextReader reader)
  453. {
  454. obj.PassTouches = Util.ReadBoolean(reader);
  455. }
  456. private static void ProcessPassCollisions(SceneObjectPart obj, XmlTextReader reader)
  457. {
  458. obj.PassCollisions = Util.ReadBoolean(reader);
  459. }
  460. private static void ProcessRegionHandle(SceneObjectPart obj, XmlTextReader reader)
  461. {
  462. obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty);
  463. }
  464. private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlTextReader reader)
  465. {
  466. obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty);
  467. }
  468. private static void ProcessGroupPosition(SceneObjectPart obj, XmlTextReader reader)
  469. {
  470. obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
  471. }
  472. private static void ProcessOffsetPosition(SceneObjectPart obj, XmlTextReader reader)
  473. {
  474. obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
  475. }
  476. private static void ProcessRotationOffset(SceneObjectPart obj, XmlTextReader reader)
  477. {
  478. obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
  479. }
  480. private static void ProcessVelocity(SceneObjectPart obj, XmlTextReader reader)
  481. {
  482. obj.Velocity = Util.ReadVector(reader, "Velocity");
  483. }
  484. private static void ProcessAngularVelocity(SceneObjectPart obj, XmlTextReader reader)
  485. {
  486. obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
  487. }
  488. private static void ProcessAcceleration(SceneObjectPart obj, XmlTextReader reader)
  489. {
  490. obj.Acceleration = Util.ReadVector(reader, "Acceleration");
  491. }
  492. private static void ProcessDescription(SceneObjectPart obj, XmlTextReader reader)
  493. {
  494. obj.Description = reader.ReadElementString("Description");
  495. }
  496. private static void ProcessColor(SceneObjectPart obj, XmlTextReader reader)
  497. {
  498. reader.ReadStartElement("Color");
  499. if (reader.Name == "R")
  500. {
  501. float r = reader.ReadElementContentAsFloat("R", String.Empty);
  502. float g = reader.ReadElementContentAsFloat("G", String.Empty);
  503. float b = reader.ReadElementContentAsFloat("B", String.Empty);
  504. float a = reader.ReadElementContentAsFloat("A", String.Empty);
  505. obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
  506. reader.ReadEndElement();
  507. }
  508. }
  509. private static void ProcessText(SceneObjectPart obj, XmlTextReader reader)
  510. {
  511. obj.Text = reader.ReadElementString("Text", String.Empty);
  512. }
  513. private static void ProcessSitName(SceneObjectPart obj, XmlTextReader reader)
  514. {
  515. obj.SitName = reader.ReadElementString("SitName", String.Empty);
  516. }
  517. private static void ProcessTouchName(SceneObjectPart obj, XmlTextReader reader)
  518. {
  519. obj.TouchName = reader.ReadElementString("TouchName", String.Empty);
  520. }
  521. private static void ProcessLinkNum(SceneObjectPart obj, XmlTextReader reader)
  522. {
  523. obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty);
  524. }
  525. private static void ProcessClickAction(SceneObjectPart obj, XmlTextReader reader)
  526. {
  527. obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty);
  528. }
  529. private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlTextReader reader)
  530. {
  531. obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty);
  532. }
  533. private static void ProcessDensity(SceneObjectPart obj, XmlTextReader reader)
  534. {
  535. obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty);
  536. }
  537. private static void ProcessFriction(SceneObjectPart obj, XmlTextReader reader)
  538. {
  539. obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty);
  540. }
  541. private static void ProcessBounce(SceneObjectPart obj, XmlTextReader reader)
  542. {
  543. obj.Restitution = reader.ReadElementContentAsFloat("Bounce", String.Empty);
  544. }
  545. private static void ProcessGravityModifier(SceneObjectPart obj, XmlTextReader reader)
  546. {
  547. obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty);
  548. }
  549. private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader)
  550. {
  551. List<string> errorNodeNames;
  552. obj.Shape = ReadShape(reader, "Shape", out errorNodeNames);
  553. if (errorNodeNames != null)
  554. {
  555. m_log.DebugFormat(
  556. "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
  557. obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
  558. }
  559. }
  560. private static void ProcessScale(SceneObjectPart obj, XmlTextReader reader)
  561. {
  562. obj.Scale = Util.ReadVector(reader, "Scale");
  563. }
  564. private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlTextReader reader)
  565. {
  566. obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
  567. }
  568. private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlTextReader reader)
  569. {
  570. obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
  571. }
  572. private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlTextReader reader)
  573. {
  574. obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
  575. }
  576. private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlTextReader reader)
  577. {
  578. obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
  579. }
  580. private static void ProcessParentID(SceneObjectPart obj, XmlTextReader reader)
  581. {
  582. string str = reader.ReadElementContentAsString("ParentID", String.Empty);
  583. obj.ParentID = Convert.ToUInt32(str);
  584. }
  585. private static void ProcessCreationDate(SceneObjectPart obj, XmlTextReader reader)
  586. {
  587. obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
  588. }
  589. private static void ProcessCategory(SceneObjectPart obj, XmlTextReader reader)
  590. {
  591. obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty);
  592. }
  593. private static void ProcessSalePrice(SceneObjectPart obj, XmlTextReader reader)
  594. {
  595. obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
  596. }
  597. private static void ProcessObjectSaleType(SceneObjectPart obj, XmlTextReader reader)
  598. {
  599. obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty);
  600. }
  601. private static void ProcessOwnershipCost(SceneObjectPart obj, XmlTextReader reader)
  602. {
  603. obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty);
  604. }
  605. private static void ProcessGroupID(SceneObjectPart obj, XmlTextReader reader)
  606. {
  607. obj.GroupID = Util.ReadUUID(reader, "GroupID");
  608. }
  609. private static void ProcessOwnerID(SceneObjectPart obj, XmlTextReader reader)
  610. {
  611. obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
  612. }
  613. private static void ProcessLastOwnerID(SceneObjectPart obj, XmlTextReader reader)
  614. {
  615. obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  616. }
  617. private static void ProcessBaseMask(SceneObjectPart obj, XmlTextReader reader)
  618. {
  619. obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty);
  620. }
  621. private static void ProcessOwnerMask(SceneObjectPart obj, XmlTextReader reader)
  622. {
  623. obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty);
  624. }
  625. private static void ProcessGroupMask(SceneObjectPart obj, XmlTextReader reader)
  626. {
  627. obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty);
  628. }
  629. private static void ProcessEveryoneMask(SceneObjectPart obj, XmlTextReader reader)
  630. {
  631. obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty);
  632. }
  633. private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlTextReader reader)
  634. {
  635. obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty);
  636. }
  637. private static void ProcessFlags(SceneObjectPart obj, XmlTextReader reader)
  638. {
  639. obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
  640. }
  641. private static void ProcessCollisionSound(SceneObjectPart obj, XmlTextReader reader)
  642. {
  643. obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
  644. }
  645. private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlTextReader reader)
  646. {
  647. obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty);
  648. }
  649. private static void ProcessMediaUrl(SceneObjectPart obj, XmlTextReader reader)
  650. {
  651. obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty);
  652. }
  653. private static void ProcessAttachedPos(SceneObjectPart obj, XmlTextReader reader)
  654. {
  655. obj.AttachedPos = Util.ReadVector(reader, "AttachedPos");
  656. }
  657. private static void ProcessDynAttrs(SceneObjectPart obj, XmlTextReader reader)
  658. {
  659. obj.DynAttrs.ReadXml(reader);
  660. }
  661. private static void ProcessTextureAnimation(SceneObjectPart obj, XmlTextReader reader)
  662. {
  663. obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty));
  664. }
  665. private static void ProcessParticleSystem(SceneObjectPart obj, XmlTextReader reader)
  666. {
  667. obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty));
  668. }
  669. private static void ProcessPayPrice0(SceneObjectPart obj, XmlTextReader reader)
  670. {
  671. obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty);
  672. }
  673. private static void ProcessPayPrice1(SceneObjectPart obj, XmlTextReader reader)
  674. {
  675. obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty);
  676. }
  677. private static void ProcessPayPrice2(SceneObjectPart obj, XmlTextReader reader)
  678. {
  679. obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty);
  680. }
  681. private static void ProcessPayPrice3(SceneObjectPart obj, XmlTextReader reader)
  682. {
  683. obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty);
  684. }
  685. private static void ProcessPayPrice4(SceneObjectPart obj, XmlTextReader reader)
  686. {
  687. obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
  688. }
  689. #endregion
  690. #region TaskInventoryXmlProcessors
  691. private static void ProcessTIAssetID(TaskInventoryItem item, XmlTextReader reader)
  692. {
  693. item.AssetID = Util.ReadUUID(reader, "AssetID");
  694. }
  695. private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlTextReader reader)
  696. {
  697. item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
  698. }
  699. private static void ProcessTICreationDate(TaskInventoryItem item, XmlTextReader reader)
  700. {
  701. item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty);
  702. }
  703. private static void ProcessTICreatorID(TaskInventoryItem item, XmlTextReader reader)
  704. {
  705. item.CreatorID = Util.ReadUUID(reader, "CreatorID");
  706. }
  707. private static void ProcessTICreatorData(TaskInventoryItem item, XmlTextReader reader)
  708. {
  709. item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  710. }
  711. private static void ProcessTIDescription(TaskInventoryItem item, XmlTextReader reader)
  712. {
  713. item.Description = reader.ReadElementContentAsString("Description", String.Empty);
  714. }
  715. private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlTextReader reader)
  716. {
  717. item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty);
  718. }
  719. private static void ProcessTIFlags(TaskInventoryItem item, XmlTextReader reader)
  720. {
  721. item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
  722. }
  723. private static void ProcessTIGroupID(TaskInventoryItem item, XmlTextReader reader)
  724. {
  725. item.GroupID = Util.ReadUUID(reader, "GroupID");
  726. }
  727. private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlTextReader reader)
  728. {
  729. item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty);
  730. }
  731. private static void ProcessTIInvType(TaskInventoryItem item, XmlTextReader reader)
  732. {
  733. item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
  734. }
  735. private static void ProcessTIItemID(TaskInventoryItem item, XmlTextReader reader)
  736. {
  737. item.ItemID = Util.ReadUUID(reader, "ItemID");
  738. }
  739. private static void ProcessTIOldItemID(TaskInventoryItem item, XmlTextReader reader)
  740. {
  741. item.OldItemID = Util.ReadUUID(reader, "OldItemID");
  742. }
  743. private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlTextReader reader)
  744. {
  745. item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  746. }
  747. private static void ProcessTIName(TaskInventoryItem item, XmlTextReader reader)
  748. {
  749. item.Name = reader.ReadElementContentAsString("Name", String.Empty);
  750. }
  751. private static void ProcessTINextPermissions(TaskInventoryItem item, XmlTextReader reader)
  752. {
  753. item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
  754. }
  755. private static void ProcessTIOwnerID(TaskInventoryItem item, XmlTextReader reader)
  756. {
  757. item.OwnerID = Util.ReadUUID(reader, "OwnerID");
  758. }
  759. private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlTextReader reader)
  760. {
  761. item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
  762. }
  763. private static void ProcessTIParentID(TaskInventoryItem item, XmlTextReader reader)
  764. {
  765. item.ParentID = Util.ReadUUID(reader, "ParentID");
  766. }
  767. private static void ProcessTIParentPartID(TaskInventoryItem item, XmlTextReader reader)
  768. {
  769. item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
  770. }
  771. private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlTextReader reader)
  772. {
  773. item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
  774. }
  775. private static void ProcessTIPermsMask(TaskInventoryItem item, XmlTextReader reader)
  776. {
  777. item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty);
  778. }
  779. private static void ProcessTIType(TaskInventoryItem item, XmlTextReader reader)
  780. {
  781. item.Type = reader.ReadElementContentAsInt("Type", String.Empty);
  782. }
  783. private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlTextReader reader)
  784. {
  785. item.OwnerChanged = Util.ReadBoolean(reader);
  786. }
  787. #endregion
  788. #region ShapeXmlProcessors
  789. private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlTextReader reader)
  790. {
  791. shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty);
  792. }
  793. private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  794. {
  795. byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
  796. shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
  797. }
  798. private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlTextReader reader)
  799. {
  800. shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
  801. }
  802. private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  803. {
  804. shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty);
  805. }
  806. private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlTextReader reader)
  807. {
  808. shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty);
  809. }
  810. private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlTextReader reader)
  811. {
  812. shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty);
  813. }
  814. private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlTextReader reader)
  815. {
  816. shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty);
  817. }
  818. private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlTextReader reader)
  819. {
  820. shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty);
  821. }
  822. private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlTextReader reader)
  823. {
  824. shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty);
  825. }
  826. private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlTextReader reader)
  827. {
  828. shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty);
  829. }
  830. private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlTextReader reader)
  831. {
  832. shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty);
  833. }
  834. private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlTextReader reader)
  835. {
  836. shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty);
  837. }
  838. private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlTextReader reader)
  839. {
  840. shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty);
  841. }
  842. private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlTextReader reader)
  843. {
  844. shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty);
  845. }
  846. private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlTextReader reader)
  847. {
  848. shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty);
  849. }
  850. private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlTextReader reader)
  851. {
  852. shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty);
  853. }
  854. private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  855. {
  856. shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty);
  857. }
  858. private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlTextReader reader)
  859. {
  860. shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty);
  861. }
  862. private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  863. {
  864. shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty);
  865. }
  866. private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlTextReader reader)
  867. {
  868. shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty);
  869. }
  870. private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlTextReader reader)
  871. {
  872. shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty);
  873. }
  874. private static void ProcessShpScale(PrimitiveBaseShape shp, XmlTextReader reader)
  875. {
  876. shp.Scale = Util.ReadVector(reader, "Scale");
  877. }
  878. private static void ProcessShpState(PrimitiveBaseShape shp, XmlTextReader reader)
  879. {
  880. shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty);
  881. }
  882. private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlTextReader reader)
  883. {
  884. shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty);
  885. }
  886. private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlTextReader reader)
  887. {
  888. shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
  889. }
  890. private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlTextReader reader)
  891. {
  892. shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
  893. }
  894. private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlTextReader reader)
  895. {
  896. shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
  897. }
  898. private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlTextReader reader)
  899. {
  900. shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty);
  901. }
  902. private static void ProcessShpSculptData(PrimitiveBaseShape shp, XmlTextReader reader)
  903. {
  904. // m_log.DebugFormat("[SCENE OBJECT SERIALIZER]: Setting sculpt data length {0}", shp.SculptData.Length);
  905. shp.SculptData = Convert.FromBase64String(reader.ReadElementString("SculptData"));
  906. }
  907. private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlTextReader reader)
  908. {
  909. shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty);
  910. }
  911. private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlTextReader reader)
  912. {
  913. shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty);
  914. }
  915. private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlTextReader reader)
  916. {
  917. shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty);
  918. }
  919. private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlTextReader reader)
  920. {
  921. shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty);
  922. }
  923. private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlTextReader reader)
  924. {
  925. shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty);
  926. }
  927. private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlTextReader reader)
  928. {
  929. shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty);
  930. }
  931. private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlTextReader reader)
  932. {
  933. shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty);
  934. }
  935. private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlTextReader reader)
  936. {
  937. shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty);
  938. }
  939. private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlTextReader reader)
  940. {
  941. shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty);
  942. }
  943. private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlTextReader reader)
  944. {
  945. shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty);
  946. }
  947. private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlTextReader reader)
  948. {
  949. shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty);
  950. }
  951. private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlTextReader reader)
  952. {
  953. shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty);
  954. }
  955. private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlTextReader reader)
  956. {
  957. shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty);
  958. }
  959. private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlTextReader reader)
  960. {
  961. shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty);
  962. }
  963. private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlTextReader reader)
  964. {
  965. shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty);
  966. }
  967. private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlTextReader reader)
  968. {
  969. shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty);
  970. }
  971. private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  972. {
  973. shp.FlexiEntry = Util.ReadBoolean(reader);
  974. }
  975. private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  976. {
  977. shp.LightEntry = Util.ReadBoolean(reader);
  978. }
  979. private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  980. {
  981. shp.SculptEntry = Util.ReadBoolean(reader);
  982. }
  983. private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlTextReader reader)
  984. {
  985. string value = reader.ReadElementContentAsString("Media", String.Empty);
  986. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  987. }
  988. #endregion
  989. ////////// Write /////////
  990. public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
  991. {
  992. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  993. SOPToXml2(writer, sog.RootPart, options);
  994. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  995. sog.ForEachPart(delegate(SceneObjectPart sop)
  996. {
  997. if (sop.UUID != sog.RootPart.UUID)
  998. SOPToXml2(writer, sop, options);
  999. });
  1000. writer.WriteEndElement();
  1001. if (sog.RootPart.KeyframeMotion != null)
  1002. {
  1003. Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
  1004. writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
  1005. writer.WriteBase64(data, 0, data.Length);
  1006. writer.WriteEndElement();
  1007. }
  1008. writer.WriteEndElement();
  1009. }
  1010. public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
  1011. {
  1012. writer.WriteStartElement("SceneObjectPart");
  1013. writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  1014. writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
  1015. writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
  1016. WriteUUID(writer, "CreatorID", sop.CreatorID, options);
  1017. if (!string.IsNullOrEmpty(sop.CreatorData))
  1018. writer.WriteElementString("CreatorData", sop.CreatorData);
  1019. else if (options.ContainsKey("home"))
  1020. {
  1021. if (m_UserManagement == null)
  1022. m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
  1023. string name = m_UserManagement.GetUserName(sop.CreatorID);
  1024. writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name);
  1025. }
  1026. WriteUUID(writer, "FolderID", sop.FolderID, options);
  1027. writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
  1028. WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
  1029. WriteUUID(writer, "UUID", sop.UUID, options);
  1030. writer.WriteElementString("LocalId", sop.LocalId.ToString());
  1031. writer.WriteElementString("Name", sop.Name);
  1032. writer.WriteElementString("Material", sop.Material.ToString());
  1033. writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
  1034. writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower());
  1035. writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
  1036. writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
  1037. WriteVector(writer, "GroupPosition", sop.GroupPosition);
  1038. WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
  1039. WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
  1040. WriteVector(writer, "Velocity", sop.Velocity);
  1041. WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
  1042. WriteVector(writer, "Acceleration", sop.Acceleration);
  1043. writer.WriteElementString("Description", sop.Description);
  1044. writer.WriteStartElement("Color");
  1045. writer.WriteElementString("R", sop.Color.R.ToString(Utils.EnUsCulture));
  1046. writer.WriteElementString("G", sop.Color.G.ToString(Utils.EnUsCulture));
  1047. writer.WriteElementString("B", sop.Color.B.ToString(Utils.EnUsCulture));
  1048. writer.WriteElementString("A", sop.Color.A.ToString(Utils.EnUsCulture));
  1049. writer.WriteEndElement();
  1050. writer.WriteElementString("Text", sop.Text);
  1051. writer.WriteElementString("SitName", sop.SitName);
  1052. writer.WriteElementString("TouchName", sop.TouchName);
  1053. writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
  1054. writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
  1055. WriteShape(writer, sop.Shape, options);
  1056. WriteVector(writer, "Scale", sop.Scale);
  1057. WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
  1058. WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
  1059. WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
  1060. WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
  1061. writer.WriteElementString("ParentID", sop.ParentID.ToString());
  1062. writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
  1063. writer.WriteElementString("Category", sop.Category.ToString());
  1064. writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
  1065. writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
  1066. writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
  1067. WriteUUID(writer, "GroupID", sop.GroupID, options);
  1068. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
  1069. WriteUUID(writer, "OwnerID", ownerID, options);
  1070. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
  1071. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1072. writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
  1073. writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
  1074. writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
  1075. writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
  1076. writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
  1077. WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
  1078. WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
  1079. writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString());
  1080. if (sop.MediaUrl != null)
  1081. writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
  1082. WriteVector(writer, "AttachedPos", sop.AttachedPos);
  1083. if (sop.DynAttrs.CountNamespaces > 0)
  1084. {
  1085. writer.WriteStartElement("DynAttrs");
  1086. sop.DynAttrs.WriteXml(writer);
  1087. writer.WriteEndElement();
  1088. }
  1089. WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
  1090. WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
  1091. writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
  1092. writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
  1093. writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
  1094. writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
  1095. writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
  1096. if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType())
  1097. writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
  1098. if (sop.Density != 1000.0f)
  1099. writer.WriteElementString("Density", sop.Density.ToString().ToLower());
  1100. if (sop.Friction != 0.6f)
  1101. writer.WriteElementString("Friction", sop.Friction.ToString().ToLower());
  1102. if (sop.Restitution != 0.5f)
  1103. writer.WriteElementString("Bounce", sop.Restitution.ToString().ToLower());
  1104. if (sop.GravityModifier != 1.0f)
  1105. writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower());
  1106. writer.WriteEndElement();
  1107. }
  1108. static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
  1109. {
  1110. writer.WriteStartElement(name);
  1111. if (options.ContainsKey("old-guids"))
  1112. writer.WriteElementString("Guid", id.ToString());
  1113. else
  1114. writer.WriteElementString("UUID", id.ToString());
  1115. writer.WriteEndElement();
  1116. }
  1117. static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
  1118. {
  1119. writer.WriteStartElement(name);
  1120. writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture));
  1121. writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture));
  1122. writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture));
  1123. writer.WriteEndElement();
  1124. }
  1125. static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
  1126. {
  1127. writer.WriteStartElement(name);
  1128. writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture));
  1129. writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture));
  1130. writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture));
  1131. writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture));
  1132. writer.WriteEndElement();
  1133. }
  1134. static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
  1135. {
  1136. writer.WriteStartElement(name);
  1137. byte[] d;
  1138. if (data != null)
  1139. d = data;
  1140. else
  1141. d = Utils.EmptyBytes;
  1142. writer.WriteBase64(d, 0, d.Length);
  1143. writer.WriteEndElement(); // name
  1144. }
  1145. static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
  1146. {
  1147. // Older versions of serialization can't cope with commas, so we eliminate the commas
  1148. writer.WriteElementString(name, flagsStr.Replace(",", ""));
  1149. }
  1150. public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
  1151. {
  1152. if (tinv.Count > 0) // otherwise skip this
  1153. {
  1154. writer.WriteStartElement("TaskInventory");
  1155. foreach (TaskInventoryItem item in tinv.Values)
  1156. {
  1157. writer.WriteStartElement("TaskInventoryItem");
  1158. WriteUUID(writer, "AssetID", item.AssetID, options);
  1159. writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
  1160. writer.WriteElementString("CreationDate", item.CreationDate.ToString());
  1161. WriteUUID(writer, "CreatorID", item.CreatorID, options);
  1162. if (!string.IsNullOrEmpty(item.CreatorData))
  1163. writer.WriteElementString("CreatorData", item.CreatorData);
  1164. else if (options.ContainsKey("home"))
  1165. {
  1166. if (m_UserManagement == null)
  1167. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  1168. string name = m_UserManagement.GetUserName(item.CreatorID);
  1169. writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name);
  1170. }
  1171. writer.WriteElementString("Description", item.Description);
  1172. writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
  1173. writer.WriteElementString("Flags", item.Flags.ToString());
  1174. WriteUUID(writer, "GroupID", item.GroupID, options);
  1175. writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
  1176. writer.WriteElementString("InvType", item.InvType.ToString());
  1177. WriteUUID(writer, "ItemID", item.ItemID, options);
  1178. WriteUUID(writer, "OldItemID", item.OldItemID, options);
  1179. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
  1180. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1181. writer.WriteElementString("Name", item.Name);
  1182. writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
  1183. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
  1184. WriteUUID(writer, "OwnerID", ownerID, options);
  1185. writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
  1186. WriteUUID(writer, "ParentID", item.ParentID, options);
  1187. WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
  1188. WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
  1189. writer.WriteElementString("PermsMask", item.PermsMask.ToString());
  1190. writer.WriteElementString("Type", item.Type.ToString());
  1191. writer.WriteElementString("OwnerChanged", item.OwnerChanged.ToString().ToLower());
  1192. writer.WriteEndElement(); // TaskInventoryItem
  1193. }
  1194. writer.WriteEndElement(); // TaskInventory
  1195. }
  1196. }
  1197. public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
  1198. {
  1199. if (shp != null)
  1200. {
  1201. writer.WriteStartElement("Shape");
  1202. writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
  1203. writer.WriteStartElement("TextureEntry");
  1204. byte[] te;
  1205. if (shp.TextureEntry != null)
  1206. te = shp.TextureEntry;
  1207. else
  1208. te = Utils.EmptyBytes;
  1209. writer.WriteBase64(te, 0, te.Length);
  1210. writer.WriteEndElement(); // TextureEntry
  1211. writer.WriteStartElement("ExtraParams");
  1212. byte[] ep;
  1213. if (shp.ExtraParams != null)
  1214. ep = shp.ExtraParams;
  1215. else
  1216. ep = Utils.EmptyBytes;
  1217. writer.WriteBase64(ep, 0, ep.Length);
  1218. writer.WriteEndElement(); // ExtraParams
  1219. writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
  1220. writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
  1221. writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
  1222. writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
  1223. writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
  1224. writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
  1225. writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
  1226. writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
  1227. writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
  1228. writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
  1229. writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
  1230. writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
  1231. writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
  1232. writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
  1233. writer.WriteElementString("PCode", shp.PCode.ToString());
  1234. writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
  1235. writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
  1236. writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
  1237. writer.WriteElementString("State", shp.State.ToString());
  1238. writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString());
  1239. WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
  1240. WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
  1241. WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
  1242. writer.WriteElementString("SculptType", shp.SculptType.ToString());
  1243. writer.WriteStartElement("SculptData");
  1244. byte[] sd;
  1245. if (shp.SculptData != null)
  1246. sd = shp.SculptData;
  1247. else
  1248. sd = Utils.EmptyBytes;
  1249. writer.WriteBase64(sd, 0, sd.Length);
  1250. writer.WriteEndElement(); // SculptData
  1251. writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
  1252. writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString());
  1253. writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString());
  1254. writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString());
  1255. writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString());
  1256. writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString());
  1257. writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString());
  1258. writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString());
  1259. writer.WriteElementString("LightColorR", shp.LightColorR.ToString());
  1260. writer.WriteElementString("LightColorG", shp.LightColorG.ToString());
  1261. writer.WriteElementString("LightColorB", shp.LightColorB.ToString());
  1262. writer.WriteElementString("LightColorA", shp.LightColorA.ToString());
  1263. writer.WriteElementString("LightRadius", shp.LightRadius.ToString());
  1264. writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString());
  1265. writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString());
  1266. writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString());
  1267. writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
  1268. writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
  1269. writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
  1270. if (shp.Media != null)
  1271. writer.WriteElementString("Media", shp.Media.ToXml());
  1272. writer.WriteEndElement(); // Shape
  1273. }
  1274. }
  1275. public static SceneObjectPart Xml2ToSOP(XmlTextReader reader)
  1276. {
  1277. SceneObjectPart obj = new SceneObjectPart();
  1278. reader.ReadStartElement("SceneObjectPart");
  1279. ExternalRepresentationUtils.ExecuteReadProcessors(
  1280. obj,
  1281. m_SOPXmlProcessors,
  1282. reader,
  1283. (o, nodeName, e)
  1284. => m_log.DebugFormat(
  1285. "[SceneObjectSerializer]: Exception while parsing {0} in object {1} {2}: {3}{4}",
  1286. ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID, nodeName, e.Message, e.StackTrace));
  1287. reader.ReadEndElement(); // SceneObjectPart
  1288. //m_log.DebugFormat("[XXX]: parsed SOP {0} - {1}", obj.Name, obj.UUID);
  1289. return obj;
  1290. }
  1291. public static TaskInventoryDictionary ReadTaskInventory(XmlTextReader reader, string name)
  1292. {
  1293. TaskInventoryDictionary tinv = new TaskInventoryDictionary();
  1294. if (reader.IsEmptyElement)
  1295. {
  1296. reader.Read();
  1297. return tinv;
  1298. }
  1299. reader.ReadStartElement(name, String.Empty);
  1300. while (reader.Name == "TaskInventoryItem")
  1301. {
  1302. reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
  1303. TaskInventoryItem item = new TaskInventoryItem();
  1304. ExternalRepresentationUtils.ExecuteReadProcessors(
  1305. item,
  1306. m_TaskInventoryXmlProcessors,
  1307. reader);
  1308. reader.ReadEndElement(); // TaskInventoryItem
  1309. tinv.Add(item.ItemID, item);
  1310. }
  1311. if (reader.NodeType == XmlNodeType.EndElement)
  1312. reader.ReadEndElement(); // TaskInventory
  1313. return tinv;
  1314. }
  1315. /// <summary>
  1316. /// Read a shape from xml input
  1317. /// </summary>
  1318. /// <param name="reader"></param>
  1319. /// <param name="name">The name of the xml element containing the shape</param>
  1320. /// <param name="errors">a list containing the failing node names. If no failures then null.</param>
  1321. /// <returns>The shape parsed</returns>
  1322. public static PrimitiveBaseShape ReadShape(XmlTextReader reader, string name, out List<string> errorNodeNames)
  1323. {
  1324. List<string> internalErrorNodeNames = null;
  1325. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  1326. if (reader.IsEmptyElement)
  1327. {
  1328. reader.Read();
  1329. errorNodeNames = null;
  1330. return shape;
  1331. }
  1332. reader.ReadStartElement(name, String.Empty); // Shape
  1333. ExternalRepresentationUtils.ExecuteReadProcessors(
  1334. shape,
  1335. m_ShapeXmlProcessors,
  1336. reader,
  1337. (o, nodeName, e)
  1338. =>
  1339. {
  1340. // m_log.DebugFormat(
  1341. // "[SceneObjectSerializer]: Exception while parsing Shape property {0}: {1}{2}",
  1342. // nodeName, e.Message, e.StackTrace);
  1343. if (internalErrorNodeNames == null)
  1344. internalErrorNodeNames = new List<string>();
  1345. internalErrorNodeNames.Add(nodeName);
  1346. }
  1347. );
  1348. reader.ReadEndElement(); // Shape
  1349. errorNodeNames = internalErrorNodeNames;
  1350. return shape;
  1351. }
  1352. #endregion
  1353. }
  1354. }