SceneObjectSerializer.cs 74 KB

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