Difference between revisions of "LlGetInventoryPermMask"

From Second Life Wiki
Jump to navigation Jump to search
(Added an example of testing whether either of two perms has been set)
m (match examples with llGetObjectPermMask)
Line 12: Line 12:
|constants={{LSL Constants Perm Mask}}
|constants={{LSL Constants Perm Mask}}
|examples=
|examples=
<lsl>// Complain unless this script is Open/ Yes Mod/ Yes Copy/ Yes Transfer.
<lsl>
if ((permsYouHave & permsYouWant) == permsYouWant)
    llSay(PUBLIC_CHANNEL, "You have the perms you want.");
else
    llSay(PUBLIC_CHANNEL, "You don't have the perms you want.");
</lsl>
<lsl>
integer ownerPerms = llGetInventoryPermMask("inventory item name goes here", MASK_OWNER);
integer copyAndModPerms = PERM_COPY | PERM_MODIFY;


warnIfClosed()
if ((ownerPerms & copyAndModPerms) == copyAndModPerms)
{      
    llSay(PUBLIC_CHANNEL, "Owner has copy & modify perms.");
     integer PERMS_OPEN = (PERM_MODIFY | PERM_COPY | PERM_TRANSFER);
else
     string item = llGetScriptName();
    llSay(PUBLIC_CHANNEL, "Owner does not have copy & modify perms.");
     integer everyonePerms = llGetInventoryPermMask(item, MASK_EVERYONE);
</lsl>
     integer nextPerms = llGetInventoryPermMask(item, MASK_NEXT);
<lsl>
     if ((everyonePerms & PERM_COPY))
string getPermsAsReadableString(integer perm)
     {
{
         if ((nextPerms & PERMS_OPEN) == PERMS_OPEN)
     integer fullPerms = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
         {
    integer copyModPerms = PERM_COPY | PERM_MODIFY;
            llOwnerSay("Open/ Yes Mod/ Yes Copy/ Yes Transfer/ Thank you");
     integer copyTransPerms = PERM_COPY | PERM_TRANSFER;
            return;
     integer modTransPerms = PERM_MODIFY | PERM_TRANSFER;
        }
     }
     string output = " perms: ";
     llSay(0, "Q: Open/ Yes Mod/ Yes Copy/ Yes Transfer? A: Not so!!!");
 
    if ((perm & fullPerms) == fullPerms)
        output += "full";
     else if ((perm & copyModPerms) == copyModPerms)
        output += "copy & modify";
     else if ((perm & copyTransPerms) == copyTransPerms)
         output += "copy & transfer";
    else if ((perm & modTransPerms) == modTransPerms)
         output += "modify & transfer";
    else if ((perm & PERM_COPY) == PERM_COPY)
        output += "copy";
    else if ((perm & PERM_TRANSFER) == PERM_TRANSFER)
        output += "transfer";
 
     //  Remember, items in Second Life must have either
     //  PERM_COPY or PERM_TRANSFER when "talking about"
    // owner perms or perms for next owner.
 
    return
        output;
}
}


default
default
{
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
     state_entry()
     state_entry()
     {
     {
         warnIfClosed();
         string inventoryItemName = "inventory item name goes here";
    }
 
}</lsl>
        integer basePerms = llGetInventoryPermMask(inventoryItemName MASK_BASE);
        integer ownerPerms = llGetInventoryPermMask(inventoryItemName MASK_OWNER);
        integer nextOwnerPerms = llGetInventoryPermMask(inventoryItemName MASK_NEXT);
        integer groupPerms = llGetInventoryPermMask(inventoryItemName MASK_GROUP);
        integer everyonePerms = llGetInventoryPermMask(inventoryItemName MASK_EVERYONE);


    //  PUBLIC_CHANNEL has the integer value 0


        llSay(PUBLIC_CHANNEL, "/me [" + inventoryItemName
            + "]: base" + getPermsAsReadableString(basePerms));
        llSay(PUBLIC_CHANNEL, "/me [" + inventoryItemName
            + "]: owner" + getPermsAsReadableString(ownerPerms));
        llSay(PUBLIC_CHANNEL, "/me [" + inventoryItemName
            + "]: next owner" + getPermsAsReadableString(nextOwnerPerms));
        llSay(PUBLIC_CHANNEL, "/me [" + inventoryItemName
            + "]: group" + getPermsAsReadableString(groupPerms));
        llSay(PUBLIC_CHANNEL, "/me [" + inventoryItemName
            + "]: everyone" + getPermsAsReadableString(everyonePerms));
    }
}
</lsl>
To test for the opposite (e.g. to see if something is NOT copy):
To test for the opposite (e.g. to see if something is NOT copy):
 
<lsl>
<lsl>((PERM_COPY & llGetInventoryPermMask(myitem, MASK_OWNER)) == 0)</lsl>
    if (!(PERM_COPY & llGetInventoryPermMask(myitem, MASK_OWNER)))
        llSay(PUBLIC_CHANNEL, "/me [" + myitem + "]: owner doesn't have copy perms.");
</lsl>


To remind the next owner what permissions to set before selling on
To remind the next owner what permissions to set before selling on
choose which need to be set;
choose which need to be set;


