How to use it
Target URLs
- Name 2 Key : n2k.appspot.com/n2k/ + avatar name, example
- Key 2 Name : n2k.appspot.com/k2n/ + avatar key, example
Notes
- Always, always, always check the returned status code. Unless a 200 is returned it is probably garbage.
- Check the length of the key returned (Second Life's UUIDs have a length of 36 characters). In the event nothing matches the service will return an empty string.
- Remember to escape any spaces in the URL.
- The Key2Name service is sorta iffy. This seems to be due to some older avatars that haven't logged in for awhile or something like that. I gave up trying to figure things out, but Linden Labs seems to be working on it [eventually].
Overly Complex Example Script
string gLookupUrl = "http://n2k.appspot.com";
key gKeyRequestID;
key gNameRequestID;
integer gLocked = 0;
default
{
touch_start(integer total_number)
{
if(gLocked == FALSE)
{
key avatar = llDetectedKey(0);
gNameRequestID = llHTTPRequest( gLookupUrl + "/k2n/" + (string) avatar, [], "" );
gKeyRequestID = llHTTPRequest( gLookupUrl + "/n2k/" + llEscapeURL(llKey2Name(avatar)), [], "" );
llSetTimerEvent(15);
gLocked == TRUE;
}
else
llWhisper(0, "Please wait for my request to finish");
}
http_response( key request_id, integer status, list metadata, string body )
{
//it is best to check if the response was correct (ie status == 200), sometimes app engine
//gets a little fidgety (particularly when it hasn't been requested in awhile)
if(status == 200)
{
if(request_id == gKeyRequestID)
{
integer length = llStringLength(body);
if(length == 36) // a proper key is 36 characters long
llWhisper(0, "Your key is \"" + body + "\"");
//ideally the service will return an empty string if no key is found
else if(length == 0)
llWhisper(0, "No key was returned, this shouldn't happen!");
else
llWhisper(0, "An invalid response was returned, this shouldn't happen!");
gKeyRequestID = NULL_KEY;
}
else if(request_id == gNameRequestID)
{
if(body == "")
llWhisper(0, "No name was returned, this happens sometimes, particularly on older avatars.");
else
llWhisper(0, "Your name is \"" + body + "\"");
gNameRequestID = NULL_KEY;
}
}
else
llWhisper(0, "The request was invalid!");
//Release the lock when both requests are finished
if(gNameRequestID == NULL_KEY && gKeyRequestID == NULL_KEY)
{
gLocked = FALSE;
llSetTimerEvent(0);
}
}
timer()
{
llWhisper(0, "The request timed out");
gLocked = FALSE;
}
}