ObjectSnapshot.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 OpenSim 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.Reflection;
  30. using System.Xml;
  31. using log4net;
  32. using OpenSim.Region.DataSnapshot.Interfaces;
  33. using OpenSim.Region.Environment.Interfaces;
  34. using OpenSim.Region.Environment.Scenes;
  35. using OpenSim.Region.Environment.Modules.World.Land;
  36. using OpenSim.Framework;
  37. using OpenMetaverse;
  38. namespace OpenSim.Region.DataSnapshot.Providers
  39. {
  40. public class ObjectSnapshot : IDataSnapshotProvider
  41. {
  42. private Scene m_scene = null;
  43. // private DataSnapshotManager m_parent = null;
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private bool m_stale = true;
  46. public void Initialize(Scene scene, DataSnapshotManager parent)
  47. {
  48. m_scene = scene;
  49. // m_parent = parent;
  50. //To check for staleness, we must catch all incoming client packets.
  51. m_scene.EventManager.OnNewClient += OnNewClient;
  52. m_scene.EventManager.OnParcelPrimCountAdd += delegate(SceneObjectGroup obj) { this.Stale = true; };
  53. }
  54. public void OnNewClient(IClientAPI client)
  55. {
  56. //Detect object data changes by hooking into the IClientAPI.
  57. //Very dirty, and breaks whenever someone changes the client API.
  58. client.OnAddPrim += delegate (UUID ownerID, UUID groupID, Vector3 RayEnd, Quaternion rot,
  59. PrimitiveBaseShape shape, byte bypassRaycast, Vector3 RayStart, UUID RayTargetID,
  60. byte RayEndIsIntersection) { this.Stale = true; };
  61. client.OnLinkObjects += delegate (IClientAPI remoteClient, uint parent, List<uint> children)
  62. { this.Stale = true; };
  63. client.OnDelinkObjects += delegate(List<uint> primIds) { this.Stale = true; };
  64. client.OnGrabUpdate += delegate(UUID objectID, Vector3 offset, Vector3 grapPos,
  65. IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs) { this.Stale = true; };
  66. client.OnObjectAttach += delegate(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt,
  67. Quaternion rot, bool silent) { this.Stale = true; };
  68. client.OnObjectDuplicate += delegate(uint localID, Vector3 offset, uint dupeFlags, UUID AgentID,
  69. UUID GroupID) { this.Stale = true; };
  70. client.OnObjectDuplicateOnRay += delegate(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
  71. UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart, bool BypassRaycast,
  72. bool RayEndIsIntersection, bool CopyCenters, bool CopyRotates) { this.Stale = true; };
  73. client.OnObjectIncludeInSearch += delegate(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
  74. { this.Stale = true; };
  75. client.OnObjectPermissions += delegate(IClientAPI controller, UUID agentID, UUID sessionID,
  76. byte field, uint localId, uint mask, byte set) { this.Stale = true; };
  77. client.OnRezObject += delegate(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd,
  78. Vector3 RayStart, UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  79. bool RezSelected,
  80. bool RemoveItem, UUID fromTaskID) { this.Stale = true; };
  81. }
  82. public Scene GetParentScene
  83. {
  84. get { return m_scene; }
  85. }
  86. public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
  87. {
  88. m_log.Debug("[DATASNAPSHOT]: Generating object data for scene " + m_scene.RegionInfo.RegionName);
  89. XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", "");
  90. XmlNode node;
  91. foreach (EntityBase entity in m_scene.Entities)
  92. {
  93. // only objects, not avatars
  94. if (entity is SceneObjectGroup)
  95. {
  96. SceneObjectGroup obj = (SceneObjectGroup)entity;
  97. // m_log.Debug("[DATASNAPSHOT]: Found object " + obj.Name + " in scene");
  98. // libomv will complain about PrimFlags.JointWheel
  99. // being obsolete, so we...
  100. #pragma warning disable 0612
  101. if ((obj.RootPart.Flags & PrimFlags.JointWheel) == PrimFlags.JointWheel)
  102. {
  103. SceneObjectPart m_rootPart = obj.RootPart;
  104. if (m_rootPart != null)
  105. {
  106. ILandObject land = m_scene.LandChannel.GetLandObject(m_rootPart.AbsolutePosition.X, m_rootPart.AbsolutePosition.Y);
  107. XmlNode xmlobject = nodeFactory.CreateNode(XmlNodeType.Element, "object", "");
  108. node = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
  109. node.InnerText = obj.UUID.ToString();
  110. xmlobject.AppendChild(node);
  111. node = nodeFactory.CreateNode(XmlNodeType.Element, "title", "");
  112. node.InnerText = m_rootPart.Name;
  113. xmlobject.AppendChild(node);
  114. node = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
  115. node.InnerText = m_rootPart.Description;
  116. xmlobject.AppendChild(node);
  117. node = nodeFactory.CreateNode(XmlNodeType.Element, "flags", "");
  118. node.InnerText = String.Format("{0:x}", m_rootPart.ObjectFlags);
  119. xmlobject.AppendChild(node);
  120. node = nodeFactory.CreateNode(XmlNodeType.Element, "regionuuid", "");
  121. node.InnerText = m_scene.RegionInfo.RegionSettings.RegionUUID.ToString();
  122. xmlobject.AppendChild(node);
  123. node = nodeFactory.CreateNode(XmlNodeType.Element, "parceluuid", "");
  124. node.InnerText = land.landData.GlobalID.ToString();
  125. xmlobject.AppendChild(node);
  126. parent.AppendChild(xmlobject);
  127. }
  128. }
  129. #pragma warning disable 0612
  130. }
  131. }
  132. this.Stale = false;
  133. return parent;
  134. }
  135. public String Name
  136. {
  137. get { return "ObjectSnapshot"; }
  138. }
  139. public bool Stale
  140. {
  141. get
  142. {
  143. return m_stale;
  144. }
  145. set
  146. {
  147. m_stale = value;
  148. if (m_stale)
  149. OnStale(this);
  150. }
  151. }
  152. public event ProviderStale OnStale;
  153. }
  154. }