コード例 #1
0
        public DateTime llCreateLink(string target, int parent)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
            {
                return(DateTime.Now);
            }

            UUID invItemID = InventorySelf();
            UUID targetID;

            if (!UUID.TryParse(target, out targetID))
            {
                return(DateTime.Now);
            }

            TaskInventoryItem item;

            lock (m_host.TaskInventory) {
                item = m_host.TaskInventory[invItemID];
            }

            if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 &&
                !m_automaticLinkPermission)
            {
                Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
                return(DateTime.Now);
            }

            IClientAPI     client = null;
            IScenePresence sp     = World.GetScenePresence(item.PermsGranter);

            if (sp != null)
            {
                client = sp.ControllingClient;
            }

            ISceneChildEntity targetPart = World.GetSceneObjectPart(targetID);

            if (targetPart.ParentEntity.RootChild.AttachmentPoint != 0)
            {
                return(DateTime.Now);
            }
            // Fail silently if attached
            ISceneEntity parentPrim = null;
            ISceneEntity childPrim  = null;

            if (parent != 0)
            {
                parentPrim = m_host.ParentEntity;
                childPrim  = targetPart.ParentEntity;
            }
            else
            {
                parentPrim = targetPart.ParentEntity;
                childPrim  = m_host.ParentEntity;
            }
            //                byte uf = childPrim.RootPart.UpdateFlag;
            parentPrim.LinkToGroup(childPrim);
            //                if (uf != (Byte)0)
            //                    parent.RootPart.UpdateFlag = uf;

            parentPrim.TriggerScriptChangedEvent(Changed.LINK);
            parentPrim.RootChild.CreateSelected = true;
            parentPrim.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);

            if (client != null)
            {
                parentPrim.GetProperties(client);
            }

            return(PScriptSleep(m_sleepMsOnCreateLink));
        }