From abea0c74c2b092d0474880a30433d9d0a2400aa8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 8 Apr 2011 04:19:17 +0100 Subject: [PATCH] Add support for the new display name related functions in LSL. This does not implement the display names functionality as such, but it allows scripts that are display name aware to function as if the display name were implemented and set to the avatar name. --- .../Shared/Api/Implementation/LSL_Api.cs | 49 +++++++++++++++++++ .../Implementation/Plugins/SensorRepeat.cs | 26 ++++++++-- .../Shared/Api/Interface/ILSL_Api.cs | 4 ++ .../Shared/Api/Runtime/LSL_Constants.cs | 2 + .../Shared/Api/Runtime/LSL_Stub.cs | 20 ++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index e5be641d26..c16a985564 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -10268,6 +10268,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_log.Info("LSL print():" + str); } } + + private string Name2Username(string name) + { + string[] parts = name.Split(new char[] {' '}); + if (parts.Length < 2) + return name.ToLower(); + if (parts[1] == "Resident") + return parts[0].ToLower(); + + return name.Replace(" ", ".").ToLower(); + } + + public LSL_String llGetUsername(string id) + { + return Name2Username(llKey2Name(id)); + } + + public LSL_String llRequestUsername(string id) + { + UUID rq = UUID.Random(); + + UUID tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, rq.ToString()); + + AsyncCommands. + DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); + + return rq.ToString(); + } + + public LSL_String llGetDisplayName(string id) + { + return llKey2Name(id); + } + + public LSL_String llRequestDisplayName(string id) + { + UUID rq = UUID.Random(); + + UUID tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, rq.ToString()); + + AsyncCommands. + DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); + + return rq.ToString(); + } } public class NotecardCache diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index fefbb35760..47c7915a3e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -50,6 +50,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins private Object SenseLock = new Object(); private const int AGENT = 1; + private const int AGENT_BY_USERNAME = 0x10; private const int ACTIVE = 2; private const int PASSIVE = 4; private const int SCRIPTED = 8; @@ -202,7 +203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins List sensedEntities = new List(); // Is the sensor type is AGENT and not SCRIPTED then include agents - if ((ts.type & AGENT) != 0 && (ts.type & SCRIPTED) == 0) + if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0) { sensedEntities.AddRange(doAgentSensor(ts)); } @@ -493,9 +494,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { ScenePresence sp; // Try lookup by name will return if/when found - if (!m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) - return sensedEntities; - senseEntity(sp); + if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) + senseEntity(sp); + if ((ts.type & AGENT_BY_USERNAME) != 0) + { + m_CmdManager.m_ScriptEngine.World.ForEachScenePresence( + delegate (ScenePresence ssp) + { + if (ssp.Lastname == "Resident") + { + if (ssp.Firstname.ToLower() == ts.name) + senseEntity(ssp); + return; + } + if (ssp.Name.Replace(" ", ".").ToLower() == ts.name) + senseEntity(ssp); + } + ); + } + + return sensedEntities; } else { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index bd6a094aa7..654ea8129a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -209,6 +209,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void llInstantMessage(string user, string message); LSL_String llIntegerToBase64(int number); LSL_String llKey2Name(string id); + LSL_String llGetUsername(string id); + LSL_String llRequestUsername(string id); + LSL_String llGetDisplayName(string id); + LSL_String llRequestDisplayName(string id); void llLinkParticleSystem(int linknum, LSL_List rules); LSL_String llList2CSV(LSL_List src); LSL_Float llList2Float(LSL_List src, int index); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index b3c4d95c48..9377cdafd8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -50,6 +50,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int STATUS_CAST_SHADOWS = 512; public const int AGENT = 1; + public const int AGENT_BY_LEGACY_NAME = 1; + public const int AGENT_BY_USERNAME = 0x10; public const int ACTIVE = 2; public const int PASSIVE = 4; public const int SCRIPTED = 8; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 3b298615d0..303d75e36d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -894,6 +894,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_LSL_Functions.llKey2Name(id); } + public LSL_String llGetUsername(string id) + { + return m_LSL_Functions.llGetUsername(id); + } + + public LSL_String llRequestUsername(string id) + { + return m_LSL_Functions.llRequestUsername(id); + } + + public LSL_String llGetDisplayName(string id) + { + return m_LSL_Functions.llGetDisplayName(id); + } + + public LSL_String llRequestDisplayName(string id) + { + return m_LSL_Functions.llRequestDisplayName(id); + } + public void llLinkParticleSystem(int linknum, LSL_List rules) { m_LSL_Functions.llLinkParticleSystem(linknum, rules);