Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim

This commit is contained in:
Melanie
2011-03-27 21:22:31 +01:00
29 changed files with 940 additions and 141 deletions

View File

@@ -72,6 +72,7 @@ namespace OpenSim.Region.CoreModules.World.Land
protected Commander m_commander = new Commander("land");
protected IUserManagement m_userManager;
protected IPrimCountModule m_primCountModule;
// Minimum for parcels to work is 64m even if we don't actually use them.
#pragma warning disable 0429
@@ -147,6 +148,7 @@ namespace OpenSim.Region.CoreModules.World.Land
public void RegionLoaded(Scene scene)
{
m_userManager = m_scene.RequestModuleInterface<IUserManagement>();
m_primCountModule = m_scene.RequestModuleInterface<IPrimCountModule>();
}
public void RemoveRegion(Scene scene)
@@ -306,10 +308,14 @@ namespace OpenSim.Region.CoreModules.World.Land
/// <returns>The parcel created.</returns>
protected ILandObject CreateDefaultParcel()
{
ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
// m_log.DebugFormat(
// "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
return AddLandObject(fullSimParcel);
}
@@ -579,7 +585,7 @@ namespace OpenSim.Region.CoreModules.World.Land
}
else
{
m_log.WarnFormat("[LAND]: Invalid local land ID {0}", landLocalID);
m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid local land ID {0}", landLocalID);
}
}
@@ -590,6 +596,11 @@ namespace OpenSim.Region.CoreModules.World.Land
public ILandObject AddLandObject(ILandObject land)
{
ILandObject new_land = land.Copy();
// Only now can we add the prim counts to the land object - we rely on the global ID which is generated
// as a random UUID inside LandData initialization
if (m_primCountModule != null)
new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID);
lock (m_landList)
{
@@ -630,7 +641,7 @@ namespace OpenSim.Region.CoreModules.World.Land
{
if (m_landIDList[x, y] == local_id)
{
m_log.WarnFormat("[LAND]: Not removing land object {0}; still being used at {1}, {2}",
m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Not removing land object {0}; still being used at {1}, {2}",
local_id, x, y);
return;
//throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
@@ -851,6 +862,10 @@ namespace OpenSim.Region.CoreModules.World.Land
public void EventManagerOnParcelPrimCountUpdate()
{
// m_log.DebugFormat(
// "[LAND MANAGEMENT MODULE]: Triggered EventManagerOnParcelPrimCountUpdate() for {0}",
// m_scene.RegionInfo.RegionName);
ResetAllLandPrimCounts();
EntityBase[] entities = m_scene.Entities.GetEntities();
foreach (EntityBase obj in entities)
@@ -1198,7 +1213,7 @@ namespace OpenSim.Region.CoreModules.World.Land
}
else
{
m_log.WarnFormat("[PARCEL]: Invalid land object {0} passed for parcel object owner request", local_id);
m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid land object {0} passed for parcel object owner request", local_id);
}
}
@@ -1361,7 +1376,7 @@ namespace OpenSim.Region.CoreModules.World.Land
{
ILandObject new_land = new LandObject(data.OwnerID, data.IsGroupOwned, m_scene);
new_land.LandData = data.Copy();
new_land.SetLandBitmapFromByteArray();
new_land.SetLandBitmapFromByteArray();
AddLandObject(new_land);
}
@@ -1426,7 +1441,7 @@ namespace OpenSim.Region.CoreModules.World.Land
{
IClientAPI client;
if (! m_scene.TryGetClient(agentID, out client)) {
m_log.WarnFormat("[LAND] unable to retrieve IClientAPI for {0}", agentID.ToString());
m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to retrieve IClientAPI for {0}", agentID);
return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
}
@@ -1475,7 +1490,7 @@ namespace OpenSim.Region.CoreModules.World.Land
}
else
{
m_log.WarnFormat("[LAND] unable to find parcelID {0}", parcelID);
m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID);
}
return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
}
@@ -1533,17 +1548,17 @@ namespace OpenSim.Region.CoreModules.World.Land
}
catch (LLSD.LLSDParseException e)
{
m_log.ErrorFormat("[LAND] Fetch error: {0}", e.Message);
m_log.ErrorFormat("[LAND] ... in request {0}", request);
m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Fetch error: {0}", e.Message);
m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: ... in request {0}", request);
}
catch(InvalidCastException)
catch (InvalidCastException)
{
m_log.ErrorFormat("[LAND] Wrong type in request {0}", request);
m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Wrong type in request {0}", request);
}
LLSDRemoteParcelResponse response = new LLSDRemoteParcelResponse();
response.parcel_id = parcelID;
m_log.DebugFormat("[LAND] got parcelID {0}", parcelID);
m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelID {0}", parcelID);
return LLSDHelpers.SerialiseLLSDReply(response);
}
@@ -1564,7 +1579,7 @@ namespace OpenSim.Region.CoreModules.World.Land
ExtendedLandData extLandData = new ExtendedLandData();
Util.ParseFakeParcelID(parcel, out extLandData.RegionHandle,
out extLandData.X, out extLandData.Y);
m_log.DebugFormat("[LAND] got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
extLandData.RegionHandle, extLandData.X, extLandData.Y);
// for this region or for somewhere else?
@@ -1605,7 +1620,7 @@ namespace OpenSim.Region.CoreModules.World.Land
info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
}
// we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
m_log.DebugFormat("[LAND] got parcelinfo for parcel {0} in region {1}; sending...",
m_log.DebugFormat("[LAND MANAGEMENT MODULE]: got parcelinfo for parcel {0} in region {1}; sending...",
data.LandData.Name, data.RegionHandle);
// HACK for now
RegionInfo r = new RegionInfo();
@@ -1616,7 +1631,7 @@ namespace OpenSim.Region.CoreModules.World.Land
remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y);
}
else
m_log.Debug("[LAND] got no parcelinfo; not sending");
m_log.Debug("[LAND MANAGEMENT MODULE]: got no parcelinfo; not sending");
}
public void setParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime)

