From 9869ca83b464d3d88cf3f48ff65ea406168c0516 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 4 Jan 2013 20:54:11 +0000 Subject: Fix llGetLinkName() to return the name of the last avatar sat as the last link number. As per http://wiki.secondlife.com/wiki/LlGetLinkName --- .../Shared/Api/Implementation/LSL_Api.cs | 76 ++++++++++------------ 1 file changed, 35 insertions(+), 41 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index f31bbff..f0e0f1a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3824,62 +3824,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String llGetLinkName(int linknum) { m_host.AddScriptLPS(1); - // simplest case, this prims link number - if (linknum == m_host.LinkNum || linknum == ScriptBaseClass.LINK_THIS) - return m_host.Name; - // parse for sitting avatare-names - List nametable = new List(); - World.ForEachRootScenePresence(delegate(ScenePresence presence) - { - SceneObjectPart sitPart = presence.ParentPart; - if (sitPart != null && m_host.ParentGroup.ContainsPart(sitPart.LocalId)) - nametable.Add(presence.ControllingClient.Name); - }); - - int totalprims = m_host.ParentGroup.PrimCount + nametable.Count; - if (totalprims > m_host.ParentGroup.PrimCount) + if (linknum < 0) { - // sitting Avatar-Name with negativ linknum / SinglePrim - if (linknum < 0 && m_host.ParentGroup.PrimCount == 1 && nametable.Count == 1) - return nametable[0]; - // Prim-Name / SinglePrim Sitting Avatar - if (linknum == 1 && m_host.ParentGroup.PrimCount == 1 && nametable.Count == 1) + if (linknum == ScriptBaseClass.LINK_THIS) return m_host.Name; - // LinkNumber > of Real PrimSet = AvatarName - if (linknum > m_host.ParentGroup.PrimCount && linknum <= totalprims) - return nametable[totalprims - linknum]; + else + return ScriptBaseClass.NULL_KEY; } - // Single prim - if (m_host.LinkNum == 0) + int actualPrimCount = m_host.ParentGroup.PrimCount; + List sittingAvatarIds = m_host.ParentGroup.GetSittingAvatars(); + int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count; + + // Special case for a single prim. In this case the linknum is zero. However, this will not match a single + // prim that has any avatars sat upon it (in which case the root prim is link 1). + if (linknum == 0) { - if (linknum == 0 || linknum == ScriptBaseClass.LINK_ROOT) + if (actualPrimCount == 1 && sittingAvatarIds.Count == 0) return m_host.Name; - else - return UUID.Zero.ToString(); - } - // Link set - SceneObjectPart part = null; - if (m_host.LinkNum == 1) // this is the Root prim + return ScriptBaseClass.NULL_KEY; + } + // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but + // here we must match 1 (ScriptBaseClass.LINK_ROOT). + else if (linknum == 1 && actualPrimCount == 1) { - if (linknum < 0) - part = m_host.ParentGroup.GetLinkNumPart(2); + if (sittingAvatarIds.Count > 0) + return m_host.ParentGroup.RootPart.Name; else - part = m_host.ParentGroup.GetLinkNumPart(linknum); + return ScriptBaseClass.NULL_KEY; } - else // this is a child prim + else if (linknum <= adjustedPrimCount) { - if (linknum < 2) - part = m_host.ParentGroup.GetLinkNumPart(1); + if (linknum <= actualPrimCount) + { + return m_host.ParentGroup.GetLinkNumPart(linknum).Name; + } else - part = m_host.ParentGroup.GetLinkNumPart(linknum); + { + ScenePresence sp = World.GetScenePresence(sittingAvatarIds[linknum - actualPrimCount - 1]); + if (sp != null) + return sp.Name; + else + return ScriptBaseClass.NULL_KEY; + } } - if (part != null) - return part.Name; else - return UUID.Zero.ToString(); + { + return ScriptBaseClass.NULL_KEY; + } } public LSL_Integer llGetInventoryNumber(int type) -- cgit v1.1