Name2Key in LSL
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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 SERVICE_NAME2KEY = 19790; integer SERVICE_NAME2KEY_RET=19791; key ONE_KEY = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
integer gCurrentRequest=0; key gReqId=NULL_KEY; string gToSearch="";
ReturnService(integer Status, string message) { key Key;
if (Status) Key=ONE_KEY; else Key=NULL_KEY;
llMessageLinked(LINK_THIS, gCurrentRequest+1, message, Key);
gCurrentRequest=0; gReqId=NULL_KEY; gToSearch=""; }
SvcName2Key(string message) { if (gCurrentRequest) { ReturnService(FALSE, "BUSY"); }
gCurrentRequest=SERVICE_NAME2KEY; string url="http://secondlife.com/app/search/search?s=Resident&q="+llEscapeURL(message); gToSearch="secondlife:///app/agent/";
gReqId=llHTTPRequest(url, [HTTP_METHOD,"GET"], ""); }
default { link_message(integer sender_number, integer number, string message, key id) { if (number==SERVICE_NAME2KEY) { SvcName2Key(message); } }
http_response(key request_id, integer status, list metadata, string body) { if (request_id==gReqId) { integer Pos1=llSubStringIndex(body, gToSearch); integer Pos2=0; string Ret=""; if (Pos1!=-1) { body=llGetSubString(body, Pos1+llStringLength(gToSearch), -1); if (gCurrentRequest==SERVICE_NAME2KEY) { Pos2=llStringLength((string)NULL_KEY); string Dat=llGetSubString(body, 0, Pos2-1); if (llStringLength((string)((key)Dat))==llStringLength(NULL_KEY)) { // Success ! Ret=llGetSubString(body, 0, Pos2-1); ReturnService(TRUE, Ret); } else ReturnService(FALSE, "UNKNOWN"); } else ReturnService(FALSE, "UNKNOWN SERVICE"); } else ReturnService(FALSE, "UNKNOWN"); }
} } </lsl>
Usage sample: <lsl> integer SERVICE_NAME2KEY = 19790; integer SERVICE_NAME2KEY_RET=19791; key ONE_KEY = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
MyName2Key(string message) { llMessageLinked(LINK_THIS, SERVICE_NAME2KEY, message, NULL_KEY); }
default { touch_start(integer total_number) { llOwnerSay("Searching key for avatar named Secret2 Linden"); MyName2Key("Secret2 Linden"); }
link_message(integer sender_number, integer number, string message, key id) { if (number==SERVICE_NAME2KEY_RET) { if (id==ONE_KEY) llOwnerSay("Found ! Key is: "+message); else llOwnerSay("Error: "+message); } } } </lsl>
Hope this helps ! Maeva Anatine
EDIT : Looks like the Lindens have either broken or blocked this function. It works from my browser, however from LSL I get an error page containing this message "Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect." - Darling Brody.
EDIT : Yes you're right Darling. It seems they've blocked this acces from within the world... I still wonder why, especially as there are some workarounds to this... Anyway I discovered there is a JIRA issue for this. Please vote for the unblock ! https://jira.secondlife.com/browse/SVC-3122 - Mae