Advertisement
Guest User

Name2Key service Inworld

a guest
May 4th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // support name.surname and fix bad key picking if user is not foudn or hidden
  2.  
  3. string sUrl = "http://anonymouse.org/cgi-bin/anon-www.cgi/http://search.secondlife.com/client_search.php?s=people&session=00000000-0000-0000-0000-000000000000&mat=7&q=";
  4. string sSearchString = "http://world.secondlife.com/resident/";
  5. string sLineStart = "<h3 class=\"result_title\">";
  6. string sLineEnd = "</h3>";
  7. integer iKeyLength = 36;
  8. string sMessage = "Please say the name in chat!";
  9. string sMessageSearching = "Searching for: ";
  10. string sMessageResult = "Result: ";
  11. float fTime = 20;
  12. integer iListen;
  13. string AVname;
  14.  
  15.  
  16. string strReplace(string str, string search, string replace) {
  17.     return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
  18. }
  19.  
  20. default
  21. {
  22.     touch_start(integer total_number)
  23.     {
  24.         llSetTimerEvent(fTime);
  25.         iListen = llListen(PUBLIC_CHANNEL, "", llDetectedKey(0), "");
  26.         llSay(PUBLIC_CHANNEL, sMessage);
  27.     }
  28.     timer()
  29.     {
  30.         llListenRemove(iListen);
  31.         llSetTimerEvent(0);
  32.     }
  33.     listen(integer channel, string name, key id, string message)
  34.     {
  35.         message =  llStringTrim(message,STRING_TRIM);
  36.         message = strReplace(llToLower(message),".","");
  37.        
  38.         if(llToLower(llGetSubString(message,-8,-1)) == "resident")
  39.         {
  40.             message =llGetSubString(message,0,-9);
  41.         }
  42.  
  43.         AVname = strReplace(llToLower(message)," ",".");
  44.        
  45.         llListenRemove(iListen);
  46.         llSay(PUBLIC_CHANNEL, sMessageSearching + AVname);
  47.         llSetTimerEvent(0);
  48.         llHTTPRequest(sUrl + llEscapeURL(message), [HTTP_BODY_MAXLENGTH,16384], "");
  49.     }
  50.     http_response(key request_id, integer status, list metadata, string body)
  51.     {
  52.         string sResultKey = "";
  53.         integer iLineStart = llSubStringIndex(body,sLineStart) + llStringLength(sLineStart);
  54.         integer iLineEnd = llSubStringIndex(body,sLineEnd) - 1;
  55.         string LineFound = llGetSubString(body,iLineStart,iLineEnd);
  56.        
  57.         llOwnerSay(LineFound);
  58.        
  59.         if (llSubStringIndex(LineFound, "(" + AVname + ")") > 1)
  60.         {
  61.             integer iResultPos = llSubStringIndex(LineFound, sSearchString);
  62.             if (iResultPos != -1)
  63.             {
  64.                 iResultPos = iResultPos + llStringLength(sSearchString);
  65.                 sResultKey = llGetSubString(LineFound, iResultPos, iResultPos + iKeyLength-1);
  66.             }
  67.             else
  68.             sResultKey = NULL_KEY;
  69.         }
  70.         else
  71.         sResultKey = NULL_KEY;
  72.        
  73.         llSay(PUBLIC_CHANNEL, sMessageResult + sResultKey);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement