User:Takat Su/Name2Key

From Second Life Wiki
< User:Takat Su
Revision as of 16:02, 20 September 2009 by Takat Su (talk | contribs) (Created page with '{{LSL Header}}__NOTOC__ == Name2Key == '''This is an update to Maeva Anatine's excellent suggestion for an updated name2key function. Rather than overwrite all her work, I crea...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Name2Key

This is an update to Maeva Anatine's excellent suggestion for an updated name2key function. Rather than overwrite all her work, I created this page. The idea is DEFINITELY hers - I just am creating an alternate implementation.

Still missing Name2Key functions in your code? Still relying on external databases that are not always up to date with latests SL subscribers?

Well now you can solve this by yourself, within your LSL script! All you have to do is to rely on LL Search engine!

I put a kind of "library" and a sample of usage for your convenience


Library

<lsl> integer cmdName2Key = 19790; integer cmdName2KeyResponse = 19791;

list gRequests;

key requestName2Key( string inName ) {

   list lNameParts = llParseString2List( inName, [" "], [] );
   string lFirstName = llList2String( lNameParts, 0 );
   string lLastName = llList2String( lNameParts, 1 );
   return llHTTPRequest( "http://name2key.appspot.com/?name=" + lFirstName + "%20" + lLastName, [], "" );

}

default {

   link_message( integer inFromPrim, integer inCommand, string inName, key inKey ) {
       if( inCommand == cmdName2Key )
           gRequests += [requestName2Key( inName ), inKey ];
   }
   
   http_response(key inKey, integer inStatus, list inMetaData, string inBody ) {
       integer lPosition = llListFindList( gRequests, [inKey]);
       if( lPosition != -1 ) {
           llMessageLinked( LINK_SET, cmdName2KeyResponse, inBody, llList2Key( gRequests, lPosition+1 ) );
           gRequests = llDeleteSubList( gRequests, lPosition, lPosition + 1 );
       }
   }

} </lsl>

Usage sample

<lsl> integer cmdName2Key = 19790; integer cmdName2KeyResponse = 19791;

default {

   state_entry() {
       llMessageLinked( LINK_SET, cmdName2Key, "Test Name", NULL_KEY );
   }
   
   link_message( integer inFromPrim, integer inCommand, string inKeyData, key inReturnedKey ) {
       if( inCommand == cmdName2KeyResponse ) {
           list lParts = llParseString2List( inKeyData, [":"], [] );
           string lName = llList2String( lParts, 0 );
           key lKey = (key)llList2String(lParts, 1 );
       }
   }
}</lsl>

Comments

The main difference is that I wrote a an app for the google app engine that act as a relay. Since I was going that far, it also parses the return, strips out all the extraneous stuff and just returns you the name and key separated by a colon.

Takat Su