Difference between revisions of "Failsafename2key"
Jump to navigation
Jump to search
m |
m (moved Failsavename2key to Failsafename2key: Typo) |
(No difference)
|
Latest revision as of 17:41, 13 March 2012
This script is a example for a failsafe name2key lookup. The script will return results also when some of the given providers are unavailable.
Main Script: <lsl> list Servers = ["http://kubwa.de/_slworld/name2key.php?name=",
"http://w-hat.com/name2key?terse=1&name=", "https://n2k.danardlabs.com/n2k_io.php?action=getkey&verbose=0&username=", "http://kdc.ethernia.net/sys/name2key.php?name="];
list LookUpQueue; default {
link_message(integer Sender, integer Num, string Str, key ID) { if (ID == "Name2Key.Lookup") { LookUpQueue = LookUpQueue + [llHTTPRequest(llList2String(Servers, 0) + llEscapeURL(Str), [HTTP_METHOD, "GET", HTTP_VERIFY_CERT, FALSE], ""), 0, Str, Num, Sender]; } } http_response(key Request, integer Status, list Meta, string Data) { integer Found = llListFindList(LookUpQueue, [Request]); if (Found > -1) { list Temp = llParseString2List(Data, [",", ";", " ", ":", "\n", "|"], []); integer i; integer LoopFound = -1; for (i = 0; i < llGetListLength(Temp); ++i) { if (llStringLength(llList2String(Temp, i)) == 36 && llList2Key(Temp, i) != NULL_KEY) {LoopFound = i;} } if (LoopFound > -1) { llMessageLinked(llList2Integer(LookUpQueue, Found + 4), llList2Integer(LookUpQueue, Found + 3), "Found", llList2Key(Temp, LoopFound)); LookUpQueue = llDeleteSubList(LookUpQueue, Found, Found + 4); } else { if (llList2Integer(LookUpQueue, Found + 1) + 1 < llGetListLength(LookUpQueue) - 1) { LookUpQueue = llListReplaceList(LookUpQueue, [llHTTPRequest(llList2String(Servers, llList2Integer(LookUpQueue, Found + 1) + 1) + llEscapeURL(llList2String(LookUpQueue, Found + 2)), [HTTP_METHOD, "GET", HTTP_VERIFY_CERT, FALSE], ""), llList2Integer(LookUpQueue, Found + 1) + 1], Found, Found + 1); } else { llMessageLinked(llList2Integer(LookUpQueue, Found + 4), llList2Integer(LookUpQueue, Found + 3), "Not-Found", NULL_KEY); LookUpQueue = llDeleteSubList(LookUpQueue, Found, Found + 4); } } } }
} </lsl>
Example usage: <lsl> default {
state_entry() { llListen(1, "", "", ""); } listen(integer chan, string name, key id, string msg) { llMessageLinked(LINK_THIS, llRound(llFrand(9999)), msg, "Name2Key.Lookup"); } link_message(integer Sender, integer Num, string Str, key ID) { llOwnerSay((string)Sender + " => " + (string)Num + "> " + Str + ": " + (string)ID); }
} </lsl>
For questions please ask Simba Fuhr in Second Life.