Difference between revisions of "Find Avatar Key"

From Second Life Wiki
Jump to navigation Jump to search
m (Unnecessary key type casting removed)
(Code changed to comply with modification of resulting SL HHTP code)
Line 12: Line 12:
* No special instructions. It operates stand alone once installed.
* No special instructions. It operates stand alone once installed.


<lsl>
<lsl>// Find Avatar Key Script
// Find Avatar Key Script
// by Huney Jewell
// by Huney Jewell
// uses Name2Key code published in LSL Library
// based on Name2Key code published in LSL Library
//
//
// Put in single prim
// Put in single prim
Line 28: Line 27:
// System settings - Do Not Change Anything Below!
// System settings - Do Not Change Anything Below!


string proxy                  = "http://66.196.80.202/babelfish/translate_url_content?&intl=us&lp=fr_en&trurl=";
string search    = "http://lawlinter.net/secondlifeutility/name2key.php5?name="; // Name2Key URL
string search                 = "http://search.secondlife.com/client_search.php?session=00000000-0000-0000-0000-000000000000&q=";
//string search   = "http://w-hat.com/name2key?terse=1&name="; // Alternate Name2Key URL
string result                  = "secondlife:///app/agent/";
string notFound  = "00000000-0000-0000-0000-000000000000";
string profile                = "Resident profiles";
string notfound                = "There were no matches for ";


list  requests               = [];
list  requests = [];


// CODE ENTRY
// CODE ENTRY
Line 41: Line 38:
default
default
{
{
     on_rez(integer i) { llResetScript(); }
     on_rez(integer i)
    {
        llResetScript();
    }


     state_entry()
     state_entry()
Line 60: Line 60:
     listen(integer c, string n, key i, string msg)
     listen(integer c, string n, key i, string msg)
     {
     {
         llSay(0,"Requesting key for " + msg);
         list Args=llParseString2List(msg, [" "], []);
        if(llListFindList(requests,[msg]) == -1) {
        string FirstName = llList2String(Args, 0);
            list Args=llParseString2List(msg, [" "], []);
        string LastName = llList2String(Args, 1);
 
        string name = FirstName + " " + LastName;
            string FirstName = llList2String(Args, 0);
        llSay(0,"Requesting key for " + name);
            string LastName = llList2String(Args, 1);
        if(llListFindList(requests,[name]) == -1)
 
        {
             string url = proxy + llEscapeURL(search) + FirstName + "%2520" + LastName;;
             string url = search + FirstName + "%20" + LastName;
             key id = llHTTPRequest(url, [], "");
             key id = llHTTPRequest(url, [], "");
             requests += [id,msg];
             requests += [(string)id,name];
         }
         }
     }
     }
Line 75: Line 75:
     http_response(key request_id, integer status, list metadata, string body)
     http_response(key request_id, integer status, list metadata, string body)
     {
     {
         integer p = llListFindList(requests,[request_id]);
        //        llOwnerSay("Status:" + (string) status + "; Body: " + body); // DEBUG
         if (p != -1) {
         integer p = llListFindList(requests,[(string)request_id]);
         if (p != -1)
        {
             string name = llList2String(requests,p+1);
             string name = llList2String(requests,p+1);
            integer find = llSubStringIndex(body,result);
             if (status == 200)
             if(find == -1) {
            {
                 find = llSubStringIndex(body,notfound);
                 if (body != notFound)
                if(find == -1)
                     llSay(0,name + " = " + body);
                     llSay(0,"Error with lookup!");
                 else
                 else
                     llSay(0," Lookup '" + name + "' failed: Not found.");
                     llSay(0,"Lookup '" + name + "' failed: Not found.");
             }
             }
             else
             else
             {
             {
                find += llStringLength(result);
                 if (status == 499)
                string avKey = llGetSubString(body,find,find+35);
                     llSay(0,"Lookup '" + name + "' timed out, try again.");
                integer namePos = llSubStringIndex(body,profile)+18;
                string foundName = llGetSubString(body, namePos+1, namePos + llSubStringIndex(llGetSubString(body,namePos+1, llStringLength(body)-1),"<"));
                 if(llToLower(name) == llToLower(foundName))
                     llSay(0,foundName + " = " + avKey);
                 else
                 else
                     llSay(0," Lookup '" + name + "' failed: Wrong found.");
                     llSay(0,"Lookup '" + name + "' failed: HHTP error code " + (string)status);
             }
             }
             requests = llDeleteSubList(requests,p,p+1);
             requests = llDeleteSubList(requests,p,p+1);
         }
         }
     }
     }
}
}</lsl>
</lsl>