View File

@@ -51,7 +51,7 @@ namespace OpenSim.Region.CoreModules.World.Land
private int m_lastSeqId = 0;
protected LandData m_landData = new LandData();
protected LandData m_landData = new LandData();
protected Scene m_scene;
protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
@@ -79,6 +79,8 @@ namespace OpenSim.Region.CoreModules.World.Land
set { m_landData = value; }
}
public IPrimCounts PrimCounts { get; set; }
public UUID RegionUUID
{

View File

@@ -51,8 +51,8 @@ namespace OpenSim.Region.CoreModules.World.Land
public class PrimCountModule : IPrimCountModule, INonSharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog m_log =
// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_Scene;
private Dictionary<UUID, PrimCounts> m_PrimCounts =
@@ -64,10 +64,16 @@ namespace OpenSim.Region.CoreModules.World.Land
private Dictionary<UUID, ParcelCounts> m_ParcelCounts =
new Dictionary<UUID, ParcelCounts>();
// For now, a simple simwide taint to get this up. Later parcel based
// taint to allow recounting a parcel if only ownership has changed
// without recounting the whole sim.
/// <value>
/// For now, a simple simwide taint to get this up. Later parcel based
/// taint to allow recounting a parcel if only ownership has changed
/// without recounting the whole sim.
///
/// We start out tainted so that the first get call resets the various prim counts.
/// <value>
private bool m_Tainted = true;
private Object m_TaintLock = new Object();
public Type ReplaceableInterface
@@ -82,9 +88,10 @@ namespace OpenSim.Region.CoreModules.World.Land
public void AddRegion(Scene scene)
{
m_Scene = scene;
m_Scene.RegisterModuleInterface<IPrimCountModule>(this);
m_Scene.EventManager.OnParcelPrimCountAdd +=
OnParcelPrimCountAdd;
m_Scene.EventManager.OnObjectAddedToScene += OnParcelPrimCountAdd;
m_Scene.EventManager.OnObjectBeingRemovedFromScene +=
OnObjectBeingRemovedFromScene;
m_Scene.EventManager.OnParcelPrimCountTainted +=
@@ -156,6 +163,8 @@ namespace OpenSim.Region.CoreModules.World.Land
// NOTE: Call under Taint Lock
private void AddObject(SceneObjectGroup obj)
{
// m_log.DebugFormat("[PRIM COUNT MODULE]: Adding object {0} to prim count", obj.Name);
if (obj.IsAttachment)
return;
if (((obj.RootPart.Flags & PrimFlags.TemporaryOnRez) != 0))
@@ -164,6 +173,10 @@ namespace OpenSim.Region.CoreModules.World.Land
Vector3 pos = obj.AbsolutePosition;
ILandObject landObject = m_Scene.LandChannel.GetLandObject(pos.X, pos.Y);
LandData landData = landObject.LandData;
// m_log.DebugFormat(
// "[PRIM COUNT MODULE]: Object {0} is owned by {1} over land owned by {2}",
// obj.Name, obj.OwnerID, landData.OwnerID);
ParcelCounts parcelCounts;
if (m_ParcelCounts.TryGetValue(landData.GlobalID, out parcelCounts))
@@ -218,8 +231,16 @@ namespace OpenSim.Region.CoreModules.World.Land
return primCounts;
}
/// <summary>
/// Get the number of prims on the parcel that are owned by the parcel owner.
/// </summary>
/// <param name="parcelID"></param>
/// <returns></returns>
public int GetOwnerCount(UUID parcelID)
{
// m_log.DebugFormat("[PRIM COUNT MODULE]: GetOwnerCount for {0}", parcelID);
lock (m_TaintLock)
{
if (m_Tainted)
@@ -232,6 +253,11 @@ namespace OpenSim.Region.CoreModules.World.Land
return 0;
}
/// <summary>
/// Get the number of prims on the parcel that have been set to the group that owns the parcel.
/// </summary>
/// <param name="parcelID"></param>
/// <returns></returns>
public int GetGroupCount(UUID parcelID)
{
lock (m_TaintLock)
@@ -246,6 +272,11 @@ namespace OpenSim.Region.CoreModules.World.Land
return 0;
}
/// <summary>
/// Get the number of prims on the parcel that are not owned by the parcel owner or set to the parcel group.
/// </summary>
/// <param name="parcelID"></param>
/// <returns></returns>
public int GetOthersCount(UUID parcelID)
{
lock (m_TaintLock)
@@ -260,6 +291,11 @@ namespace OpenSim.Region.CoreModules.World.Land
return 0;
}
/// <summary>
/// Get the number of prims that are in the entire simulator for the owner of this parcel.
/// </summary>
/// <param name="parcelID"></param>
/// <returns></returns>
public int GetSimulatorCount(UUID parcelID)
{
lock (m_TaintLock)
@@ -278,6 +314,12 @@ namespace OpenSim.Region.CoreModules.World.Land
return 0;
}
/// <summary>
/// Get the number of prims that a particular user owns on this parcel.
/// </summary>
/// <param name="parcelID"></param>
/// <param name="userID"></param>
/// <returns></returns>
public int GetUserCount(UUID parcelID, UUID userID)
{
lock (m_TaintLock)
@@ -299,18 +341,21 @@ namespace OpenSim.Region.CoreModules.World.Land
// NOTE: This method MUST be called while holding the taint lock!
private void Recount()
{
// m_log.DebugFormat("[PRIM COUNT MODULE]: Recounting prims on {0}", m_Scene.RegionInfo.RegionName);
m_OwnerMap.Clear();
m_SimwideCounts.Clear();
m_ParcelCounts.Clear();
List<ILandObject> land = m_Scene.LandChannel.AllParcels();
foreach (ILandObject l in land)
{
LandData landData = l.LandData;
m_OwnerMap[landData.GlobalID] = landData.OwnerID;
m_SimwideCounts[landData.OwnerID] = 0;
// m_log.DebugFormat("[PRIM COUNT MODULE]: Adding parcel count for {0}", landData.GlobalID);
m_ParcelCounts[landData.GlobalID] = new ParcelCounts();
}

View File

@@ -0,0 +1,131 @@
/*
* 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 OpenSimulator 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 log4net.Config;
using NUnit.Framework;
using OpenMetaverse;
using OpenMetaverse.Assets;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
using OpenSim.Tests.Common.Mock;
using OpenSim.Tests.Common.Setup;
namespace OpenSim.Region.CoreModules.World.Land.Tests
{
[TestFixture]
public class PrimCountModuleTests
{
protected UUID m_userId = new UUID("00000000-0000-0000-0000-100000000000");
protected UUID m_dummyUserId = new UUID("99999999-9999-9999-9999-999999999999");
protected TestScene m_scene;
protected PrimCountModule m_pcm;
protected ILandObject m_lo;
[SetUp]
public void SetUp()
{
m_pcm = new PrimCountModule();
LandManagementModule lmm = new LandManagementModule();
m_scene = SceneSetupHelpers.SetupScene();
SceneSetupHelpers.SetupSceneModules(m_scene, lmm, m_pcm);
ILandObject lo = new LandObject(m_userId, false, m_scene);
lo.SetLandBitmap(lo.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
m_lo = lmm.AddLandObject(lo);
//scene.loadAllLandObjectsFromStorage(scene.RegionInfo.originRegionID);
}
/// <summary>
/// Test count after a parcel owner owned object is added.
/// </summary>
[Test]
public void TestAddOwnerObject()
{
TestHelper.InMethod();
// log4net.Config.XmlConfigurator.Configure();
IPrimCounts pc = m_lo.PrimCounts;
Assert.That(pc.Owner, Is.EqualTo(0));
Assert.That(pc.Group, Is.EqualTo(0));
Assert.That(pc.Others, Is.EqualTo(0));
Assert.That(pc.Users[m_userId], Is.EqualTo(0));
Assert.That(pc.Users[m_dummyUserId], Is.EqualTo(0));
Assert.That(pc.Simulator, Is.EqualTo(0));
SceneObjectGroup sog = SceneSetupHelpers.CreateSceneObject(3, m_userId, 0x01);
m_scene.AddNewSceneObject(sog, false);
Assert.That(pc.Owner, Is.EqualTo(3));
Assert.That(pc.Group, Is.EqualTo(0));
Assert.That(pc.Others, Is.EqualTo(0));
Assert.That(pc.Users[m_userId], Is.EqualTo(3));
Assert.That(pc.Users[m_dummyUserId], Is.EqualTo(0));
Assert.That(pc.Simulator, Is.EqualTo(3));
// Add a second object and retest
SceneObjectGroup sog2 = SceneSetupHelpers.CreateSceneObject(2, m_userId, 0x10);
m_scene.AddNewSceneObject(sog2, false);
Assert.That(pc.Owner, Is.EqualTo(5));
Assert.That(pc.Group, Is.EqualTo(0));
Assert.That(pc.Others, Is.EqualTo(0));
Assert.That(pc.Users[m_userId], Is.EqualTo(5));
Assert.That(pc.Users[m_dummyUserId], Is.EqualTo(0));
Assert.That(pc.Simulator, Is.EqualTo(5));
}
/// <summary>
/// Test count after a parcel owner owned object is removed.
/// </summary>
[Test]
public void TestRemoveOwnerObject()
{
TestHelper.InMethod();
// log4net.Config.XmlConfigurator.Configure();
IPrimCounts pc = m_lo.PrimCounts;
m_scene.AddNewSceneObject(SceneSetupHelpers.CreateSceneObject(1, m_userId, 0x1), false);
SceneObjectGroup sogToDelete = SceneSetupHelpers.CreateSceneObject(3, m_userId, 0x10);
m_scene.AddNewSceneObject(sogToDelete, false);
m_scene.DeleteSceneObject(sogToDelete, false);
Assert.That(pc.Owner, Is.EqualTo(1));
Assert.That(pc.Group, Is.EqualTo(0));
Assert.That(pc.Others, Is.EqualTo(0));
Assert.That(pc.Users[m_userId], Is.EqualTo(1));
Assert.That(pc.Users[m_dummyUserId], Is.EqualTo(0));
Assert.That(pc.Simulator, Is.EqualTo(1));
}
}
}