Email 1 2 x

From SLSA
Jump to navigation Jump to search

This is one of 5 email scripts, it sends an email to one of the 5 officials after voting closes. There are five of these, because the LSL function llEmail() is a throttled function and the system normally has to wait one minute after each email is sent. With 5 email scripts each election official will receive their email at the same time.

// copyright Sally laSalle 2010.
// this allows for up to 160 eligible voters that actually voted. maximum we have ever received is 55.
// version 2.0 , June 2011
// added reset response

list codelist;
string codes;
string codes1;
string codes2;
integer CODE_RECEIVED=0;
integer SEND=1;
integer RESET=-1;
string email_message;
string email_header;


default
{
    state_entry()
    {
        // set the Send response code for this email script to the number on the end  of the script name, e.g. email3 then SEND=3.
        SEND = (integer)llGetSubString(llGetScriptName(),-1,-1);
        llSay(PUBLIC_CHANNEL,"email "+(string)SEND + " ready");
    }

    link_message(integer sender, integer num, string message, key id){
        if (num == CODE_RECEIVED){
            // an encrypted voter voting receipt code (without the vote) has been reeived. add it to a list.
            codelist = [message] + codelist;
        } else if (num == RESET){
            llResetScript();
        } else if (num == SEND){
            // first sort the code list alphabetically (so no vote sequence correlation is possible)
            codelist = llListSort(codelist,1,TRUE);
            // create a string with line breaks between codes for easier reading.
            codes = llDumpList2String(codelist, "\n");
            // "message" will hold the officials pass phrase, "id" will hold email address
            email_message = "Voter Code Lists From Voting Machine\n" + (string) llGetKey();
            email_message += "\nLocation " + llGetRegionName() + " Position " + (string) llGetPos();
            //attach this officials passphrase so they know email is from the machine they dropped their card into.
            email_message += "\nYour Pass Phrase: " + message + "\n";
            if (llStringLength(codes)>3280){
                // emails can be a maximum of 4096 bytes including header and email address
                // so if necessary create multiple parts.
                codes1 = llGetSubString(codes,0, 3280);  //3485 = 80 * 41,  41 = the lendth of one code + \n
                email_header = email_message;
                email_message = email_header + codes1;
                llEmail((string)id, "voting results part 1", email_message);

                codes2 = llGetSubString(codes,3281,-1);
                email_message = email_header + codes2;
                llEmail((string)id, "voting results part 2", email_message);
            }else{
                    // short list (less than 80 voters) so only one email necessary
                    email_message +=codes;
                llEmail((string)id, "voting results", email_message);
            }
        }
    }
}