From 6214e6a217cfe206e127739b141bdcceb253c98d Mon Sep 17 00:00:00 2001 From: Bo Iwu Date: Thu, 12 Jan 2012 17:43:20 +0100 Subject: [PATCH 01/12] Allow update of stored entries within User Management Module-this is needed for proper work of HG friends. See http://opensimulator.org/mantis/view.php?id=5847 --- .../UserManagement/UserManagementModule.cs | 100 +++++++++--------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 37292d66fd..2ad30a0a0d 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -423,58 +423,62 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement AddUser(uuid, profileURL + ";" + first + " " + last); } - public void AddUser(UUID id, string creatorData) + public void AddUser (UUID id, string creatorData) { - lock (m_UserCache) - { - if (m_UserCache.ContainsKey(id)) - return; - } - -// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, craetorData {1}", id, creatorData); - - UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id); - - if (account != null) - { - AddUser(id, account.FirstName, account.LastName); - } - else - { - UserData user = new UserData(); - user.Id = id; - user.Flags = -1; - user.Created = -1; - - if (creatorData != null && creatorData != string.Empty) - { - //creatorData = ; - - string[] parts = creatorData.Split(';'); - if (parts.Length >= 1) - { - user.HomeURL = parts[0]; - try - { - Uri uri = new Uri(parts[0]); - user.LastName = "@" + uri.Authority; - } - catch (UriFormatException) - { - m_log.DebugFormat("[SCENE]: Unable to parse Uri {0}", parts[0]); - user.LastName = "@unknown"; - } + UserData oldUser; + //lock the whole block - prevent concurrent update + lock (m_UserCache) { + m_UserCache.TryGetValue (id, out oldUser); + if (oldUser != null) { + if (creatorData == null || creatorData == String.Empty) { + //ignore updates without creator data + return; + } + //try update unknown users + //and creator's home URL's + if ((oldUser.FirstName == "Unknown" && !creatorData.Contains ("Unknown")) || (oldUser.HomeURL != null && !creatorData.StartsWith (oldUser.HomeURL))) { + m_UserCache.Remove (id); +// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData,oldUser.HomeURL); + } else { + //we have already a valid user within the cache + return; } - if (parts.Length >= 2) - user.FirstName = parts[1].Replace(' ', '.'); } - else - { - user.FirstName = "Unknown"; - user.LastName = "User"; +// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData); + + UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount (m_Scenes[0].RegionInfo.ScopeID, id); + + if (account != null) { + AddUser (id, account.FirstName, account.LastName); + } else { + UserData user = new UserData (); + user.Id = id; + user.Flags = -1; + user.Created = -1; + + if (creatorData != null && creatorData != string.Empty) { + //creatorData = ; + + string[] parts = creatorData.Split (';'); + if (parts.Length >= 1) { + user.HomeURL = parts[0]; + try { + Uri uri = new Uri (parts[0]); + user.LastName = "@" + uri.Authority; + } catch (UriFormatException) { + m_log.DebugFormat ("[SCENE]: Unable to parse Uri {0}", parts[0]); + user.LastName = "@unknown"; + } + } + if (parts.Length >= 2) + user.FirstName = parts[1].Replace (' ', '.'); + } else { + user.FirstName = "Unknown"; + user.LastName = "User"; + } + + AddUserInternal (user); } - - AddUserInternal(user); } } From b47c0d7e51bdb4d4bfa34f0952593f94c657d19c Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 18:14:19 +0000 Subject: [PATCH 02/12] refactor: Move existing npc owner checks to NPCModule.CheckPermissions() methods and expose on interface for external calls. --- .../Region/Framework/Interfaces/INPCModule.cs | 8 +++ .../OptionalModules/World/NPC/NPCModule.cs | 49 ++++++++++++++----- .../Shared/Api/Implementation/OSSL_Api.cs | 6 +-- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index cac8479142..3ec1bda71f 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs @@ -52,6 +52,14 @@ namespace OpenSim.Region.Framework.Interfaces /// True if the agent is an NPC in the given scene. False otherwise. bool IsNPC(UUID agentID, Scene scene); + /// + /// Check if the caller has permission to manipulate the given NPC. + /// + /// + /// + /// true if they do, false if they don't or if there's no NPC with the given ID. + bool CheckPermissions(UUID npcID, UUID callerID); + /// /// Set the appearance for an NPC. /// diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index e87441703a..8f9b513b9b 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 bool CheckPermissions(UUID npcID, UUID callerID) { + lock (m_avatars) + { + NPCAvatar av; + if (m_avatars.TryGetValue(npcID, out av)) + return CheckPermissions(av, callerID); + else + return false; + } } - public void Close() + /// + /// 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) { - } - - public string Name - { - get { return "NPCModule"; } - } - - public bool IsSharedModule - { - get { return true; } + return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index e2a045b00b..1d7a2105ac 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2152,11 +2152,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return new LSL_Key(UUID.Zero.ToString()); - if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) - return new LSL_Key(UUID.Zero.ToString()); - - UUID ownerID = npcModule.GetOwner(npcId); - if (ownerID != UUID.Zero && ownerID != m_host.OwnerID) + if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) return new LSL_Key(UUID.Zero.ToString()); return SaveAppearanceToNotecard(npcId, notecard); From cadd645076eacd6bd0b70a665ed3f5157cd6e5d3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 12 Jan 2012 10:22:52 -0800 Subject: [PATCH 03/12] Renamed one var and deleted commented code. No functional changes. --- .../UserManagement/UserManagementModule.cs | 35 ++----------------- .../Framework/Interfaces/IUserManagement.cs | 2 +- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 2ad30a0a0d..80ab30c3ef 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -413,14 +413,13 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement user.Id = uuid; user.FirstName = first; user.LastName = last; - // user.ProfileURL = we should initialize this to the default AddUserInternal(user); } - public void AddUser(UUID uuid, string first, string last, string profileURL) + public void AddUser(UUID uuid, string first, string last, string homeURL) { - AddUser(uuid, profileURL + ";" + first + " " + last); + AddUser(uuid, homeURL + ";" + first + " " + last); } public void AddUser (UUID id, string creatorData) @@ -492,36 +491,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement // user.Id, user.FirstName, user.LastName, user.HomeURL); } - //public void AddUser(UUID uuid, string userData) - //{ - // if (m_UserCache.ContainsKey(uuid)) - // return; - - // UserData user = new UserData(); - // user.Id = uuid; - - // // userData = ; - // string[] parts = userData.Split(';'); - // if (parts.Length >= 1) - // user.ProfileURL = parts[0].Trim(); - // if (parts.Length >= 2) - // { - // string[] name = parts[1].Trim().Split(' '); - // if (name.Length >= 1) - // user.FirstName = name[0]; - // if (name.Length >= 2) - // user.LastName = name[1]; - // else - // user.LastName = "?"; - // } - - // lock (m_UserCache) - // m_UserCache.Add(uuid, user); - - // m_log.DebugFormat("[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}", user.Id, user.FirstName, user.LastName, user.ProfileURL); - - //} - public bool IsLocalGridUser(UUID uuid) { UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid); diff --git a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs index 54dfaf4c63..4f62e28789 100644 --- a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs +++ b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs @@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// - void AddUser(UUID uuid, string firstName, string lastName, string profileURL); + void AddUser(UUID uuid, string firstName, string lastName, string homeURL); bool IsLocalGridUser(UUID uuid); } From ba3491c76e2d7cc7187a025dccd782790929f0b7 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 19:06:46 +0000 Subject: [PATCH 04/12] Add permissions checks for owned avatars to all other osNpc* functions. This is being done outside the npc module since the check is meaningless for region module callers, who can fake any id that they like. --- .../Region/Framework/Interfaces/INPCModule.cs | 2 +- .../OptionalModules/World/NPC/NPCModule.cs | 5 +- .../Shared/Api/Implementation/OSSL_Api.cs | 70 +++++++++++++------ 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index 3ec1bda71f..c50e734c18 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs @@ -125,7 +125,7 @@ namespace OpenSim.Region.Framework.Interfaces /// The UUID of the NPC /// /// True if the operation succeeded, false if there was no such agent or the agent was not an NPC - bool DeleteNPC(UUID agentID, UUID CallerID, Scene scene); + bool DeleteNPC(UUID agentID, Scene scene); /// /// Get the owner of a NPC diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 8f9b513b9b..d90309f66f 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -266,16 +266,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC return UUID.Zero; } - public bool DeleteNPC(UUID agentID, UUID callerID, Scene scene) + public bool DeleteNPC(UUID agentID, Scene scene) { lock (m_avatars) { NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { - if (!CheckPermissions(av, callerID)); - return false; - scene.RemoveClient(agentID, false); m_avatars.Remove(agentID); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 1d7a2105ac..509bbecde9 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2173,6 +2173,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return; + if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) + return; + string appearanceSerialized = LoadNotecard(notecard); OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); @@ -2196,7 +2199,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return new LSL_Vector(0, 0, 0); - if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) return new LSL_Vector(0, 0, 0); Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition; @@ -2216,6 +2219,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID npcId; if (!UUID.TryParse(npc.m_string, out npcId)) return; + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); module.MoveToTarget(npcId, World, pos, false, true); @@ -2233,6 +2239,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return; + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); module.MoveToTarget( new UUID(npc.m_string), @@ -2254,7 +2263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); - if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); ScenePresence sp = World.GetScenePresence(npcId); @@ -2277,7 +2286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!UUID.TryParse(npc.m_string, out npcId)) return; - if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) + if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) return; ScenePresence sp = World.GetScenePresence(npcId); @@ -2291,7 +2300,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) - module.StopMoveToTarget(new UUID(npc.m_string), World); + { + UUID npcId = new UUID(npc.m_string); + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + + module.StopMoveToTarget(npcId, World); + } } public void osNpcSay(LSL_Key npc, string message) @@ -2301,7 +2317,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - module.Say(new UUID(npc.m_string), World, message); + UUID npcId = new UUID(npc.m_string); + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + + module.Say(npcId, World, message); } } @@ -2312,7 +2333,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - module.Sit(new UUID(npc.m_string), new UUID(target.m_string), World); + UUID npcId = new UUID(npc.m_string); + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + + module.Sit(npcId, new UUID(target.m_string), World); } } @@ -2323,7 +2349,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - module.Stand(new UUID(npc.m_string), World); + UUID npcId = new UUID(npc.m_string); + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + + module.Stand(npcId, World); } } @@ -2334,7 +2365,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - module.DeleteNPC(new UUID(npc.m_string), m_host.OwnerID, World); + UUID npcId = new UUID(npc.m_string); + + if (!module.CheckPermissions(npcId, m_host.OwnerID)) + return; + + module.DeleteNPC(npcId, World); } } @@ -2346,12 +2382,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (module != null) { UUID npcID = new UUID(npc.m_string); - if (module.IsNPC(npcID, m_host.ParentGroup.Scene)) - { - UUID ownerID = module.GetOwner(npcID); - if (ownerID == UUID.Zero || ownerID == m_host.OwnerID) - AvatarPlayAnimation(npcID.ToString(), animation); - } + + if (module.CheckPermissions(npcID, m_host.OwnerID)) + AvatarPlayAnimation(npcID.ToString(), animation); } } @@ -2363,12 +2396,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (module != null) { UUID npcID = new UUID(npc.m_string); - if (module.IsNPC(npcID, m_host.ParentGroup.Scene)) - { - UUID ownerID = module.GetOwner(npcID); - if (ownerID == UUID.Zero || ownerID == m_host.OwnerID) - AvatarStopAnimation(npcID.ToString(), animation); - } + + if (module.CheckPermissions(npcID, m_host.OwnerID)) + AvatarPlayAnimation(npcID.ToString(), animation); } } From d27dd3714f77aa37db1eeb241401270163cd236d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 19:19:34 +0000 Subject: [PATCH 05/12] Allow all NPCs to show up on sensors as all osNpc* script methods now check for ownership permission before executing. As per #opensim-dev irc discussion. --- .../Api/Implementation/Plugins/SensorRepeat.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 7d7813dd68..8356dced80 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -463,12 +463,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins toRegionPos = presence.AbsolutePosition; dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); - if (presence.PresenceType == PresenceType.Npc && npcModule != null) - { - UUID npcOwner = npcModule.GetOwner(presence.UUID); - if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID) - return; - } + // Disabled for now since all osNpc* methods check for appropriate ownership permission. + // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not + // sensed might be useful. +// if (presence.PresenceType == PresenceType.Npc && npcModule != null) +// { +// UUID npcOwner = npcModule.GetOwner(presence.UUID); +// if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID) +// return; +// } // are they in range if (dis <= ts.range) From c4972e773465172d33d72f94d3f5e37cec1b8831 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 19:37:30 +0000 Subject: [PATCH 06/12] Add osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) variant. This will be documented soon. Options can currently be OS_NPC_CREATE_OWNED - creates a 'creator owned' avatar that will only respond to osNpc* functions made by scripts owned by the npc creator OS_NPC_NOT_OWNED - creates an avatar which will respond to any osNpc* functions that a caller has permission to make (through the usual OSSL permission mechanisms). options is being added to provide better scope for future extensibility without having to add more functions The original non-options osNpcCreate() function will continue to exist. --- .../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 6 ++++++ .../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 3 +++ OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 509bbecde9..25e4789c3a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2089,6 +2089,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return NpcCreate(firstname, lastname, position, notecard, false); } + public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) + { + CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); + return NpcCreate(firstname, lastname, position, notecard, (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0); + } + private LSL_Key NpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, bool owned) { INPCModule module = World.RequestModuleInterface(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index f92f51faef..ddfc20d8e2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -172,6 +172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); key osNpcCreate(string user, string name, vector position, string notecard); + key osNpcCreate(string user, string name, vector position, string notecard, int options); key osNpcCreateOwned(string user, string name, vector position, string notecard); LSL_Key osNpcSaveAppearance(key npc, string notecard); void osNpcLoadAppearance(key npc, string notecard); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index b58cf570f0..176dc560ea 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -606,6 +606,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int OS_NPC_SIT_NOW = 0; + public const int OS_NPC_CREATOR_OWNED = 0x1; + public const int OS_NPC_NOT_OWNED = 0x2; + public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index a94392a27a..ceccceb82c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -488,6 +488,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); } + public key osNpcCreate(string user, string name, vector position, key cloneFrom, int options) + { + return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom, options); + } + public key osNpcCreateOwned(string user, string name, vector position, key cloneFrom) { return m_OSSL_Functions.osNpcCreateOwned(user, name, position, cloneFrom); From 1ac5aa68087910dbb3cdfc141d77a95eb89177fa Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 20:47:19 +0000 Subject: [PATCH 07/12] Add remove test for unowned avatars --- .../World/NPC/Tests/NPCModuleTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 571d33d9ce..d21d601482 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -118,6 +118,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); } + [Test] + public void TestRemove() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); +// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); + + Vector3 startPos = new Vector3(128, 128, 30); + INPCModule npcModule = scene.RequestModuleInterface(); + UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); + + npcModule.DeleteNPC(npcId, scene); + + ScenePresence deletedNpc = scene.GetScenePresence(npcId); + + Assert.That(deletedNpc, Is.Null); + } + [Test] public void TestAttachments() { From caa207f59f5c7e9160715172e22bd59659abbeb4 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 21:03:54 +0000 Subject: [PATCH 08/12] Add ossl level test for removing an unowned npc --- .../Shared/Tests/OSSL_ApiNpcTests.cs | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs new file mode 100644 index 0000000000..c4832c96c4 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs @@ -0,0 +1,115 @@ +/* + * 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 System.Text; +using log4net; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenMetaverse.Assets; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Region.CoreModules.Avatar.AvatarFactory; +using OpenSim.Region.OptionalModules.World.NPC; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.ScriptEngine.Shared; +using OpenSim.Region.ScriptEngine.Shared.Api; +using OpenSim.Region.ScriptEngine.Shared.ScriptBase; +using OpenSim.Services.Interfaces; +using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + /// + /// Tests for OSSL NPC API + /// + [TestFixture] + public class OSSL_NpcApiAppearanceTest + { + protected Scene m_scene; + protected XEngine.XEngine m_engine; + + [SetUp] + public void SetUp() + { + IConfigSource initConfigSource = new IniConfigSource(); + IConfig config = initConfigSource.AddConfig("XEngine"); + config.Set("Enabled", "true"); + config.Set("AllowOSFunctions", "true"); + config.Set("OSFunctionThreatLevel", "Severe"); + config = initConfigSource.AddConfig("NPC"); + config.Set("Enabled", "true"); + + m_scene = SceneHelpers.SetupScene(); + SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); + + m_engine = new XEngine.XEngine(); + m_engine.Initialise(initConfigSource); + m_engine.AddRegion(m_scene); + } + + /// + /// Test creation of an NPC where the appearance data comes from an avatar already in the region. + /// + [Test] + public void TestOsNpcRemove() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + // Store an avatar with a different height from default in a notecard. + UUID userId = TestHelpers.ParseTail(0x1); + float newHeight = 1.9f; + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); + sp.Appearance.AvatarHeight = newHeight; + SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); + SceneObjectPart part = so.RootPart; + m_scene.AddSceneObject(so); + + OSSL_Api osslApi = new OSSL_Api(); + osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); + + string notecardName = "appearanceNc"; + osslApi.osOwnerSaveAppearance(notecardName); + + string npcRaw + = osslApi.osNpcCreate( + "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED); + + osslApi.osNpcRemove(npcRaw); + + UUID npcId = new UUID(npcRaw); + ScenePresence npc = m_scene.GetScenePresence(npcId); + Assert.That(npc, Is.Null); + } + } +} \ No newline at end of file From beab155434b1ea4338004496fd35df2a22170960 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 22:35:11 +0000 Subject: [PATCH 09/12] Add api level test for removing an owned npc --- .../Shared/Tests/OSSL_ApiNpcTests.cs | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index c4832c96c4..f0b28b22de 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs @@ -77,10 +77,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests } /// - /// Test creation of an NPC where the appearance data comes from an avatar already in the region. + /// Test removal of an owned NPC. /// [Test] - public void TestOsNpcRemove() + public void TestOsNpcRemoveOwned() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + // Store an avatar with a different height from default in a notecard. + UUID userId = TestHelpers.ParseTail(0x1); + UUID otherUserId = TestHelpers.ParseTail(0x2); + float newHeight = 1.9f; + + SceneHelpers.AddScenePresence(m_scene, otherUserId); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); + sp.Appearance.AvatarHeight = newHeight; + + SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); + SceneObjectPart part = so.RootPart; + m_scene.AddSceneObject(so); + + SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId); + SceneObjectPart otherPart = otherSo.RootPart; + m_scene.AddSceneObject(otherSo); + + OSSL_Api osslApi = new OSSL_Api(); + osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); + + OSSL_Api otherOsslApi = new OSSL_Api(); + otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID); + + string notecardName = "appearanceNc"; + osslApi.osOwnerSaveAppearance(notecardName); + + string npcRaw + = osslApi.osNpcCreate( + "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED); + + otherOsslApi.osNpcRemove(npcRaw); + + // Should still be around + UUID npcId = new UUID(npcRaw); + ScenePresence npc = m_scene.GetScenePresence(npcId); + Assert.That(npc, Is.Not.Null); + + osslApi.osNpcRemove(npcRaw); + + npc = m_scene.GetScenePresence(npcId); + + } + + /// + /// Test removal of an unowned NPC. + /// + [Test] + public void TestOsNpcRemoveUnowned() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); From 47377f17c626515747f507014301c6c101791014 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Jan 2012 23:46:43 +0000 Subject: [PATCH 10/12] Add missing assert to confirm owner delete succeeded to the end of TestOsNpcRemoveOwned() --- OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index f0b28b22de..9d9fc514a3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs @@ -127,6 +127,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests npc = m_scene.GetScenePresence(npcId); + // Now the owner deleted it and it's gone + Assert.That(npc, Is.Null); } /// From 6e7154d55c4b5ab8dacd2bcbce3b5408470b7f48 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 13 Jan 2012 00:00:18 +0000 Subject: [PATCH 11/12] Removing osNpcCreateOwned(). Please use osNpcCreate(string user, string name, vector position, string notecard, int options) instead with option OS_NPC_CREATOR_OWNED Please note that correct option name is OS_NPC_CREATOR_OWNED not OS_NPC_CREATE_OWNED as mistakenly put in a previous commit. --- .../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 6 ------ .../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 - OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ----- 3 files changed, 12 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 25e4789c3a..2c35f58b1e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2077,12 +2077,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return retVal; } - public LSL_Key osNpcCreateOwned(string firstname, string lastname, LSL_Vector position, string notecard) - { - CheckThreatLevel(ThreatLevel.High, "osNpcCreateOwned"); - return NpcCreate(firstname, lastname, position, notecard, true); - } - public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) { CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index ddfc20d8e2..af6be5f78b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -173,7 +173,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces key osNpcCreate(string user, string name, vector position, string notecard); key osNpcCreate(string user, string name, vector position, string notecard, int options); - key osNpcCreateOwned(string user, string name, vector position, string notecard); LSL_Key osNpcSaveAppearance(key npc, string notecard); void osNpcLoadAppearance(key npc, string notecard); vector osNpcGetPos(key npc); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index ceccceb82c..0c05ea491c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -493,11 +493,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom, options); } - public key osNpcCreateOwned(string user, string name, vector position, key cloneFrom) - { - return m_OSSL_Functions.osNpcCreateOwned(user, name, position, cloneFrom); - } - public key osNpcSaveAppearance(key npc, string notecard) { return m_OSSL_Functions.osNpcSaveAppearance(npc, notecard); From 3b59af222580e6d6e1a938ab622961285bd6903c Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 13 Jan 2012 00:03:39 +0000 Subject: [PATCH 12/12] Change the default osNpcCreate() to create an 'owned' npc rather than an 'unowned' one. An owned NPC is one that only the original creator can manipulate and delete. An unowned NPC is one that anybody with access to the osNpc* methods and knowledge of the avatar id can manipulate. This is to correct an oversight I made in the original reimplementation where I mistakenly assumed that avatar IDs could be treated as private. I am not anticipating that many people were deliberately making use of unowned npcs due to their insecure nature. If you do need an unowned NPC please call the new overloaded osCreateNpc() function with the option OS_NPC_NOT_OWNED. --- .../Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 2c35f58b1e..40d9d6f47d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2080,7 +2080,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) { CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); - return NpcCreate(firstname, lastname, position, notecard, false); + return NpcCreate(firstname, lastname, position, notecard, true); } public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)