From 9939f94f08b33e3dd9eeea65b730f0ddc80275a5 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 27 Jan 2012 23:05:48 +0000 Subject: [PATCH 1/3] Implement osNpcGetOwner(key npc):key. This returns the owner for an 'owned' NPC, the npc's own key for an 'unowned' NPC and NULL_KEY is the input key was not an npc. llGetOwnerKey() could also be extended but this does not allow one to distinguish between an unowned NPC and some other result (e.g. 'no such object' if NULL_KEY is the return. Also, any future extensions to LSL functions by Linden Lab are unpredictable and OpenSim-specific extensions could clash. --- .../Region/Framework/Interfaces/INPCModule.cs | 2 +- .../Shared/Api/Implementation/OSSL_Api.cs | 21 +++++++++ .../Shared/Api/Interface/IOSSL_Api.cs | 46 +++++++++++-------- .../Shared/Api/Runtime/OSSL_Stub.cs | 5 ++ 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index c50e734c18..b428c40a61 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs @@ -134,4 +134,4 @@ namespace OpenSim.Region.Framework.Interfaces /// UUID of owner if the NPC exists, UUID.Zero if there was no such agent, the agent is unowned or the agent was not an NPC UUID GetOwner(UUID agentID); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 7792ab587e..ba96ad8a97 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2313,6 +2313,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + public LSL_Key osNpcGetOwner(LSL_Key npc) + { + CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner"); + + INPCModule npcModule = World.RequestModuleInterface(); + if (npcModule != null) + { + UUID npcId; + if (UUID.TryParse(npc.m_string, out npcId)) + { + UUID owner = npcModule.GetOwner(npcId); + if (owner != UUID.Zero) + return new LSL_Key(owner.ToString()); + else + return npc; + } + } + + return new LSL_Key(UUID.Zero.ToString()); + } + public LSL_Vector osNpcGetPos(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 0f8cbdc7b2..ee48ec4be7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -173,25 +173,35 @@ 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); - LSL_Key osNpcSaveAppearance(key npc, string notecard); - void osNpcLoadAppearance(key npc, string notecard); - vector osNpcGetPos(key npc); - void osNpcMoveTo(key npc, vector position); - void osNpcMoveToTarget(key npc, vector target, int options); - rotation osNpcGetRot(key npc); - void osNpcSetRot(LSL_Key npc, rotation rot); - void osNpcStopMoveToTarget(LSL_Key npc); - void osNpcSay(key npc, string message); - void osNpcSit(key npc, key target, int options); - void osNpcStand(LSL_Key npc); - void osNpcRemove(key npc); - void osNpcPlayAnimation(LSL_Key npc, string animation); - void osNpcStopAnimation(LSL_Key npc, string animation); + key osNpcCreate(string user, string name, vector position, string notecard); + key osNpcCreate(string user, string name, vector position, string notecard, int options); + LSL_Key osNpcSaveAppearance(key npc, string notecard); + void osNpcLoadAppearance(key npc, string notecard); + vector osNpcGetPos(key npc); + void osNpcMoveTo(key npc, vector position); + void osNpcMoveToTarget(key npc, vector target, int options); - LSL_Key osOwnerSaveAppearance(string notecard); - LSL_Key osAgentSaveAppearance(key agentId, string notecard); + /// + /// Get the owner of the NPC + /// + /// + /// + /// The owner of the NPC for an owned NPC. The NPC's agent id for an unowned NPC. UUID.Zero if the key is not an npc. + /// + LSL_Key osNpcGetOwner(key npc); + + rotation osNpcGetRot(key npc); + void osNpcSetRot(LSL_Key npc, rotation rot); + void osNpcStopMoveToTarget(LSL_Key npc); + void osNpcSay(key npc, string message); + void osNpcSit(key npc, key target, int options); + void osNpcStand(LSL_Key npc); + void osNpcRemove(key npc); + void osNpcPlayAnimation(LSL_Key npc, string animation); + void osNpcStopAnimation(LSL_Key npc, string animation); + + LSL_Key osOwnerSaveAppearance(string notecard); + LSL_Key osAgentSaveAppearance(key agentId, string notecard); key osGetMapTexture(); key osGetRegionMapTexture(string regionName); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 02efecf13e..38a814d30c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -513,6 +513,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_OSSL_Functions.osNpcLoadAppearance(npc, notecard); } + public LSL_Key osNpcGetOwner(LSL_Key npc) + { + return m_OSSL_Functions.osNpcGetOwner(npc); + } + public vector osNpcGetPos(LSL_Key npc) { return m_OSSL_Functions.osNpcGetPos(npc); From 7c1d075a5a72dd9411e40676054b648b26f116a6 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 27 Jan 2012 23:17:13 +0000 Subject: [PATCH 2/3] Implement osIsNpc(key npc):integer. This return TRUE if the given key belongs to an NPC in the region. FALSE if not or if the NPC module isn't present. --- .../Shared/Api/Implementation/OSSL_Api.cs | 17 +++++++++++++++++ .../Shared/Api/Interface/IOSSL_Api.cs | 7 +++++++ .../Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index ba96ad8a97..034d54582f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2202,6 +2202,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return retVal; } + public LSL_Integer osIsNpc(LSL_Key npc) + { + CheckThreatLevel(ThreatLevel.None, "osIsNpc"); + m_host.AddScriptLPS(1); + + INPCModule module = World.RequestModuleInterface(); + if (module != null) + { + UUID npcId; + if (UUID.TryParse(npc.m_string, out npcId)) + if (module.IsNPC(npcId, World)) + return ScriptBaseClass.TRUE; + } + + return ScriptBaseClass.FALSE; + } + 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 ee48ec4be7..dbc1dfc804 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -173,6 +173,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); + /// + /// Check if the given key is an npc + /// + /// + /// TRUE if the key belongs to an npc in the scene. FALSE otherwise. + LSL_Integer osIsNpc(LSL_Key npc); + key osNpcCreate(string user, string name, vector position, string notecard); key osNpcCreate(string user, string name, vector position, string notecard, int options); LSL_Key osNpcSaveAppearance(key npc, string notecard); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 38a814d30c..cc8d417d64 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -493,6 +493,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osGetLinkPrimitiveParams(linknumber, rules); } + public LSL_Integer osIsNpc(LSL_Key npc) + { + return m_OSSL_Functions.osIsNpc(npc); + } + public key osNpcCreate(string user, string name, vector position, key cloneFrom) { return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); From 31b87ff07b7442e2fc74936e4da0084118123285 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 27 Jan 2012 23:24:49 +0000 Subject: [PATCH 3/3] Increment LPS script stat for OSSL functions that were not already doing this --- .../Shared/Api/Implementation/OSSL_Api.cs | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 034d54582f..a2f5c921aa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -416,6 +416,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer osSetTerrainHeight(int x, int y, double val) { CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); + return SetTerrainHeight(x, y, val); } @@ -423,12 +424,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); + return SetTerrainHeight(x, y, val); } private LSL_Integer SetTerrainHeight(int x, int y, double val) { m_host.AddScriptLPS(1); + if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0) OSSLError("osSetTerrainHeight: Coordinate out of bounds"); @@ -468,6 +471,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osTerrainFlush() { CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush"); + m_host.AddScriptLPS(1); ITerrainModule terrainModule = World.RequestModuleInterface(); if (terrainModule != null) terrainModule.TaintTerrain(); @@ -884,6 +888,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // threat level is None as we could get this information with an // in-world script as well, just not as efficient CheckThreatLevel(ThreatLevel.None, "osGetAgents"); + m_host.AddScriptLPS(1); LSL_List result = new LSL_List(); World.ForEachRootScenePresence(delegate(ScenePresence sp) @@ -1164,6 +1169,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // should be removed // CheckThreatLevel(ThreatLevel.High, "osSetStateEvents"); + m_host.AddScriptLPS(1); m_host.SetScriptEvents(m_itemID, events); } @@ -1511,7 +1517,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); - ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); @@ -1572,6 +1577,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion"); m_host.AddScriptLPS(1); + return m_ScriptEngine.World.GetSimulatorVersion(); } @@ -1909,6 +1915,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public string osAvatarName2Key(string firstname, string lastname) { CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); + m_host.AddScriptLPS(1); UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname); if (null == account) @@ -1924,6 +1931,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public string osKey2Name(string id) { CheckThreatLevel(ThreatLevel.Low, "osKey2Name"); + m_host.AddScriptLPS(1); + UUID key = new UUID(); if (UUID.TryParse(id, out key)) @@ -2222,12 +2231,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) { CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); + m_host.AddScriptLPS(1); + return NpcCreate(firstname, lastname, position, notecard, true); } public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) { CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); + m_host.AddScriptLPS(1); + return NpcCreate(firstname, lastname, position, notecard, (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0); } @@ -2285,6 +2298,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard) { CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); @@ -2306,6 +2320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcLoadAppearance(LSL_Key npc, string notecard) { CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); @@ -2333,6 +2348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osNpcGetOwner(LSL_Key npc) { CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) @@ -2354,6 +2370,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Vector osNpcGetPos(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) @@ -2375,6 +2392,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) { CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2394,6 +2412,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options) { CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2418,6 +2437,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Rotation osNpcGetRot(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcGetRot"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) @@ -2441,6 +2461,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) { CheckThreatLevel(ThreatLevel.High, "osNpcSetRot"); + m_host.AddScriptLPS(1); INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) @@ -2460,6 +2481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcStopMoveToTarget(LSL_Key npc) { CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2476,6 +2498,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcSay(LSL_Key npc, string message) { CheckThreatLevel(ThreatLevel.High, "osNpcSay"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2492,6 +2515,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcSit(LSL_Key npc, LSL_Key target, int options) { CheckThreatLevel(ThreatLevel.High, "osNpcSit"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2508,6 +2532,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcStand(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcStand"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2524,6 +2549,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcRemove(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2540,6 +2566,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcPlayAnimation(LSL_Key npc, string animation) { CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2554,6 +2581,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osNpcStopAnimation(LSL_Key npc, string animation) { CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation"); + m_host.AddScriptLPS(1); INPCModule module = World.RequestModuleInterface(); if (module != null) @@ -2573,6 +2601,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osOwnerSaveAppearance(string notecard) { CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance"); + m_host.AddScriptLPS(1); return SaveAppearanceToNotecard(m_host.OwnerID, notecard); } @@ -2580,6 +2609,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard) { CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance"); + m_host.AddScriptLPS(1); return SaveAppearanceToNotecard(avatarId, notecard); } @@ -2630,6 +2660,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osGetMapTexture() { CheckThreatLevel(ThreatLevel.None, "osGetMapTexture"); + m_host.AddScriptLPS(1); + return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString(); } @@ -2641,6 +2673,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key osGetRegionMapTexture(string regionName) { CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture"); + m_host.AddScriptLPS(1); + Scene scene = m_ScriptEngine.World; UUID key = UUID.Zero; GridRegion region; @@ -2706,6 +2740,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osKickAvatar(string FirstName,string SurName,string alert) { CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); + m_host.AddScriptLPS(1); + if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) { World.ForEachRootScenePresence(delegate(ScenePresence sp) @@ -2840,6 +2876,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_List osGetAvatarList() { CheckThreatLevel(ThreatLevel.None, "osGetAvatarList"); + m_host.AddScriptLPS(1); LSL_List result = new LSL_List(); World.ForEachRootScenePresence(delegate (ScenePresence avatar) @@ -2864,6 +2901,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String osUnixTimeToTimestamp(long time) { CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp"); + m_host.AddScriptLPS(1); + long baseTicks = 621355968000000000; long tickResolution = 10000000; long epochTicks = (time * tickResolution) + baseTicks; @@ -2872,4 +2911,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); } } -} +} \ No newline at end of file