1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using OpenMetaverse;
using log4net;
using OpenSim.Framework;
using OpenSim.Region.DataSnapshot.Interfaces;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Modules.World.Land;
using OpenSim.Region.Environment.Scenes;
using OpenMetaverse.Packets;
namespace OpenSim.Region.DataSnapshot.Providers
{
public class LandSnapshot : IDataSnapshotProvider
{
private Scene m_scene = null;
// private DataSnapshotManager m_parent = null;
//private Dictionary<int, Land> m_landIndexed = new Dictionary<int, Land>();
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool m_stale = true;
#region Dead code
/*
* David, I don't think we need this at all. When we do the snapshot, we can
* simply look into the parcels that are marked for ShowDirectory -- see
* conditional in RequestSnapshotData
*
//Revise this, look for more direct way of checking for change in land
#region Client hooks
public void OnNewClient(IClientAPI client)
{
//Land hooks
client.OnParcelDivideRequest += ParcelSplitHook;
client.OnParcelJoinRequest += ParcelSplitHook;
client.OnParcelPropertiesUpdateRequest += ParcelPropsHook;
}
public void ParcelSplitHook(int west, int south, int east, int north, IClientAPI remote_client)
{
PrepareData();
}
public void ParcelPropsHook(ParcelPropertiesUpdatePacket packet, IClientAPI remote_client)
{
PrepareData();
}
#endregion
public void PrepareData()
{
m_log.Info("[EXTERNALDATA]: Generating land data.");
m_landIndexed.Clear();
//Index sim land
foreach (KeyValuePair<int, Land> curLand in m_scene.LandManager.landList)
{
//if ((curLand.Value.landData.landFlags & (uint)Parcel.ParcelFlags.ShowDirectory) == (uint)Parcel.ParcelFlags.ShowDirectory)
//{
m_landIndexed.Add(curLand.Key, curLand.Value.Copy());
//}
}
}
public Dictionary<int,Land> IndexedLand {
get { return m_landIndexed; }
}
*/
#endregion
#region IDataSnapshotProvider members
public void Initialize(Scene scene, DataSnapshotManager parent)
{
m_scene = scene;
// m_parent = parent;
//Brought back from the dead for staleness checks.
m_scene.EventManager.OnNewClient += OnNewClient;
}
public Scene GetParentScene
{
get { return m_scene; }
}
public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
{
ILandChannel landChannel = m_scene.LandChannel;
List<ILandObject> parcels = landChannel.AllParcels();
XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "parceldata", "");
if (parcels != null)
{
//foreach (KeyValuePair<int, Land> curParcel in m_landIndexed)
foreach (ILandObject parcel_interface in parcels)
{
// Play it safe
if (!(parcel_interface is LandObject))
continue;
LandObject land = (LandObject)parcel_interface;
LandData parcel = land.landData;
if ((parcel.Flags & (uint)Parcel.ParcelFlags.ShowDirectory) == (uint)Parcel.ParcelFlags.ShowDirectory)
{
//TODO: make better method of marshalling data from LandData to XmlNode
XmlNode xmlparcel = nodeFactory.CreateNode(XmlNodeType.Element, "parcel", "");
// Attributes of the parcel node
XmlAttribute scripts_attr = nodeFactory.CreateAttribute("scripts");
scripts_attr.Value = GetScriptsPermissions(parcel);
XmlAttribute build_attr = nodeFactory.CreateAttribute("build");
build_attr.Value = GetBuildPermissions(parcel);
XmlAttribute public_attr = nodeFactory.CreateAttribute("public");
public_attr.Value = GetPublicPermissions(parcel);
// Check the category of the Parcel
XmlAttribute category_attr = nodeFactory.CreateAttribute("category");
category_attr.Value = parcel.Category.ToString();
//XmlAttribute entities_attr = nodeFactory.CreateAttribute("entities");
//entities_attr.Value = land.primsOverMe.Count.ToString();
xmlparcel.Attributes.Append(scripts_attr);
xmlparcel.Attributes.Append(build_attr);
xmlparcel.Attributes.Append(public_attr);
xmlparcel.Attributes.Append(category_attr);
//xmlparcel.Attributes.Append(entities_attr);
//name, description, area, and UUID
XmlNode name = nodeFactory.CreateNode(XmlNodeType.Element, "name", "");
name.InnerText = parcel.Name;
xmlparcel.AppendChild(name);
XmlNode desc = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
desc.InnerText = parcel.Description;
xmlparcel.AppendChild(desc);
XmlNode uuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
uuid.InnerText = parcel.GlobalID.ToString();
xmlparcel.AppendChild(uuid);
XmlNode area = nodeFactory.CreateNode(XmlNodeType.Element, "area", "");
area.InnerText = parcel.Area.ToString();
xmlparcel.AppendChild(area);
//default location
XmlNode tpLocation = nodeFactory.CreateNode(XmlNodeType.Element, "location", "");
Vector3 loc = parcel.UserLocation;
if (loc.Equals(Vector3.Zero)) // This test is mute at this point: the location is wrong by default
loc = new Vector3((parcel.AABBMax.X - parcel.AABBMin.X) / 2, (parcel.AABBMax.Y - parcel.AABBMin.Y) / 2, (parcel.AABBMax.Y - parcel.AABBMin.Y) / 2);
tpLocation.InnerText = loc.X.ToString() + "/" + loc.Y.ToString() + "/" + loc.Z.ToString();
xmlparcel.AppendChild(tpLocation);
//TODO: figure how to figure out teleport system landData.landingType
//land texture snapshot uuid
if (parcel.SnapshotID != UUID.Zero)
{
XmlNode textureuuid = nodeFactory.CreateNode(XmlNodeType.Element, "image", "");
textureuuid.InnerText = parcel.SnapshotID.ToString();
xmlparcel.AppendChild(textureuuid);
}
//attached user and group
if (parcel.GroupID != UUID.Zero)
{
XmlNode groupblock = nodeFactory.CreateNode(XmlNodeType.Element, "group", "");
XmlNode groupuuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
groupuuid.InnerText = parcel.GroupID.ToString();
groupblock.AppendChild(groupuuid);
//No name yet, there's no way to get a group name since they don't exist yet.
//TODO: When groups are supported, add the group handling code.
xmlparcel.AppendChild(groupblock);
}
if (!parcel.IsGroupOwned)
{
XmlNode userblock = nodeFactory.CreateNode(XmlNodeType.Element, "owner", "");
UUID userOwnerUUID = parcel.OwnerID;
XmlNode useruuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
useruuid.InnerText = userOwnerUUID.ToString();
userblock.AppendChild(useruuid);
try
{
XmlNode username = nodeFactory.CreateNode(XmlNodeType.Element, "name", "");
UserProfileData userProfile = m_scene.CommsManager.UserService.GetUserProfile(userOwnerUUID);
username.InnerText = userProfile.FirstName + " " + userProfile.SurName;
userblock.AppendChild(username);
}
catch (Exception)
{
m_log.Info("[DATASNAPSHOT]: Cannot find owner name; ignoring this parcel");
}
xmlparcel.AppendChild(userblock);
}
//else
//{
// XmlAttribute type = (XmlAttribute)nodeFactory.CreateNode(XmlNodeType.Attribute, "type", "");
// type.InnerText = "owner";
// groupblock.Attributes.Append(type);
//}
parent.AppendChild(xmlparcel);
}
}
//snap.AppendChild(parent);
}
this.Stale = false;
return parent;
}
public String Name
{
get { return "LandSnapshot"; }
}
public bool Stale
{
get
{
return m_stale;
}
set
{
m_stale = value;
if (m_stale)
OnStale(this);
}
}
public event ProviderStale OnStale;
#endregion
#region Helper functions
private string GetScriptsPermissions(LandData parcel)
{
if ((parcel.Flags & (uint)Parcel.ParcelFlags.AllowOtherScripts) == (uint)Parcel.ParcelFlags.AllowOtherScripts)
return "yes";
else
return "no";
}
private string GetPublicPermissions(LandData parcel)
{
if ((parcel.Flags & (uint)Parcel.ParcelFlags.UseAccessList) == (uint)Parcel.ParcelFlags.UseAccessList)
return "yes";
else
return "no";
}
private string GetBuildPermissions(LandData parcel)
{
if ((parcel.Flags & (uint)Parcel.ParcelFlags.CreateObjects) == (uint)Parcel.ParcelFlags.CreateObjects)
return "yes";
else
return "no";
}
#endregion
#region Change detection hooks
public void OnNewClient(IClientAPI client)
{
//Land hooks
client.OnParcelDivideRequest += delegate (int west, int south, int east, int north,
IClientAPI remote_client) { this.Stale = true; };
client.OnParcelJoinRequest += delegate (int west, int south, int east, int north,
IClientAPI remote_client) { this.Stale = true; };
client.OnParcelPropertiesUpdateRequest += delegate(LandUpdateArgs args, int local_id,
IClientAPI remote_client) { this.Stale = true; };
client.OnParcelBuy += delegate (UUID agentId, UUID groupId, bool final, bool groupOwned,
bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
{ this.Stale = true; };
}
public void ParcelSplitHook(int west, int south, int east, int north, IClientAPI remote_client)
{
this.Stale = true;
}
public void ParcelPropsHook(LandUpdateArgs args, int local_id, IClientAPI remote_client)
{
this.Stale = true;
}
#endregion
}
}
|