Advertisement
Guest User

XStreet Data Interceptor

a guest
Aug 26th, 2010
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Ridiculously and overly complex XStreetSL data interceptor
  2. // with absolutely no comments on how it works
  3. // by Nicocci Denfu
  4.  
  5. string separator = " ";
  6. string args = "";
  7. string next_arg() {
  8.     string result = "";
  9.     integer index = 0;
  10.     do {
  11.         index = llSubStringIndex(args, separator);
  12.         if (index == -1) result += args;
  13.         else result += llDeleteSubString(args, index, -1);
  14.         args = llDeleteSubString(args, 0, index);
  15.         if (llGetSubString(result, -1, -1) == "\\") result = llDeleteSubString(result, -1, -1) + separator;
  16.     } while (llGetSubString(result, -1, -1) == separator && args != "");
  17.     return result;
  18. }
  19.  
  20. integer listener = 0;
  21. init() {
  22.     llOwnerSay((string)llGetFreeMemory() + " bytes free.");
  23.     llListenRemove(listener);
  24.     listener = llListen(1, "", llGetOwner(), "");
  25. }
  26.  
  27. integer chat = 1;
  28. list capture_values = [4];
  29. list ignore_values = [];
  30. integer captured = 0;
  31. integer ignored = 0;
  32.  
  33. list data_forwarding = [
  34.     "Rescale [Boxed]", "http://www.lawlinter.net/secondlifeutility/rescalereg.php", "recipient"
  35. ];
  36. list req_ids = [];
  37. list req_keys = [];
  38. list req_fails = [];
  39.  
  40. string gen_tid() {
  41.     return "&tid=" + (string)((integer)llFrand(DEBUG_CHANNEL));
  42. }
  43.  
  44. default
  45. {
  46.     state_entry() {
  47.         init();
  48.     }
  49.    
  50.     on_rez(integer start) {
  51.         init();
  52.     }
  53.    
  54.     listen(integer channel, string name, key id, string msg) {
  55.         args = msg;
  56.         string arg = next_arg();
  57.         if (arg != "xsli")
  58.             return;
  59.         while (args != "") {
  60.             arg = llToLower(next_arg());
  61.             if (arg == "-capture" || arg == "-c") {
  62.                 integer new_value = (integer)next_arg();
  63.                 if (llListFindList(capture_values, [new_value]) < 0) {
  64.                     capture_values += [new_value];
  65.                     llOwnerSay("Capturing new data value: \"" + (string)new_value + ".\"");
  66.                 } else
  67.                     llOwnerSay("Already capturing data value \"" + (string)new_value + ".\"");
  68.             } else if (arg == "-ignore" || arg == "-i") {
  69.                 integer new_value = (integer)next_arg();
  70.                 if (llListFindList(ignore_values, [new_value]) < 0) {
  71.                     ignore_values += [new_value];
  72.                     llOwnerSay("Ignoring new data value: \"" + (string)new_value + ".\"");
  73.                 } else
  74.                     llOwnerSay("Already ignoring data value \"" + (string)new_value + ".\"");
  75.             } else if (arg == "-rmcap") {
  76.                 integer new_value = (integer)next_arg();
  77.                 integer index = llListFindList(capture_values, [new_value]);
  78.                 if (index >= 0) {
  79.                     capture_values = llDeleteSubList(capture_values, index, index);
  80.                     llOwnerSay("Removing capture data value: \"" + (string)new_value + ".\"");
  81.                 } else
  82.                     llOwnerSay("Not capturing data value \"" + (string)new_value + ".\"");
  83.             } else if (arg == "-rmign") {
  84.                 integer new_value = (integer)next_arg();
  85.                 integer index = llListFindList(ignore_values, [new_value]);
  86.                 if (index >= 0) {
  87.                     ignore_values = llDeleteSubList(ignore_values, index, index);
  88.                     llOwnerSay("Removing ignore data value: \"" + (string)new_value + ".\"");
  89.                 } else
  90.                     llOwnerSay("Not ignoring data value \"" + (string)new_value + ".\"");
  91.             } else if (arg == "-stats") {
  92.                 llOwnerSay("Capture statistics:" + "\nCaptured: " + (string)captured + "\nIgnored: " + (string)ignored + "\nTotal: " + (string)(captured + ignored));
  93.             } else if (arg == "-clear") {
  94.                 capture_values = [];
  95.                 ignore_values = [];
  96.                 llOwnerSay("All intercept values cleared.");
  97.             } else if (arg == "-forward") {
  98.                 arg = next_arg();
  99.                 if (llListFindList(data_forwarding, [arg]) < 0) {
  100.                     data_forwarding += [arg, next_arg(), next_arg()];
  101.                     llOwnerSay("Added forwarding entry for \"" + arg + ".\"");
  102.                 } else
  103.                     llOwnerSay("Forwarding entry \"" + arg + "\" already exists.");
  104.             } else if (arg == "-rmfwd") {
  105.                 arg = next_arg();
  106.                 integer index = llListFindList(llList2ListStrided(data_forwarding, 0, -1, 3), [arg]);
  107.                 index *= 3;
  108.                 if (index < 0)
  109.                     llOwnerSay("No forwarding entry found for \"" + arg + ".\"");
  110.                 else {
  111.                     data_forwarding = llDeleteSubList(data_forwarding, index, index + 2);
  112.                     llOwnerSay("Forwarding entry \"" + arg + "\" removed.");
  113.                 }
  114.             } else if (arg == "-lsfwd") {
  115.                 string text = "";
  116.                 integer count = llGetListLength(data_forwarding);
  117.                 while (count > 0) {
  118.                     text = "\n" + llDumpList2String(llList2List(data_forwarding, count - 3, count - 1), "\n") + "\n" + text;
  119.                     count -= 3;
  120.                 }
  121.                 llOwnerSay("------- DATA FORWARDING ENTRIES -------\n" + text + "\n------- END DATA FORWARDING ENTRIES -------");
  122.             } else if (arg == "-chat") {
  123.                 chat = !chat;
  124.                 if (chat)
  125.                     llOwnerSay("Intercepted message chatter enabled.");
  126.                 else
  127.                     llOwnerSay("Intercepted message chatter disabled.");
  128.             } else if (arg == "-lsfail") {
  129.                 llOwnerSay("------- FAILED DATA FORWARD REQUESTS -------\n" + llDumpList2String(req_fails, "\n") + "\n------- END FAILED DATA FORWARD REQUESTS -------");
  130.             }
  131.         }
  132.     }
  133.    
  134.     link_message(integer sender, integer data, string msg, key id) {
  135.         if (llListFindList(capture_values, [data]) < 0 && llGetListLength(capture_values) || llListFindList(ignore_values, [data]) >= 0) {
  136.             ++ignored;
  137.             return;
  138.         }
  139.         if (llGetListLength(data_forwarding)) {
  140.             list margs = llParseString2List(msg, [" "], []);
  141.             integer index = llListFindList(data_forwarding, [llDumpList2String(llList2List(margs, 4, -1), " ")]);
  142.             if (index >= 0) {
  143.                 req_ids += [llHTTPRequest(llList2String(data_forwarding, index + 1) + "?" + llList2String(data_forwarding, index + 2) + "=" + llList2String(margs, 2) + gen_tid(), [], "")];
  144.                 req_keys += [llList2String(margs, 2)];
  145.                 llOwnerSay("Sending data forwarding request to " + llList2String(data_forwarding, index + 1) + " on behalf of avatar key: " + llList2String(margs, 2) + ".");
  146.             }
  147.         }
  148.         if (chat) {
  149.             llOwnerSay(
  150.                 "------- LINK MESSAGE -------" +
  151.                 "\nSender link: " + (string)sender +
  152.                 "\nData value: " + (string)data +
  153.                 "\nParsed message: " +
  154.                     "\n\t{ " + llDumpList2String(llParseString2List(msg, ["\n"], []), " }\n\t{ ") + " }" +
  155.                 "\nID key: " + (string)id +
  156.                 "\n------- END LINK MESSAGE -------"
  157.             );
  158.         }
  159.         ++captured;
  160.     }
  161.    
  162.     dataserver(key query, string data) {
  163.         if (chat) {
  164.             llOwnerSay(
  165.                 "------- DATASERVER RESPONSE -------" +
  166.                 "\nQuery ID: " + (string)query +
  167.                 "\nBody message: " + data +
  168.                     "\n\t{ " + llDumpList2String(llParseString2List(data, [" "], []), " }\n\t{ ") + " }" +
  169.                 "\n------- END DATASERVER RESPONSE -------"
  170.             );
  171.         }
  172.         ++captured;
  173.     }
  174.    
  175.     http_response(key request, integer status, list metadata, string body) {
  176.         integer index = llListFindList(req_ids, [request]);
  177.         if (index < 0) {
  178.             if (chat) {
  179.                 llOwnerSay(
  180.                     "------- HTTP RESPONSE -------" +
  181.                     "\nRequest ID: " + (string)request +
  182.                     "\nHTTP status: " + (string)status +
  183.                     "\nMetadata: " +
  184.                         "\n\t{ " + llDumpList2String(metadata, " }\n\t{ ") + " }" +
  185.                     "\nParsed message: " +
  186.                         "\n\t{ " + llDumpList2String(llParseString2List(body, [" "], []), " }\n\t{ ") + " }" +
  187.                     "\n------- END HTTP RESPONSE -------"
  188.                 );
  189.             }
  190.             ++captured;
  191.         } else {
  192.             if (status == 200)
  193.                 llOwnerSay("Data forwarding succeeded for avatar key " + llList2String(req_keys, index) + " with body:\n" +
  194.                     "------- MESSAGE BODY -------\n" + body + "\n------- END MESSAGE BODY -------");
  195.             else {
  196.                 llOwnerSay("Data forwarding failed for avatar key " + llList2String(req_keys, index) + " with body:\n" +
  197.                     "------- MESSAGE BODY -------\n" + body + "\n------- END MESSAGE BODY -------");
  198.                 if (llListFindList(req_fails, llList2List(req_keys, index, index)) < 0) {
  199.                     req_fails += [llList2String(req_keys, index)];
  200.                     if (llGetListLength(req_fails) > 100)
  201.                         req_fails = llList2List(req_fails, -100, -1);
  202.                 }
  203.             }
  204.  
  205.             req_ids = llDeleteSubList(req_ids, index, index);
  206.             req_keys = llDeleteSubList(req_keys, index, index);
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement