Difference between revisions of "LlGetInventoryPermMask"

From Second Life Wiki
Jump to navigation Jump to search
(add first example - promptly complain any time the SL GUI restricts copying differently than you wish)
 
(32 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{LSL_Function/inventory|item|uuid=false}}{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/inventory|item|uuid=false}}
|func_id=289|func_sleep=0.0|func_energy=10.0
|func_id=289|func_sleep=0.0|func_energy=10.0
|func=llGetInventoryPermMask|return_type=integer
|func=llGetInventoryPermMask|return_type=integer|return_subtype=bit field
|p1_type=string|p1_name=item
|p1_type=string|p1_name=item
|p2_type=integer|p2_name=mask|p2_desc=MASK_* flag
|p2_type=integer|p2_name=category|p2_desc=MASK_* flag
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=bitfield that is the requested permission '''mask''' for the inventory '''item'''
|return_text=of the requested permission {{LSLP|category}} for the inventory {{LSLP|item}}
|spec
|spec
|caveats
|caveats
|constants={{LSL Constants Perm Mask}}
|constants={{LSL Constants Perm Mask}}
|examples=
|examples=
Promptly complain any time the SL GUI restricts copying differently than you wish.
<source lang="lsl2">
<pre>
if ((permsYouHave & permsYouWant) == permsYouWant)
// Remember the last perms described.
    llSay(PUBLIC_CHANNEL, "You have the perms you want.");
else
    llSay(PUBLIC_CHANNEL, "You don't have the perms you want.");
</source>
<source lang="lsl2">
integer ownerPerms = llGetInventoryPermMask("inventory item name goes here", MASK_OWNER);
integer copyAndModPerms = PERM_COPY | PERM_MODIFY;


integer everyonePerms;
if ((ownerPerms & copyAndModPerms) == copyAndModPerms)
integer nextPerms;
    llSay(PUBLIC_CHANNEL, "Owner has copy & modify perms.");
integer troubles;
else
    llSay(PUBLIC_CHANNEL, "Owner does not have copy & modify perms.");
</source>
<source lang="lsl2">
string getPermsAsReadableString(integer perm)
{
    integer fullPerms = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
    integer copyModPerms = PERM_COPY | PERM_MODIFY;
    integer copyTransPerms = PERM_COPY | PERM_TRANSFER;
    integer modTransPerms = PERM_MODIFY | PERM_TRANSFER;
    string output = " perms: ";
 
    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";
    else
        output += "none";
 
    //  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;
}


