Table of Contents

About

Due to the powerful directorysearch command, Corrade is able to resolve all kinds of names to their UUIDs. This is valid for:

  • classifieds
  • events
  • groups
  • land
  • people
  • places

Each of these searches return a CSV list of fields or properties mapped to values as per the directorysearch API command which can be filtered using the optional data parameter.

People Example

Here is a full example of how to resolve the agent key for an avatar called Bobby Resident when an avatar touches the primitive:

///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0      //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//                            CONFIGURATION                              //
///////////////////////////////////////////////////////////////////////////
// The UUID / Key of the scripted agent.
string CORRADE = "82e9ec7b-123b-41d0-8d94-2b26c75872c3";
// The name of the group to invite to.
string GROUP = "MyGroup";
// 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 wasKeyValueEncode(list data) {
    list k = llList2ListStrided(data, 0, -1, 2);
    list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
    data = [];
    do {
        data += llList2String(k, 0) + "=" + llList2String(v, 0);
        k = llDeleteSubList(k, 0, 0);
        v = llDeleteSubList(v, 0, 0);
    } while(llGetListLength(k) != 0);
    return llDumpList2String(data, "&");
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueGet(string k, string data) {
    if(llStringLength(data) == 0) return "";
    if(llStringLength(k) == 0) return "";
    list a = llParseStringKeepNulls(data, ["&", "="], []);
    integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
    if(i != -1) return llList2String(a, 2*i+1);
    return "";
}
 
///////////////////////////////////////////////////////////////////////////
//    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;
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
// unescapes a string in conformance with RFC1738
string wasURLUnescape(string i) {
    return llUnescapeURL(
        llDumpList2String(
            llParseString2List(
                llDumpList2String(
                    llParseString2List(
                        i, 
                        ["+"], 
                        []
                    ), 
                    " "
                ), 
                ["%0D%0A"], 
                []
            ), 
            "\n"
        )
    );
}
 
// store the key of the toucher
key touche = NULL_KEY;
// store the URL for the callback
string URL = "";
 
// the default state just grabs 
default {
    state_entry() {
        llSetTimerEvent(1);
    }
    timer() {
        llRequestURL();
        // retry in 60s
        llSetTimerEvent(60);
    }
    http_request(key id, string method, string body) {
        // could not grab an URL so just bail and 
        // wait for the next pass of timer
        if(method != URL_REQUEST_GRANTED) return;
        // we got an URL so stop the timer
        llSetTimerEvent(0);
        // store the URL
        URL = body;
        // and switch to main
        state main;
    }
}
 
state main {
    touch_start(integer num) {
        // first get the key of the toucher to 
        // send the result of the query to
        touche = llDetectedKey(0);
 
        // now send the message to Corrade to 
        // resolve the agent name Bobby Resident
        llInstantMessage(CORRADE, 
            wasKeyValueEncode(
                [
                    "command", "directorysearch",
                    "group", GROUP,
                    "password", PASSWORD,
                    "type", "people",
                    "name", "Bobby Resident",
                    "timeout", 10000,
                    "callback", wasURLEscape(URL)
                ]
            )
        );
    }
    http_request(key id, string method, string body) {
        // always confirm to Corrade that the message
        // has been properly received by the callback
        llHTTPResponse(id, 200, "Ok");
        // grab the "data" key, then unescape it 
        // and serialise the result to a list
        list data = wasCSVToList(
            wasURLUnescape(
                wasKeyValueGet(
                    "data", 
                    body
                )
            )
        );
        // we are looking for the key after AgentID
        key agentID = llList2Key(
            data,
            llListFindList(
                data, 
                ["AgentID"]
            )
            +1
        );
        // in case the agent does not exist
        if(agentID == NULL_KEY) {
            llInstantMessage(touche, "agent does not exist");
            return;
        }
        llInstantMessage(touche, (string)agentID);
    }
    changed(integer change) {
        // if the region has just started, then the URL
        // has most likely been invalidated, so reset
        if(change & CHANGED_REGION_START) llResetScript();
    }
}

Index


secondlife/scripted_agents/corrade/tutorials/name2key.txt ยท Last modified: 2023/09/27 10:04 by office

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.