Table of Contents

Shortnote

This inviter for the corrade bot keeps track of visitors and does not invite them again if they have been invited once. That means that once an avatar accepts or declines to join the group, they will not be invited again until the script restarts or consumes more than 62KB of memory (Mono).

Algorithm

  1. [Thread 1] Once agents are detected, check whether an invite was already sent by searching for them in the visitor list.
    1. If an invite was already sent (if they are in the visitor list) do not invite them. Goto (1).
    2. If an invite was not previously sent to that agent then add them to the visitor list and send them an offer to accept or decline the invitation to the group.
  2. [Thread 2] Every 1 second check that the script has more than 2KB of free RAM available.
    1. If it has more than 2KB of free RAM available, do Goto (2).
    2. If the script has less than 2KB of free RAM available, pop the last element off the visitor stack and discard it. Goto (2).

Code

corrade_inviter_once_per_agent.lsl
////////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2013 - License: CC BY 2.0      //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//                            CONFIGURATION                              //
///////////////////////////////////////////////////////////////////////////
// The UUID / Key of the scripted agent.
string CORRADE = "aaa465f0-e18c-4aec-baa2-21b153092886";
// The name of the group to invite to.
string GROUP = "My Group";
// The password for that group in Corrade.ini.
string PASSWORD = "mypassword";
///////////////////////////////////////////////////////////////////////////
//                          END CONFIGURATION                            //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueGet(string var, string kvp) {
    list dVars = llParseString2List(kvp, ["&"], []);
    do {
        list data = llParseString2List(llList2String(dVars, 0), ["="], []);
        string k = llList2String(data, 0);
        if(k != var) jump continue;
        return llList2String(data, 1);
@continue;
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    return "";
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueEncode(list kvp) {
    if(llGetListLength(kvp) < 2) return "";
    string k = llList2String(kvp, 0);
    kvp = llDeleteSubList(kvp, 0, 0);
    string v = llList2String(kvp, 0);
    kvp = llDeleteSubList(kvp, 0, 0);
    if(llGetListLength(kvp) < 2) return k + "=" + v;
    return k + "=" + v + "&" + wasKeyValueEncode(kvp);
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
// escapes a string in conformance with RFC1738
string wasURLEscape(string i) {
    string o = "";
    do {
        string c = llGetSubString(i, 0, 0);
        i = llDeleteSubString(i, 0, 0);
        if(c == "") jump continue;
        if(c == " ") {
            o += "+";
            jump continue;
        }
        if(c == "\n") {
            o += "%0D" + llEscapeURL(c);
            jump continue;
        }
        o += llEscapeURL(c);
@continue;
    } while(i != "");
    return o;
}
 
list vList = [];
 
default {
    state_entry() {
        llSensorRepeat("", "", AGENT,64, TWO_PI, 1);
        llSetTimerEvent(1);
    }
    sensor(integer num) {
        --num;
        do {
            string d = llDetectedName(num);
            if(llListFindList(vList, (list)d) != -1) jump next;
            list name = llParseString2List(llDetectedName(num), [" "], []);
            llInstantMessage(CORRADE, wasKeyValueEncode(
                [
                    "command", "invite",
                    "group", wasURLEscape(GROUP),
                    "password", wasURLEscape(PASSWORD),
                    "firstname", llList2String(name, 0),
                    "lastname", llList2String(name, 1)
                ])
            );
            vList += d;
@next;
        } while(--num>=-1);
    }
    timer() {
        if(llGetFreeMemory() > 2048) return;
        if(llGetListLength(vList) == 0) return;
        vList = llDeleteSubList(vList, 0, 0);
    }
    changed(integer change) {
        if (change & (CHANGED_REGION | CHANGED_REGION_START))
            llResetScript();
    }
    on_rez(integer num) {
        llResetScript();
    }
}

Index


secondlife/scripted_agents/corrade/projects/in_world/group_inviters/once_per_agent.txt ยท Last modified: 2022/11/24 07:45 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.