Sign in to follow this  
Followers 0
Rolig Loon

Generic Whitelist

16 posts in this topic

We seem to get a lot of requests for a script that will give access to some residents but not others.  Here is a generic script that lets the owner give access to (1) Owner only, (2) Group and owner, (3) whitelisted avatars, (4) group and whitelisted avatars, or (5) everyone.  All you need to do is drop the script and a notecard with whitelisted names into an object.  (Be sure to add your own event in state OK to define the action that people with access are allowed to do -- open a door, receive an object, play a sound .... whatever.)

 

// Generic Whitelist Script -- Rolig Loon -- March 2011

// Put login names (NOT Display names) of avatars to be whitelisted in a notecard, one per line
// Spelling and capitalization count

list gWhiteList = [];
string gCard;
integer gLine;
key gQuery;
list gWho = ["Me Only","Group","List","Group+List","Everyone"];
integer gAccess;
integer gDChnl;

default  // Read Whitelist from notecard, one name per line
{
    state_entry()
    {
        if(llGetInventoryNumber(INVENTORY_NOTECARD) == 1)
        {
            gCard = llGetInventoryName(INVENTORY_NOTECARD,0);
            gQuery = llGetNotecardLine(gCard, 0);
        }
        else
        {
            llOwnerSay("The whitelist notecard is missing.");
        }
    }

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
    
     dataserver(key QID, string data)
    {
        if(gQuery == QID)
        {
            if (data != EOF)
            {
                gWhiteList += [llStringTrim(data,STRING_TRIM)];
                gQuery = llGetNotecardLine(gCard, ++gLine);
            }
            else
            {
                llOwnerSay("Initialized");
                state running;
            }
        }
    }
}

state running
{
    state_entry()
    {
        gDChnl = (integer) ("0xF" + llGetSubString(llGetOwner(),0,6));
    }

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
    
    touch_start(integer total_number)
    {
        llResetTime();
        integer idx = llListFindList(gWhiteList,[llDetectedName(0)]);
        if (llDetectedKey(0) != llGetOwner())
        {
            if ((gAccess == 4) ||
                ((gAccess == 3) && (~idx || llSameGroup(llDetectedKey(0)))) ||
                ((gAccess == 2) && (~idx)) ||
                ((gAccess == 1) && (llSameGroup(llDetectedKey(0)))))
            {
                llSay(0,"Access granted.");
                state OK;
            }
            else
            {
                llSay(0,"Access denied.");
            }
        }
    }
    
    touch_end(integer num) //Mouse button released
    {
        if(llDetectedKey(0) == llGetOwner())
        {
            if (llGetTime() < 3.0 ) //Less than 3 seconds after mouse button down
            {
                llSay(0,"Access granted.");
                state OK;
            }
            else if (llGetTime() >= 3.0 ) // Owner set access permissions
            {
                llListen(gDChnl,"","","");
                llDialog(llGetOwner(),"Who should have access?",gWho,gDChnl);
            }
        }
    }

    listen(integer channel, string name, key id, string msg)
    {
        gAccess = llListFindList(gWho,[msg]);
        string temp;
        if (gAccess == 0)
        {
            temp = "you only.";
        }
        else if (gAccess == 1)
        {
            temp = "group members only.";
        }
        else if (gAccess == 2)
        {
            temp = " \n" + llDumpList2String(gWhiteList," \n");
        }
        else if (gAccess == 3)
        {
            temp = "this group and " + " \n" +llDumpList2String(gWhiteList, " \n");
        }
        else
        {
            temp = "everyone.";
        }
        llOwnerSay("Access has been granted to " + temp);
    }
}

state OK
{
    state_entry()
    {
        llSetTimerEvent(10.0);
        llSay(0,"You're in!"); 
    }

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
    
    // Insert whatever events you want available for people with access
    // Be sure that there is a path back to state running 
    
    timer()  // Return to previous state if nothing else happens before timer triggers
    {
        llSetTimerEvent(0.0);
        state running;
    }
}

 

 

1 person likes this

Share this post


Link to post
Share on other sites

Greeting Rolig, just wanted to thank you for sharing this wonderful scirpt. I had been struggling with a whitelist for quite a while, and finally could write a script I wanted by working from your codes. Your generous guidance is much appreciated!

Share this post


Link to post
Share on other sites

thanks very much for this script!it is really very usefull!!!but i have something to ask....you have in the object's contents a notecard with avatars names who are allowed to add things in your prim.but when someone puts a second notepad in prim's contents the script doesn't work.can i do something about this??for example there is a way in this script that i can make it to read whitelisted avatars only from a certain notepad ??????

 
 
 

Share this post


Link to post
Share on other sites

Change the default state_entry to

        if( llGetInventoryType(gCard) == 7)        {            gQuery = llGetNotecardLine(gCard, 0);        }        else        {            llOwnerSay("The whitelist notecard is missing.");        }

 You must supply the card name in this case - e.g. where it is declared

