Remove the cruft of accessing a private member of another module's class

from DataSnapshot and replace it with a best practices approach, making
it much less dependent on the land module's internal structure and types.
0.6.0-stable
Melanie Thielker 2008-09-13 17:50:02 +00:00
parent e45db5917b
commit 91e3463582
4 changed files with 27 additions and 17 deletions

View File

@ -119,28 +119,22 @@ namespace OpenSim.Region.DataSnapshot.Providers
public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
{
ILandChannel landChannel = (LandChannel)m_scene.LandChannel;
Dictionary<int, ILandObject> landList = null;
try
{
Type landChannelType = typeof(LandChannel);
FieldInfo landListField = landChannelType.GetField("landList", BindingFlags.NonPublic | BindingFlags.Instance);
if (landListField != null)
{
landList = (Dictionary<int, ILandObject>)landListField.GetValue(landChannel);
}
}
catch (Exception e)
{
m_log.Error("[DATASNAPSHOT] couldn't access field reflectively\n" + e.ToString());
}
ILandChannel landChannel = m_scene.LandChannel;
List<ILandObject> parcels = landChannel.AllParcels();
XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "parceldata", "");
if (landList != null)
if (parcels != null)
{
//foreach (KeyValuePair<int, Land> curParcel in m_landIndexed)
foreach (LandObject land in landList.Values)
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)
{

View File

@ -36,6 +36,7 @@ namespace OpenSim.Region.Environment.Interfaces
{
List<ILandObject> ParcelsNearPoint(Vector3 position);
List<ILandObject> AllParcels();
ILandObject GetLandObject(int x, int y);
ILandObject GetLandObject(float x, float y);
bool IsLandPrimCountTainted();

View File

@ -105,6 +105,16 @@ namespace OpenSim.Region.Environment.Modules.World.Land
return obj;
}
public List<ILandObject> AllParcels()
{
if (m_landManagementModule != null)
{
return m_landManagementModule.AllParcels();
}
return new List<ILandObject>();
}
public List<ILandObject> ParcelsNearPoint(Vector3 position)
{
if (m_landManagementModule != null)

View File

@ -175,6 +175,11 @@ namespace OpenSim.Region.Environment.Modules.World.Land
AddLandObject(fullSimParcel);
}
public List<ILandObject> AllParcels()
{
return new List<ILandObject>(landList.Values);
}
public List<ILandObject> ParcelsNearPoint(Vector3 position)
{
List<ILandObject> parcelsNear = new List<ILandObject>();