Mail

From Second Life Wiki
Jump to: navigation, search
KBnote.png Note: Due to licensing issues, all contributions to this wiki have stopped and the articles that we posted are just being maintained. This is one of the projects that has gone further and for updates you are cordially invited to the project page on our wiki.

Created by Kira Komarov.

Motivation

This script is a free implementation of a mail system which can be used to deliver items to a list of subscribers compatible with the greeter system I wrote but also works perfectly independently of it. It allows you to maintain a subscription list, it implements an access list so that several people are allowed shared access to the device, it sends a greeting before delivering items and after the item has been delivered and also notifies the person who triggered the delivery system of the current progress of the system.

This is a very compact script which does not need too much setting up and can be placed in whatever prim you like (if need be, you could also drop it in a HUD). The controls are simple: the menu item "Mail!" starts sending all the items the prim contains to every subscriber on the list. Another menu item is "Subs" which will display a list of your current subscribers.

Setting Up

To set up the system, create two notecards:

First, create a notecard called Subscribers and fill it with avatar key names / avatar names line-by-line following the following format. For example, the following are the contents of the notecard "Subscribers" which contains two avatars keys and their names separated by a hash sign:

1ad33407-a792-476d-a5e3-06007c0802bf#Kira Komarov
82c73d6d-facf-4332-b17b-06d8cd66a116#Lance Lenoirre

Next, create a notecard called Access and enter the avatar names line-by-line which will have access to the mailing system. For example, in order to grant myself access to the system, my access list looks like this:

Kira Komarov
Lance Lenoirre

Thus letting both Kira Komarov and Lance Lenoirre manipulate the script. Afterwards, add the script below to the prim and then add whatever items you want to be delivered. Please note that you can send any item you want, it can be a sound, it can be a notecard, it can be an object, it can be whatever you like. The script itself does not send the notecards Subscribers and Access, as well as itself to the subscribers. The script should automatically pick up inventory changes. Thus, if you want an item removed from being sent to the subscribers, simply remove it from the prim's inventory. The mailbox system also asks you to confirm the objects being sent. You can chose to "Confirm" or "Abort". If you "Confirm", the script will start sending the items in its inventory to every subscriber sequentially and will also notify you via IM of its progress.

Applications

Here's a list of possible applications I could think of:

  • If you own a shop and wish to deliver gifts to customers, you can use this system to mass-send them.
  • Good for groups or roleplay SIMs.

Code

//////////////////////////////////////////////////////////
// [K] Kira Komarov - 2011, License: GPLv3              //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
list sList = [];
list nList = [];
list aList = [];
list pList = [];
key sQuery = NULL_KEY;
key aQuery = NULL_KEY;
integer sLine = 0;
integer aLine = 0;
integer comHandle = 0;
 
readSetup()
{
    aList = [];
    sList = [];
    nList = [];
 
    integer itra;
    integer cards;
 
    while (itra < llGetInventoryNumber(INVENTORY_NOTECARD))
    {
        string notecardName = llGetInventoryName(INVENTORY_NOTECARD, itra);
        if(notecardName == "Subscribers" || notecardName == "Access")
           ++cards;
        if(cards == 2)
            jump found_cards;
 
        ++itra;
    }
    return;
@found_cards;
    sLine = 0;
    aLine = 0;
    sQuery = llGetNotecardLine("Subscribers", sLine);
    aQuery = llGetNotecardLine("Access", aLine);
}
 
readPost()
{
    pList = [];
    integer itra;
    while (itra < llGetInventoryNumber(INVENTORY_ALL))
    {
        string itemName = llGetInventoryName(INVENTORY_ALL, itra);
 
        if(itemName == "Subscribers")
        {
            jump continue;
        }
        else if(itemName == "Access")
        {
            jump continue;
        }
        else if(itemName == llGetScriptName())
        {
            jump continue;
        }
        pList += itemName;
 
        ++itra;
@continue;
    }
}
 
sendPost(key id)
{
    integer itra;
    while (itra < llGetListLength(sList))
    {
        llInstantMessage(llList2Key(sList, itra), "Hello " + llList2String(nList, itra) + "! We have a delivery for you, a package containing " + llDumpList2String(pList, ", ") + ". Please accept the items as they are being delivered...");
 
        integer itrb;
        while (itrb < llGetListLength(pList))
        {
            llGiveInventory(llList2Key(sList, itra), llList2String(pList, itrb));
            llInstantMessage(id, "Sending: " + llList2String(pList, itrb) + " to " + llList2String(nList, itra));
 
            ++itrb;
        }
        llInstantMessage(llList2Key(sList, itra), "Have a nice day " + llList2String(nList, itra) + "! Thank you for subscribing with us.");
 
        ++itra;
    }
}
 
default
{
    changed(integer change)
    {
        if(change & CHANGED_INVENTORY)
        {
            readSetup();
            readPost();
        }
    }
 
    state_entry()
    {
        readSetup();
        readPost();
    }
 
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        string name = llDetectedName(0);
 
        if(!~llListFindList(aList, [name]))
            return;
 
        integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        comHandle = llListen(comChannel, "", id, "");
        llDialog(id, "Welcome to the mailer, please select an action: ", [ "Mail!", "Subs" ], comChannel);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(!~llListFindList(aList, [name]))
            return;
 
        if(message == "Mail!")
        {
            string post;
 
            integer itra;
            while (itra < llGetListLength(pList))
            {
                post += (string)itra + ".) " + llList2String(pList, itra) + "\n";
                ++itra;
            }
            llDialog(id, "Please confirm sending the following items to all the listed subscribers:\n" + post, [ "Confirm", "Abort" ], channel);
        }
        else if(message == "Subs")
        {
            string subs;
 
            integer itra;
            while (itra < llGetListLength(nList))
            {
                subs += llList2String(nList, itra);
 
                if(itra+1<llGetListLength(nList))
                    subs += ", ";
                else
                    subs += ".";
 
                ++itra;
            }
            llInstantMessage(id, "Your subscribers are: " + subs);
        }
        else if(message == "Confirm")
        {
            sendPost(id);
        }
 
        llListenRemove(comHandle);
    }
 
    dataserver(key query_id, string data)
    {
        if(query_id == aQuery)
        {
            if(data == EOF)
                return;
 
            if(data == "")
                jump next_access;
 
            aList += (list) data;
@next_access;
            ++aLine;
            aQuery = llGetNotecardLine("Access", aLine);
        }
        else if(query_id == sQuery)
        {
            if(data == EOF)
                return;
 
            if(data == "")
                jump next_subscriber;
 
            sList += llList2List(llParseString2List(data, ["#"], [""]), 0, 0);
            nList += llList2List(llParseString2List(data, ["#"], [""]), 1, 1);
@next_subscriber;
            ++sLine;
            sQuery = llGetNotecardLine("Subscribers", sLine);
        }
    }
}