string gCard ="MyWhitelist";

 

Share this post


Link to post
Share on other sites

thank you very much for replying to me so early!!!now my script works perfectly!!! :-)

Share this post


Link to post
Share on other sites

Hello,

I tried to implement the "Linkable Mulitprim Sliding Door"" script into this one here. Thanks in both cases for the code as I am hard working on getting better in scripting, which rather means that I am spending lots of time with trial and error than really knowing what I am doing. But it could be worse *smirks*

Anyways, I could make it work fo me (and only me) that I click the linked multiprim door, then it says the message about Access granted. So as there is also a timer, I have a certain time span during that it is possible to open the door by clicking it again (or close) before the access will be checked again.

The problem is, that the login names which I put in the notecard, and this in the same prim´s inventory as the script, do not have access as it is meant to be. I checked the spelling and capitalization twice.

I am not sure if I should post the script in here (it´s kind of big), but without doing that there will be no way I guess.

So I would be thankful for suggestion what I am doing wrong.

// Generic Whitelist Script -- Rolig Loon -- March 2011// Put login names (NOT Display names) of avatars to be whitelisted in a notecard, one per line// Spelling and capitalization count//MEINE NOTIZEN: der erste Klick checkt die Permissions von der Notecard. Dann gibt es einen Zeitraum, während dem man durch Klicken die Tür öffnet und schließt. Die Dauer des Zeitraums kann im state OK Teil geändert werden.list gWhiteList = [];string gCard;integer gLine;key gQuery;list gWho = ["Me Only","Group","List","Group+List","Everyone"];integer gAccess;integer gDChnl;//--- Part of the "Sliding Door in Linkset" Scriptinteger gON = 1; // Change to -1 to reverse the direction of openingfloat gDistance = 0.5; // Adjust to set the distance the door should move long its local Y axis//---default  // Read Whitelist from notecard, one name per line{    state_entry()    {        if(llGetInventoryNumber(INVENTORY_NOTECARD) == 1)        {            gCard = llGetInventoryName(INVENTORY_NOTECARD,0);            gQuery = llGetNotecardLine(gCard, 0);        }        else        {            llOwnerSay("The whitelist notecard is missing.");        }    }    changed(integer change)    {        if (change & CHANGED_INVENTORY)        {            llResetScript();        }    }         dataserver(key QID, string data)    {        if(gQuery == QID)        {            if (data != EOF)            {                gWhiteList += [llStringTrim(data,STRING_TRIM)];                gQuery = llGetNotecardLine(gCard, ++gLine);            }            else            {                llOwnerSay("Initialized");                state running;            }        }    }}state running{    state_entry()    {        gDChnl = (integer) ("0xF" + llGetSubString(llGetOwner(),0,6));    }    changed(integer change)    {        if (change & CHANGED_INVENTORY)        {            llResetScript();        }    }        touch_start(integer total_number)    {        llResetTime();        integer idx = llListFindList(gWhiteList,[llDetectedName(0)]);        if (llDetectedKey(0) != llGetOwner())        {            if ((gAccess == 4) ||                ((gAccess == 3) && (~idx || llSameGroup(llDetectedKey(0)))) ||                ((gAccess == 2) && (~idx)) ||                ((gAccess == 1) && (llSameGroup(llDetectedKey(0)))))            {                llSay(0,"Access granted.");                state OK;            }            else            {                llSay(0,"Access denied.");            }        }    }        touch_end(integer num) //Mouse button released    {        if(llDetectedKey(0) == llGetOwner())        {            if (llGetTime() < 3.0 ) //Less than 3 seconds after mouse button down            {                llSay(0,"Access granted.");                state OK;            }            else if (llGetTime() >= 3.0 ) // Owner set access permissions            {                llListen(gDChnl,"","","");                llDialog(llGetOwner(),"Who should have access?",gWho,gDChnl);            }        }    }    listen(integer channel, string name, key id, string msg)    {        gAccess = llListFindList(gWho,[msg]);        string temp;        if (gAccess == 0)        {            temp = "you only.";        }        else if (gAccess == 1)        {            temp = "group members only.";        }        else if (gAccess == 2)        {            temp = " \n" + llDumpList2String(gWhiteList," \n");        }        else if (gAccess == 3)        {            temp = "this group and " + " \n" +llDumpList2String(gWhiteList, " \n");        }        else        {            temp = "everyone.";        }        llOwnerSay("Access has been granted to " + temp);    }}state OK{    state_entry()    {        llSetTimerEvent(60.0);        llWhisper(0,"You have 60 seconds to open and close the door before your access permissions will be checked again.");     }    changed(integer change)    {        if (change & CHANGED_INVENTORY)        {            llResetScript();        }    }        // Insert whatever events you want available for people with access    // Be sure that there is a path back to state running     touch_start(integer total_number)    {    if (llGetLinkName(llDetectedLinkNumber(0)) == "DOOR")        {            integer i;            for (i=2;i<=llGetNumberOfPrims();++i)            {                if (llGetLinkName(i) == "DOOR")                {                    list temp = llGetLinkPrimitiveParams(i,[PRIM_POSITION,PRIM_ROT_LOCAL]);                    rotation local_rot = (rotation)llList2String(temp,1);                    vector local_pos = ((vector)llList2String(temp,0)- llGetPos())/llGetRot();                    llSetLinkPrimitiveParamsFast(i,[PRIM_POSITION,local_pos + (<0.0,gDistance *gON,0.0>*local_rot),PRIM_ROTATION,local_rot/llGetRot()]);                }            }            gON = (-1)*gON;        }    }    //End of Sliding Action        timer()  // Return to previous state if nothing else happens before timer triggers    {        llSetTimerEvent(0.0);        state running;    }}

 

