aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs')
-rw-r--r--OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs264
1 files changed, 264 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs b/OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs
new file mode 100644
index 0000000..0bb4044
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/DataSnapshot/ObjectSnapshot.cs
@@ -0,0 +1,264 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Xml;
32using log4net;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.DataSnapshot.Interfaces;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38
39namespace OpenSim.Region.DataSnapshot.Providers
40{
41 public class ObjectSnapshot : IDataSnapshotProvider
42 {
43 private Scene m_scene = null;
44 // private DataSnapshotManager m_parent = null;
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private bool m_stale = true;
47
48 private static UUID m_DefaultImage = new UUID("89556747-24cb-43ed-920b-47caed15465f");
49 private static UUID m_BlankImage = new UUID("5748decc-f629-461c-9a36-a35a221fe21f");
50
51
52 public void Initialize(Scene scene, DataSnapshotManager parent)
53 {
54 m_scene = scene;
55 // m_parent = parent;
56
57 //To check for staleness, we must catch all incoming client packets.
58 m_scene.EventManager.OnNewClient += OnNewClient;
59 m_scene.EventManager.OnParcelPrimCountAdd += delegate(SceneObjectGroup obj) { this.Stale = true; };
60 }
61
62 public void OnNewClient(IClientAPI client)
63 {
64 //Detect object data changes by hooking into the IClientAPI.
65 //Very dirty, and breaks whenever someone changes the client API.
66
67 client.OnAddPrim += delegate (UUID ownerID, UUID groupID, Vector3 RayEnd, Quaternion rot,
68 PrimitiveBaseShape shape, byte bypassRaycast, Vector3 RayStart, UUID RayTargetID,
69 byte RayEndIsIntersection) { this.Stale = true; };
70 client.OnLinkObjects += delegate (IClientAPI remoteClient, uint parent, List<uint> children)
71 { this.Stale = true; };
72 client.OnDelinkObjects += delegate(List<uint> primIds, IClientAPI clientApi) { this.Stale = true; };
73 client.OnGrabUpdate += delegate(UUID objectID, Vector3 offset, Vector3 grapPos,
74 IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs) { this.Stale = true; };
75 client.OnObjectAttach += delegate(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt,
76 bool silent) { this.Stale = true; };
77 client.OnObjectDuplicate += delegate(uint localID, Vector3 offset, uint dupeFlags, UUID AgentID,
78 UUID GroupID) { this.Stale = true; };
79 client.OnObjectDuplicateOnRay += delegate(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
80 UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart, bool BypassRaycast,
81 bool RayEndIsIntersection, bool CopyCenters, bool CopyRotates) { this.Stale = true; };
82 client.OnObjectIncludeInSearch += delegate(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
83 { this.Stale = true; };
84 client.OnObjectPermissions += delegate(IClientAPI controller, UUID agentID, UUID sessionID,
85 byte field, uint localId, uint mask, byte set) { this.Stale = true; };
86 client.OnRezObject += delegate(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd,
87 Vector3 RayStart, UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
88 bool RezSelected,
89 bool RemoveItem, UUID fromTaskID) { this.Stale = true; };
90 }
91
92 public Scene GetParentScene
93 {
94 get { return m_scene; }
95 }
96
97 public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
98 {
99 m_log.Debug("[DATASNAPSHOT]: Generating object data for scene " + m_scene.RegionInfo.RegionName);
100
101 XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", "");
102 XmlNode node;
103
104 EntityBase[] entities = m_scene.Entities.GetEntities();
105 foreach (EntityBase entity in entities)
106 {
107 // only objects, not avatars
108 if (entity is SceneObjectGroup)
109 {
110 SceneObjectGroup obj = (SceneObjectGroup)entity;
111
112// m_log.Debug("[DATASNAPSHOT]: Found object " + obj.Name + " in scene");
113
114 // libomv will complain about PrimFlags.JointWheel
115 // being obsolete, so we...
116 #pragma warning disable 0612
117 if ((obj.RootPart.Flags & PrimFlags.JointWheel) == PrimFlags.JointWheel)
118 {
119 SceneObjectPart m_rootPart = obj.RootPart;
120
121 ILandObject land = m_scene.LandChannel.GetLandObject(m_rootPart.AbsolutePosition.X, m_rootPart.AbsolutePosition.Y);
122
123 XmlNode xmlobject = nodeFactory.CreateNode(XmlNodeType.Element, "object", "");
124 node = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
125 node.InnerText = obj.UUID.ToString();
126 xmlobject.AppendChild(node);
127
128 node = nodeFactory.CreateNode(XmlNodeType.Element, "title", "");
129 node.InnerText = m_rootPart.Name;
130 xmlobject.AppendChild(node);
131
132 node = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
133 node.InnerText = m_rootPart.Description;
134 xmlobject.AppendChild(node);
135
136 node = nodeFactory.CreateNode(XmlNodeType.Element, "flags", "");
137 node.InnerText = String.Format("{0:x}", (uint)m_rootPart.Flags);
138 xmlobject.AppendChild(node);
139
140 node = nodeFactory.CreateNode(XmlNodeType.Element, "regionuuid", "");
141 node.InnerText = m_scene.RegionInfo.RegionSettings.RegionUUID.ToString();
142 xmlobject.AppendChild(node);
143
144 if (land != null && land.LandData != null)
145 {
146 node = nodeFactory.CreateNode(XmlNodeType.Element, "parceluuid", "");
147 node.InnerText = land.LandData.GlobalID.ToString();
148 xmlobject.AppendChild(node);
149 }
150 else
151 {
152 // Something is wrong with this object. Let's not list it.
153 m_log.WarnFormat("[DATASNAPSHOT]: Bad data for object {0} ({1}) in region {2}", obj.Name, obj.UUID, m_scene.RegionInfo.RegionName);
154 continue;
155 }
156
157 node = nodeFactory.CreateNode(XmlNodeType.Element, "location", "");
158 Vector3 loc = obj.AbsolutePosition;
159 node.InnerText = loc.X.ToString() + "/" + loc.Y.ToString() + "/" + loc.Z.ToString();
160 xmlobject.AppendChild(node);
161
162 string bestImage = GuessImage(obj);
163 if (bestImage != string.Empty)
164 {
165 node = nodeFactory.CreateNode(XmlNodeType.Element, "image", "");
166 node.InnerText = bestImage;
167 xmlobject.AppendChild(node);
168 }
169
170 parent.AppendChild(xmlobject);
171 }
172 #pragma warning disable 0612
173 }
174 }
175 this.Stale = false;
176 return parent;
177 }
178
179 public String Name
180 {
181 get { return "ObjectSnapshot"; }
182 }
183
184 public bool Stale
185 {
186 get
187 {
188 return m_stale;
189 }
190 set
191 {
192 m_stale = value;
193
194 if (m_stale)
195 OnStale(this);
196 }
197 }
198
199 public event ProviderStale OnStale;
200
201 /// <summary>
202 /// Guesses the best image, based on a simple heuristic. It guesses only for boxes.
203 /// We're optimizing for boxes, because those are the most common objects
204 /// marked "Show in search" -- boxes with content inside.For other shapes,
205 /// it's really hard to tell which texture should be grabbed.
206 /// </summary>
207 /// <param name="sog"></param>
208 /// <returns></returns>
209 private string GuessImage(SceneObjectGroup sog)
210 {
211 string bestguess = string.Empty;
212 Dictionary<UUID, int> counts = new Dictionary<UUID, int>();
213
214 PrimitiveBaseShape shape = sog.RootPart.Shape;
215 if (shape != null && shape.ProfileShape == ProfileShape.Square)
216 {
217 Primitive.TextureEntry textures = shape.Textures;
218 if (textures != null)
219 {
220 if (textures.DefaultTexture != null &&
221 textures.DefaultTexture.TextureID != UUID.Zero &&
222 textures.DefaultTexture.TextureID != m_DefaultImage &&
223 textures.DefaultTexture.TextureID != m_BlankImage &&
224 textures.DefaultTexture.RGBA.A < 50f)
225 {
226 counts[textures.DefaultTexture.TextureID] = 8;
227 }
228
229 if (textures.FaceTextures != null)
230 {
231 foreach (Primitive.TextureEntryFace tentry in textures.FaceTextures)
232 {
233 if (tentry != null)
234 {
235 if (tentry.TextureID != UUID.Zero && tentry.TextureID != m_DefaultImage && tentry.TextureID != m_BlankImage && tentry.RGBA.A < 50)
236 {
237 int c = 0;
238 counts.TryGetValue(tentry.TextureID, out c);
239 counts[tentry.TextureID] = c + 1;
240 // decrease the default texture count
241 if (counts.ContainsKey(textures.DefaultTexture.TextureID))
242 counts[textures.DefaultTexture.TextureID] = counts[textures.DefaultTexture.TextureID] - 1;
243 }
244 }
245 }
246 }
247
248 // Let's pick the most unique texture
249 int min = 9999;
250 foreach (KeyValuePair<UUID, int> kv in counts)
251 {
252 if (kv.Value < min && kv.Value >= 1)
253 {
254 bestguess = kv.Key.ToString();
255 min = kv.Value;
256 }
257 }
258 }
259 }
260
261 return bestguess;
262 }
263 }
264}