fetchPerms()
default
{
{
     everyonePerms = llGetInventoryPermMask(llGetScriptName(), MASK_EVERYONE);
     state_entry()
     nextPerms = llGetInventoryPermMask(llGetScriptName(), MASK_NEXT);
     {
}
        string inventoryItemName = "inventory item name goes here";


// Describe the copyable thing for which some clients respect the perms.
        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);


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


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


permsShouldBe()
<source lang="lsl2">
{
CheckPerms()
        integer wasTroubles = troubles;
{      
        troubles = 0;
    string item = llGetScriptName();
       
    integer nextOwnerPerms = llGetInventoryPermMask(item, MASK_NEXT);
        if (!(everyonePerms & PERM_COPY))
 
        {
    if(PERM_COPY & nextOwnerPerms)
            llOwnerSay("No = Allow anyone to copy " + me());
         llOwnerSay("Set no copy");
            troubles += 1;
        }
       
        if (!(nextPerms & PERM_MODIFY))
        {
            llOwnerSay("No = Next owner can modify " + me());
            troubles += 1;
        }
        if (!(nextPerms & PERM_COPY))
        {
            llOwnerSay("No = Next owner can copy " + me());
            troubles += 1;
        }
        if (!(nextPerms & PERM_TRANSFER))
         {
            llOwnerSay("No = Next owner can resell/ give away " + me());
            troubles += 1;
        }
       
        if (wasTroubles && !troubles)
        {
            llOwnerSay("Open / Yes Mod/ Yes Copy/ Yes Transfer");
        }
       
        if (wasTroubles || troubles)
        {
            llOwnerSay("");
        }
}


// Describe the perms when rezzed or reset, and when the perms change.
    if(PERM_MODIFY & nextOwnerPerms)
        llOwnerSay("Set no mod");


    if(PERM_TRANSFER & nextOwnerPerms)
        llOwnerSay("Set no transfer");
}
default
default
{
{
     on_rez(integer start_param)
     on_rez(integer start_param)
     {
     {
         llResetScript();  
         llResetScript();
     }
     }
     state_entry()
     state_entry()
     {
     {
         fetchPerms();
         if(llGetOwner() != llGetInventoryCreator(llGetScriptName()))
        permsShouldBe();
             CheckPerms();
        llSetTimerEvent(1.0); // 1.0 = once per second
    }
    timer()
    {
        integer wasEveryonePerms = everyonePerms;       
        integer wasNextPerms = nextPerms;       
        fetchPerms();
        if (everyonePerms != wasEveryonePerms)
        {
            permsShouldBe();
        }
        else if (nextPerms != wasNextPerms)
        {
             permsShouldBe();
        }
     }
     }
}
}
</pre>
</source>
 
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llGetObjectPermMask]]|}}
|also_functions=
{{LSL DefineRow||[[llGetInventoryCreator]]|}}
{{LSL DefineRow||[[llGetObjectPermMask]]|}}
{{LSL DefineRow||[[llGetInventoryKey]]|}}
{{LSL DefineRow||[[llGetInventoryAcquireTime]]|Returns the time the item was added to the prim's inventory}}
{{LSL DefineRow||[[llGetInventoryType]]|}}
{{LSL DefineRow||[[llGetInventoryName]]|Returns the inventory item's name}}
{{LSL DefineRow||[[llGetInventoryType]]|Tests to see if an inventory item exists and returns its type}}
{{LSL DefineRow||[[llGetInventoryNumber]]|Returns the number of items of a specific type in inventory}}
{{LSL DefineRow||[[llGetInventoryKey]]|Returns the inventory item's [[UUID]] (if full perm)}}
{{LSL DefineRow||[[llGetInventoryCreator]]|Returns the inventory item's creator}}
|also_events
|also_events
|also_tests
|also_tests=
|also_articles
{{LSL DefineRow||[[llGetInventoryPermMask Test]]}}
|notes
|also_articles=
|permission
{{LSL DefineRow||[[hex]]}}
|negative_index
|notes=
* In effect, the perms for articles published on this Wiki are [[PERM_COPY]] and [[PERM_TRANSFER]] until you log in, then [[PERM_MODIFY]], [[PERM_MOVE]], [[PERM_COPY]] and [[PERM_TRANSFER]].
* The default perms of a newly created script are: Base = [[PERM_ALL]], Owner = [[PERM_ALL]], Next = [[PERM_MOVE]] or [[PERM_TRANSFER]], Group = 0 (none), Everyone = 0 (none). These perms are the same, no matter if the script is created in user inventory or in an object.
** However, an option in the ''[[Preferences window|Preferences]] > Advanced'' menu allows to set the '''Default Creation Permissions''' of all items that can be created or uploaded in-world.
|cat1=Inventory
|cat1=Inventory
|cat2=Permissions/Asset
|cat2=Permissions/Asset

Latest revision as of 09:17, 28 May 2021

Summary

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

Returns a bit field (an integer) of the requested permission category for the inventory item

• string item an item in the inventory of the prim this script is in
• integer category 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

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.");
integer ownerPerms = llGetInventoryPermMask("inventory item name goes here", MASK_OWNER);
integer copyAndModPerms = PERM_COPY | PERM_MODIFY;

if ((ownerPerms & copyAndModPerms) == copyAndModPerms)
    llSay(PUBLIC_CHANNEL, "Owner has copy & modify perms.");
else
    llSay(PUBLIC_CHANNEL, "Owner does not have copy & modify perms.");
string getPermsAsReadableString(integer perm)
{
    integer fullPerms = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
    integer copyModPerms = PERM_COPY | PERM_MODIFY;
    integer copyTransPerms = PERM_COPY | PERM_TRANSFER;
    integer modTransPerms = PERM_MODIFY | PERM_TRANSFER;
 
    string output = " perms: ";

    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";
    else
        output += "none";

    //  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
{
    state_entry()
    {
        string inventoryItemName = "inventory item name goes here";

        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);

        llSay(0, "/me [" + inventoryItemName
            + "]: base" + getPermsAsReadableString(basePerms));
        llSay(0, "/me [" + inventoryItemName
            + "]: owner" + getPermsAsReadableString(ownerPerms));
        llSay(0, "/me [" + inventoryItemName
            + "]: next owner" + getPermsAsReadableString(nextOwnerPerms));
        llSay(0, "/me [" + inventoryItemName
            + "]: group" + getPermsAsReadableString(groupPerms));
        llSay(0, "/me [" + inventoryItemName
            + "]: everyone" + getPermsAsReadableString(everyonePerms));
    }
}

To test for the opposite (e.g. to see if something is NOT copy):

    if (!(PERM_COPY & llGetInventoryPermMask(myitem, MASK_OWNER)))
        llSay(PUBLIC_CHANNEL, "/me [" + myitem + "]: owner doesn't have copy perms.");

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

CheckPerms()
{        
    string item = llGetScriptName();
    integer nextOwnerPerms = llGetInventoryPermMask(item, MASK_NEXT);

    if(PERM_COPY & nextOwnerPerms)
        llOwnerSay("Set no copy");

    if(PERM_MODIFY & nextOwnerPerms)
        llOwnerSay("Set no mod");

    if(PERM_TRANSFER & nextOwnerPerms)
        llOwnerSay("Set no transfer");
}
 
default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }

    state_entry()
    {
        if(llGetOwner() != llGetInventoryCreator(llGetScriptName()))
            CheckPerms();
    }
}

Notes

  • In effect, the perms for articles published on this Wiki are PERM_COPY and PERM_TRANSFER until you log in, then PERM_MODIFY, PERM_MOVE, PERM_COPY and PERM_TRANSFER.
  • The default perms of a newly created script are: Base = PERM_ALL, Owner = PERM_ALL, Next = PERM_MOVE or PERM_TRANSFER, Group = 0 (none), Everyone = 0 (none). These perms are the same, no matter if the script is created in user inventory or in an object.
    • However, an option in the Preferences > Advanced menu allows to set the Default Creation Permissions of all items that can be created or uploaded in-world.

See Also

Functions

•  llGetObjectPermMask
•  llGetInventoryAcquireTime Returns the time the item was added to the prim's inventory
•  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 category );