Share this post


Link to post
Share on other sites

Ok, it works now. I took care about the capitalization as Rolig mentioned. But it had to be different than I thought.

I typed the login names exactly as shown in my friends list and there have been some with lower case and/or a dot between the two names. Spelling them with capitals and without that dot finally works.

Share this post


Link to post
Share on other sites

Sorry that I didn't see your post until after I got back from the holidays, but I'm glad that you figured out your problem.  The many variants of SL names make life interesting for scripters.  If you want to be diligent about capturing all of them, you have to write a discouraging mess of extra code.  Innula has done just that, so if you dig through scripts she has posted in the forums, you can save yourself a lot of trouble.

Incidentally, the LSL Scripting Library is really not the place for this sort of debugging/experimenting conversation.  Next time you have something cool like this to discuss, it ought to be in the LSL Scripting forum, where other scripters are more likely to see it.  :smileywink:

Share this post


Link to post
Share on other sites

Just as it says in the script.... if you're the owner, touch and hold your mouse button down for 3 seconds to activate the permission menu.  You could shorten that time if you like, or you could redesign that part of the script to simply offer the owner a different dialog menu than anyone else.  Whatever magic appeals to you.  This script was in part a demonstration of the way to use time delay to separate user functions from owner functions.

 

Share this post


Link to post
Share on other sites

Hi Rolig,

As always, I appreciate all the help you've given me with scripting, including with this whitelist script. I've used it before with a hot tub cover, and it worked beautifully. I am looking to apply the whitelist function to control access to a boat. Might I ask how one could incorporate the functions to work with the pilot sitting and taking controls?

Here's how the code currently is written, which currently only works with the owner. I'm pretty what I have below constitutes the relevant functions of the script that handle pilot seating.

 

integer sit; // declares 'sit' as being either 'TRUE' or 'FALSE,' depending on if the pilot is sitting or notkey pilot;   // this declares 'pilot' as placeholder for the pilot's UUID key // DETECT AV SITTING/UNSITTING AND GIVE PERMISSIONS    changed(integer change)    {       key agent = llAvatarOnSitTarget();       if(change & CHANGED_LINK)       {           if (agent == NULL_KEY && sit)           {               //               //  Pilot gets out of vehicle                //                llSetStatus(STATUS_PHYSICS, FALSE);               llSetTimerEvent(0.0);               sit = FALSE;               llMessageLinked(LINK_SET, 0, "throttle", "");               llMessageLinked(LINK_SET, 0, "unseated", "");               llStopSound();               llReleaseControls();               set_motor();           }           else if (agent == llGetOwner() && !sit)           {               //                 // Pilot gets into vehicle               //               sit = TRUE;               pilot = agent;               llSetStatus(STATUS_PHYSICS,TRUE);               llRequestPermissions(pilot, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);               llSetTimerEvent(TIMER_DELAY);               llMessageLinked(LINK_SET, 0, "seated", "");            }        }    }

 Mig

 

 

Share this post


Link to post
Share on other sites

Try using the whitelist test to set a flag that is either 0 (not authorized) or 1 (authorized).  Then wrap a test for that flag around everything in your changed event after if(changed & CHANGED_LINK).  So basically,

if (toucher_is_authorized){    if ((agent == NULL_KEY) && sit)   {       // and so forth all the way to the end   }}

 Or, you just put the changed event in state OK, where it's not accessible until after the whitelist test changes state to there.

 

 

Share this post


Link to post
Share on other sites

sry to reopen a old thread but i have been trying to figure out for some time now how to get a script to use a access list to set a parcel stream ie: avtarname = landmedia url, now eaither i have not dug far enough or no one has felt it nessary to post a example so i am hoping someone here may be abel to help, I can get the generic whitelist to compile but as for the script (or any script for that matter) seeing a second value like land media ur im at a loss.

Share this post


Link to post
Share on other sites

If you're using this script, all you need to pay attention to is the note in state OK that says:

    // Insert whatever events you want available for people with access    // Be sure that there is a path back to state running 

So if you need to llSetParcelMedia, figure out whether you want to just do it in the touch_start event or in a new event.  As long as your visitor has made it as far as state OK, you can let him do whatever you want.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0