Reply
Rolig Loon
Posts: 24,932
Registered: ‎10-05-2009

Generic Whitelist

[ Edited ]

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

 

 

Not as dumb as I look
Honored Resident
Swimmie Chaffe
Posts: 30
0 Kudos

Re: Generic Whitelist

Reply to Rolig Loon - view message

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!

Honored Resident
Jam Mint
Posts: 9
0 Kudos

Re: Generic Whitelistnk

Reply to Rolig Loon - view message

Thanks, going to be using this in a few ways :smileyhappy:

Resident
Henning Lionheart
Posts: 1
0 Kudos

Re: Generic Whitelist

Reply to Rolig Loon - view message

Oh this is definately something I can use :smileyhappy:
Honored Resident
candella1
Posts: 13
0 Kudos

Re: Generic Whitelist

Reply to Rolig Loon - view message

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 ??????

 
 
 
Darkie Minotaur
Posts: 1,616
Topics: 8
Kudos: 154
Blog Posts: 0
Registered: ‎02-23-2010
0 Kudos

Re: Generic Whitelist

[ Edited ]

Reply to candella1 - view message

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

 

Honored Resident
candella1
Posts: 13
0 Kudos

Re: Generic Whitelist

Reply to Rolig Loon - view message

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

Honored Resident
LashElmond
Posts: 2
0 Kudos

Re: Generic Whitelist

Reply to Rolig Loon - view message

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" Script
integer gON = 1; // Change to -1 to reverse the direction of opening
float 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;
    }
}

 

Honored Resident
LashElmond
Posts: 2
0 Kudos

Re: Generic Whitelist

Reply to LashElmond - view message

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.

Rolig Loon
Posts: 24,932
Registered: ‎10-05-2009
0 Kudos

Re: Generic Whitelist

Reply to LashElmond - view message

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:

Not as dumb as I look