<div id="box">
== Comments ==
<div style="padding: 0.5em;">
The search URL needed to be changed as of 2010-01-10 to comply with modification of LL HHTP code, which apparently moved the requested key out of LSL limit for body parameter within http_response event.
</div>
{{LSLC|Library}}
{{LSLC|Library}}

Revision as of 11:05, 10 January 2010

Find Avatar Key

Explores UUID of avatar whose name is said in local chat or who touches the prim. Uses Name2Key code published in LSL Library.

Requirements:

  • Place this script into a single prim and decorate to taste.

Operation:

  • No special instructions. It operates stand alone once installed.

<lsl>// Find Avatar Key Script // by Huney Jewell // based on Name2Key code published in LSL Library // // Put in single prim // Explores UUID of avatar whose name is said in local chat or who touches the prim // LL Search engine sometimes returns wrong profile, hence lookup may fail. // Then the only method to explore the key is by touching the prim //

// GLOBALS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// System settings - Do Not Change Anything Below!

string search = "http://lawlinter.net/secondlifeutility/name2key.php5?name="; // Name2Key URL //string search = "http://w-hat.com/name2key?terse=1&name="; // Alternate Name2Key URL string notFound = "00000000-0000-0000-0000-000000000000";

list requests = [];

// CODE ENTRY //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

default {

   on_rez(integer i)
   {
       llResetScript();
   }
   state_entry()
   {
       llSay(0, "Ready. Say \"/1 firstname lastname\" or touch me");
       llListen(1, "", "", "");
   }
   touch_start(integer total_number)
   {
       integer i = 0;
       for (; i < total_number; ++i)
       {
           llSay(0, llDetectedName(i) + " = " + (string)llDetectedKey(i));
       }
   }
   listen(integer c, string n, key i, string msg)
   {
       list Args=llParseString2List(msg, [" "], []);
       string FirstName = llList2String(Args, 0);
       string LastName = llList2String(Args, 1);
       string name = FirstName + " " + LastName;
       llSay(0,"Requesting key for " + name);
       if(llListFindList(requests,[name]) == -1)
       {
           string url = search + FirstName + "%20" + LastName;
           key id = llHTTPRequest(url, [], "");
           requests += [(string)id,name];
       }
   }
   http_response(key request_id, integer status, list metadata, string body)
   {
       //        llOwnerSay("Status:" + (string) status + "; Body: " + body); // DEBUG
       integer p = llListFindList(requests,[(string)request_id]);
       if (p != -1)
       {
           string name = llList2String(requests,p+1);
           if (status == 200)
           {
               if (body != notFound)
                   llSay(0,name + " = " + body);
               else
                   llSay(0,"Lookup '" + name + "' failed: Not found.");
           }
           else
           {
               if (status == 499)
                   llSay(0,"Lookup '" + name + "' timed out, try again.");
               else
                   llSay(0,"Lookup '" + name + "' failed: HHTP error code " + (string)status);
           }
           requests = llDeleteSubList(requests,p,p+1);
       }
   }

}</lsl>

Comments

The search URL needed to be changed as of 2010-01-10 to comply with modification of LL HHTP code, which apparently moved the requested key out of LSL limit for body parameter within http_response event.