From 33dd74e410bcd95364d8029a3f2a21b522c9f9d2 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 8 Apr 2011 03:50:27 +0200 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. --- .../World/Land/LandManagementModule.cs | 1 - OpenSim/Region/Framework/Scenes/Scene.cs | 12 ++--- .../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 ++++++++ 7 files changed, 103 insertions(+), 11 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index fae4f90b12..9905a53370 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs @@ -1264,7 +1264,6 @@ namespace OpenSim.Region.CoreModules.World.Land { land.DeedToGroup(groupID); } - EventManagerOnParcelPrimCountTainted(); } #region Land Object From Storage Functions diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 2e82e1f37f..0e3cffb039 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1337,12 +1337,12 @@ namespace OpenSim.Region.Framework.Scenes terrainMS = Util.EnvironmentTickCountSubtract(terMS); } - if (Frame % m_update_land == 0) - { - int ldMS = Util.EnvironmentTickCount(); - UpdateLand(); - landMS = Util.EnvironmentTickCountSubtract(ldMS); - } + // if (Frame % m_update_land == 0) + // { + // int ldMS = Util.EnvironmentTickCount(); + // UpdateLand(); + // landMS = Util.EnvironmentTickCountSubtract(ldMS); + // } frameMS = Util.EnvironmentTickCountSubtract(tmpFrameMS); otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index c0b490af49..8ceb814ff0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -10909,6 +10909,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return GetNumberOfSides(parts[0]); } + + 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 c4f90d21c7..3afedc72f9 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)); } @@ -505,9 +506,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 bae7d4b78b..0ae23882ad 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 c31e5d3092..5f94ff5b35 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 7c26824197..63cac9a134 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -896,6 +896,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);