From 91e346358283e43644ef9a28483d9fac0b159e45 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 13 Sep 2008 17:50:02 +0000 Subject: 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. --- OpenSim/Region/DataSnapshot/LandSnapshot.cs | 28 +++++++++------------- .../Region/Environment/Interfaces/ILandChannel.cs | 1 + .../Environment/Modules/World/Land/LandChannel.cs | 10 ++++++++ .../Modules/World/Land/LandManagementModule.cs | 5 ++++ 4 files changed, 27 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/DataSnapshot/LandSnapshot.cs b/OpenSim/Region/DataSnapshot/LandSnapshot.cs index b0ba29d..dc7ef8c 100644 --- a/OpenSim/Region/DataSnapshot/LandSnapshot.cs +++ b/OpenSim/Region/DataSnapshot/LandSnapshot.cs @@ -119,28 +119,22 @@ namespace OpenSim.Region.DataSnapshot.Providers public XmlNode RequestSnapshotData(XmlDocument nodeFactory) { - ILandChannel landChannel = (LandChannel)m_scene.LandChannel; - Dictionary landList = null; - try - { - Type landChannelType = typeof(LandChannel); - FieldInfo landListField = landChannelType.GetField("landList", BindingFlags.NonPublic | BindingFlags.Instance); - if (landListField != null) - { - landList = (Dictionary)landListField.GetValue(landChannel); - } - } - catch (Exception e) - { - m_log.Error("[DATASNAPSHOT] couldn't access field reflectively\n" + e.ToString()); - } + ILandChannel landChannel = m_scene.LandChannel; + List parcels = landChannel.AllParcels(); + XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "parceldata", ""); - if (landList != null) + if (parcels != null) { //foreach (KeyValuePair 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) { diff --git a/OpenSim/Region/Environment/Interfaces/ILandChannel.cs b/OpenSim/Region/Environment/Interfaces/ILandChannel.cs index 4a74949..98998f7 100644 --- a/OpenSim/Region/Environment/Interfaces/ILandChannel.cs +++ b/OpenSim/Region/Environment/Interfaces/ILandChannel.cs @@ -36,6 +36,7 @@ namespace OpenSim.Region.Environment.Interfaces { List ParcelsNearPoint(Vector3 position); + List AllParcels(); ILandObject GetLandObject(int x, int y); ILandObject GetLandObject(float x, float y); bool IsLandPrimCountTainted(); diff --git a/OpenSim/Region/Environment/Modules/World/Land/LandChannel.cs b/OpenSim/Region/Environment/Modules/World/Land/LandChannel.cs index 1e1291a..8747bd4 100644 --- a/OpenSim/Region/Environment/Modules/World/Land/LandChannel.cs +++ b/OpenSim/Region/Environment/Modules/World/Land/LandChannel.cs @@ -105,6 +105,16 @@ namespace OpenSim.Region.Environment.Modules.World.Land return obj; } + public List AllParcels() + { + if (m_landManagementModule != null) + { + return m_landManagementModule.AllParcels(); + } + + return new List(); + } + public List ParcelsNearPoint(Vector3 position) { if (m_landManagementModule != null) diff --git a/OpenSim/Region/Environment/Modules/World/Land/LandManagementModule.cs b/OpenSim/Region/Environment/Modules/World/Land/LandManagementModule.cs index f4ba9a3..bf51edb 100644 --- a/OpenSim/Region/Environment/Modules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Land/LandManagementModule.cs @@ -175,6 +175,11 @@ namespace OpenSim.Region.Environment.Modules.World.Land AddLandObject(fullSimParcel); } + public List AllParcels() + { + return new List(landList.Values); + } + public List ParcelsNearPoint(Vector3 position) { List parcelsNear = new List(); -- cgit v1.1