<lsl>CheckPerms()
<lsl>
CheckPerms()
{         
{         
     string item = llGetScriptName();
     string item = llGetScriptName();
     if((PERM_COPY & llGetInventoryPermMask(item, MASK_NEXT)) != 0)
 
    {
     if((PERM_COPY & llGetInventoryPermMask(item, MASK_NEXT)))
         llOwnerSay("Set no copy");
         llOwnerSay("Set no copy");
    }
 
     if((PERM_MODIFY & llGetInventoryPermMask(item, MASK_NEXT)) != 0)
     if((PERM_MODIFY & llGetInventoryPermMask(item, MASK_NEXT)))
    {
         llOwnerSay("Set no mod");
         llOwnerSay("Set no mod");
    }
 
     if((PERM_TRANSFER & llGetInventoryPermMask(item, MASK_NEXT)) != 0)
     if((PERM_TRANSFER & llGetInventoryPermMask(item, MASK_NEXT)))
    {
         llOwnerSay("Set no transfer");
         llOwnerSay("Set no transfer");
    }
    return;
}
}
   
   
Line 75: Line 115:
         llResetScript();
         llResetScript();
     }
     }
     state_entry()
     state_entry()
     {
     {
         if(llGetOwner() != llGetInventoryCreator(llGetScriptName()))
         if(llGetOwner() != llGetInventoryCreator(llGetScriptName()))
        {
             CheckPerms();
             CheckPerms();
        }
     }
     }
}
</lsl>
</lsl>


Line 91: Line 131:
     touch_start(integer num)
     touch_start(integer num)
     {
     {
         integer i;
         integer index;
         while(i < llGetInventoryNumber(INVENTORY_OBJECT))
         do
         {
         {
             string myitem = llGetInventoryName(INVENTORY_OBJECT,i);
             string myitem = llGetInventoryName(INVENTORY_OBJECT, index);
            //Notice that PERM_COPY and PERM_TRANSFER are combined with a bitwise & in this test.
 
             if (((PERM_COPY & PERM_TRANSFER) & llGetInventoryPermMask(myitem, MASK_OWNER)) == 0)
        // notice that PERM_COPY and PERM_TRANSFER are combined with a bitwise & in this test.
             if (!((PERM_COPY & PERM_TRANSFER) & llGetInventoryPermMask(myitem, MASK_OWNER)))
             {
             {
                 if (((PERM_COPY) & llGetInventoryPermMask(myitem, MASK_OWNER)) == 0)
                 if (!((PERM_COPY) & llGetInventoryPermMask(myitem, MASK_OWNER)))
                {
                     llSay(PUBLIC_CHANNEL, myitem + " is no copy");
                     llSay(0, myitem + " is no copy");
 
                }
                 else if (!((PERM_TRANSFER) & llGetInventoryPermMask(myitem, MASK_OWNER)))
                 else if (((PERM_TRANSFER) & llGetInventoryPermMask(myitem, MASK_OWNER)) == 0)
                     llSay(PUBLIC_CHANNEL, myitem + " is no transfer");
                {
                     llSay(0, myitem + " is no transfer");
                }
             }
             }
            ++i;
         }
         }
        while (++i < llGetInventoryNumber(INVENTORY_OBJECT));
     }
     }
}
}

Revision as of 13:13, 25 November 2012

Summary

Function: integer llGetInventoryPermMask( string item, integer mask );

Returns an integer bitfield that is the requested permission mask for the inventory item

• string item an item in the inventory of the prim this script is in
• integer mask MASK_* flag

Category Description
MASK_BASE 0 The base permissions.
MASK_OWNER 1 Current owner permissions.
MASK_GROUP 2 Active group permissions.
MASK_EVERYONE 3 Permissions everyone has.
MASK_NEXT 4 Permissions the next owner will have.
Permissions Value Description
PERM_ALL 0x7FFFFFFF Move/Modify/Copy/Transfer permissions
PERM_COPY 0x00008000 Copy permission
PERM_MODIFY 0x00004000 Modify permission
PERM_MOVE 0x00080000 Move permission
PERM_TRANSFER 0x00002000 Transfer permission

Caveats

  • If item is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> if ((permsYouHave & permsYouWant) == permsYouWant)

   llSay(PUBLIC_CHANNEL, "You have the perms you want.");

else

   llSay(PUBLIC_CHANNEL, "You don't have the perms you want.");

</lsl> <lsl> integer ownerPerms = llGetInventoryPermMask("inventory item name goes here", MASK_OWNER);

integer copyAndModPerms = PERM_COPY

Notes

See Also

Functions

•  llGetObjectPermMask
•  llGetInventoryName Returns the inventory item's name
•  llGetInventoryType Tests to see if an inventory item exists and returns its type
•  llGetInventoryNumber Returns the number of items of a specific type in inventory
•  llGetInventoryKey Returns the inventory item's UUID (if full perm)
•  llGetInventoryCreator Returns the inventory item's creator

Articles

•  hex

Deep Notes

Search JIRA for related Issues

Tests

•  llGetInventoryPermMask Test

Signature

function integer llGetInventoryPermMask( string item, integer mask );