OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.llRemoteLoadScriptPin C# (CSharp) Method

llRemoteLoadScriptPin() public method

public llRemoteLoadScriptPin ( string target, string name, int pin, int running, int start_param ) : void
target string
name string
pin int
running int
start_param int
return void
        public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
        {
            m_host.AddScriptLPS(1);

            UUID destId = UUID.Zero;

            if (!UUID.TryParse(target, out destId))
            {
                Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
                return;
            }

            // target must be a different prim than the one containing the script
            if (m_host.UUID == destId)
            {
                return;
            }

            // copy the first script found with this inventory name
            TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);

            // make sure the object is a script
            if (item == null || item.Type != 10)
            {
                Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
                return;
            }

            SceneObjectPart dest = World.GetSceneObjectPart(destId);
            if (dest != null)
            {
                if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
                {
                    // the rest of the permission checks are done in RezScript, so check the pin there as well
                    World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);

                    if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
                        m_host.Inventory.RemoveInventoryItem(item.ItemID);
                }
            }
            // this will cause the delay even if the script pin or permissions were wrong - seems ok
            ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
        }

Usage Example

        public void TestLlRemoteLoadScriptPin()
        {
            TestHelpers.InMethod();
//                        TestHelpers.EnableLogging();

            UUID user1Id = TestHelpers.ParseTail(0x1);
            UUID user2Id = TestHelpers.ParseTail(0x2);

            SceneObjectGroup sourceSo = SceneHelpers.AddSceneObject(m_scene, "sourceSo", user1Id);
            m_scene.AddSceneObject(sourceSo);
            LSL_Api api = new LSL_Api();
            api.Initialize(m_engine, sourceSo.RootPart, null);
            TaskInventoryHelpers.AddScript(m_scene.AssetService, sourceSo.RootPart, "script", "Hello World");

            SceneObjectGroup targetSo = SceneHelpers.AddSceneObject(m_scene, "targetSo", user1Id);
            SceneObjectGroup otherOwnedTargetSo = SceneHelpers.AddSceneObject(m_scene, "otherOwnedTargetSo", user2Id);

            // Test that we cannot load a script when the target pin has never been set (i.e. it is zero)
            api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 0, 0, 0);
            Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));

            // Test that we cannot load a script when the given pin does not match the target
            targetSo.RootPart.ScriptAccessPin = 5;
            api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0);
            Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));

            // Test that we cannot load into a prim with a different owner
            otherOwnedTargetSo.RootPart.ScriptAccessPin = 3;
            api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0);
            Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script"));

            // Test that we can load a script when given pin and dest pin match.
            targetSo.RootPart.ScriptAccessPin = 3;
            api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0);
            TaskInventoryItem insertedItem = targetSo.RootPart.Inventory.GetInventoryItem("script");
            Assert.IsNotNull(insertedItem);

            // Test that we can no longer load if access pin is unset
            targetSo.RootPart.Inventory.RemoveInventoryItem(insertedItem.ItemID);
            Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));

            targetSo.RootPart.ScriptAccessPin = 0;
            api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0);
            Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script"));
        }
LSL_Api