From b47c0d7e51bdb4d4bfa34f0952593f94c657d19c Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 12 Jan 2012 18:14:19 +0000
Subject: refactor: Move existing npc owner checks to
NPCModule.CheckPermissions() methods and expose on interface for external
calls.
---
.../Region/OptionalModules/World/NPC/NPCModule.cs | 49 ++++++++++++++++------
1 file changed, 36 insertions(+), 13 deletions(-)
(limited to 'OpenSim/Region/OptionalModules/World/NPC')
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index e874417..8f9b513 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -56,6 +56,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC
}
}
+ public void PostInitialise()
+ {
+ }
+
+ public void Close()
+ {
+ }
+
+ public string Name
+ {
+ get { return "NPCModule"; }
+ }
+
+ public bool IsSharedModule
+ {
+ get { return true; }
+ }
+
public bool IsNPC(UUID agentId, Scene scene)
{
// FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect
@@ -255,7 +273,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
NPCAvatar av;
if (m_avatars.TryGetValue(agentID, out av))
{
- if (av.OwnerID != UUID.Zero && callerID != UUID.Zero && av.OwnerID != callerID)
+ if (!CheckPermissions(av, callerID));
return false;
scene.RemoveClient(agentID, false);
@@ -268,22 +286,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
return false;
}
- public void PostInitialise()
- {
- }
-
- public void Close()
- {
- }
-
- public string Name
+ public bool CheckPermissions(UUID npcID, UUID callerID)
{
- get { return "NPCModule"; }
+ lock (m_avatars)
+ {
+ NPCAvatar av;
+ if (m_avatars.TryGetValue(npcID, out av))
+ return CheckPermissions(av, callerID);
+ else
+ return false;
+ }
}
- public bool IsSharedModule
+ ///
+ /// Check if the caller has permission to manipulate the given NPC.
+ ///
+ ///
+ ///
+ /// true if they do, false if they don't.
+ private bool CheckPermissions(NPCAvatar av, UUID callerID)
{
- get { return true; }
+ return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID;
}
}
}
--
cgit v1.1