Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ridiculously and overly complex XStreetSL data interceptor
- // with absolutely no comments on how it works
- // by Nicocci Denfu
- string separator = " ";
- string args = "";
- string next_arg() {
- string result = "";
- integer index = 0;
- do {
- index = llSubStringIndex(args, separator);
- if (index == -1) result += args;
- else result += llDeleteSubString(args, index, -1);
- args = llDeleteSubString(args, 0, index);
- if (llGetSubString(result, -1, -1) == "\\") result = llDeleteSubString(result, -1, -1) + separator;
- } while (llGetSubString(result, -1, -1) == separator && args != "");
- return result;
- }
- integer listener = 0;
- init() {
- llOwnerSay((string)llGetFreeMemory() + " bytes free.");
- llListenRemove(listener);
- listener = llListen(1, "", llGetOwner(), "");
- }
- integer chat = 1;
- list capture_values = [4];
- list ignore_values = [];
- integer captured = 0;
- integer ignored = 0;
- list data_forwarding = [
- "Rescale [Boxed]", "http://www.lawlinter.net/secondlifeutility/rescalereg.php", "recipient"
- ];
- list req_ids = [];
- list req_keys = [];
- list req_fails = [];
- string gen_tid() {
- return "&tid=" + (string)((integer)llFrand(DEBUG_CHANNEL));
- }
- default
- {
- state_entry() {
- init();
- }
- on_rez(integer start) {
- init();
- }
- listen(integer channel, string name, key id, string msg) {
- args = msg;
- string arg = next_arg();
- if (arg != "xsli")
- return;
- while (args != "") {
- arg = llToLower(next_arg());
- if (arg == "-capture" || arg == "-c") {
- integer new_value = (integer)next_arg();
- if (llListFindList(capture_values, [new_value]) < 0) {
- capture_values += [new_value];
- llOwnerSay("Capturing new data value: \"" + (string)new_value + ".\"");
- } else
- llOwnerSay("Already capturing data value \"" + (string)new_value + ".\"");
- } else if (arg == "-ignore" || arg == "-i") {
- integer new_value = (integer)next_arg();
- if (llListFindList(ignore_values, [new_value]) < 0) {
- ignore_values += [new_value];
- llOwnerSay("Ignoring new data value: \"" + (string)new_value + ".\"");
- } else
- llOwnerSay("Already ignoring data value \"" + (string)new_value + ".\"");
- } else if (arg == "-rmcap") {
- integer new_value = (integer)next_arg();
- integer index = llListFindList(capture_values, [new_value]);
- if (index >= 0) {
- capture_values = llDeleteSubList(capture_values, index, index);
- llOwnerSay("Removing capture data value: \"" + (string)new_value + ".\"");
- } else
- llOwnerSay("Not capturing data value \"" + (string)new_value + ".\"");
- } else if (arg == "-rmign") {
- integer new_value = (integer)next_arg();
- integer index = llListFindList(ignore_values, [new_value]);
- if (index >= 0) {
- ignore_values = llDeleteSubList(ignore_values, index, index);
- llOwnerSay("Removing ignore data value: \"" + (string)new_value + ".\"");
- } else
- llOwnerSay("Not ignoring data value \"" + (string)new_value + ".\"");
- } else if (arg == "-stats") {
- llOwnerSay("Capture statistics:" + "\nCaptured: " + (string)captured + "\nIgnored: " + (string)ignored + "\nTotal: " + (string)(captured + ignored));
- } else if (arg == "-clear") {
- capture_values = [];
- ignore_values = [];
- llOwnerSay("All intercept values cleared.");
- } else if (arg == "-forward") {
- arg = next_arg();
- if (llListFindList(data_forwarding, [arg]) < 0) {
- data_forwarding += [arg, next_arg(), next_arg()];
- llOwnerSay("Added forwarding entry for \"" + arg + ".\"");
- } else
- llOwnerSay("Forwarding entry \"" + arg + "\" already exists.");
- } else if (arg == "-rmfwd") {
- arg = next_arg();
- integer index = llListFindList(llList2ListStrided(data_forwarding, 0, -1, 3), [arg]);
- index *= 3;
- if (index < 0)
- llOwnerSay("No forwarding entry found for \"" + arg + ".\"");
- else {
- data_forwarding = llDeleteSubList(data_forwarding, index, index + 2);
- llOwnerSay("Forwarding entry \"" + arg + "\" removed.");
- }
- } else if (arg == "-lsfwd") {
- string text = "";
- integer count = llGetListLength(data_forwarding);
- while (count > 0) {
- text = "\n" + llDumpList2String(llList2List(data_forwarding, count - 3, count - 1), "\n") + "\n" + text;
- count -= 3;
- }
- llOwnerSay("------- DATA FORWARDING ENTRIES -------\n" + text + "\n------- END DATA FORWARDING ENTRIES -------");
- } else if (arg == "-chat") {
- chat = !chat;
- if (chat)
- llOwnerSay("Intercepted message chatter enabled.");
- else
- llOwnerSay("Intercepted message chatter disabled.");
- } else if (arg == "-lsfail") {
- llOwnerSay("------- FAILED DATA FORWARD REQUESTS -------\n" + llDumpList2String(req_fails, "\n") + "\n------- END FAILED DATA FORWARD REQUESTS -------");
- }
- }
- }
- link_message(integer sender, integer data, string msg, key id) {
- if (llListFindList(capture_values, [data]) < 0 && llGetListLength(capture_values) || llListFindList(ignore_values, [data]) >= 0) {
- ++ignored;
- return;
- }
- if (llGetListLength(data_forwarding)) {
- list margs = llParseString2List(msg, [" "], []);
- integer index = llListFindList(data_forwarding, [llDumpList2String(llList2List(margs, 4, -1), " ")]);
- if (index >= 0) {
- req_ids += [llHTTPRequest(llList2String(data_forwarding, index + 1) + "?" + llList2String(data_forwarding, index + 2) + "=" + llList2String(margs, 2) + gen_tid(), [], "")];
- req_keys += [llList2String(margs, 2)];
- llOwnerSay("Sending data forwarding request to " + llList2String(data_forwarding, index + 1) + " on behalf of avatar key: " + llList2String(margs, 2) + ".");
- }
- }
- if (chat) {
- llOwnerSay(
- "------- LINK MESSAGE -------" +
- "\nSender link: " + (string)sender +
- "\nData value: " + (string)data +
- "\nParsed message: " +
- "\n\t{ " + llDumpList2String(llParseString2List(msg, ["\n"], []), " }\n\t{ ") + " }" +
- "\nID key: " + (string)id +
- "\n------- END LINK MESSAGE -------"
- );
- }
- ++captured;
- }
- dataserver(key query, string data) {
- if (chat) {
- llOwnerSay(
- "------- DATASERVER RESPONSE -------" +
- "\nQuery ID: " + (string)query +
- "\nBody message: " + data +
- "\n\t{ " + llDumpList2String(llParseString2List(data, [" "], []), " }\n\t{ ") + " }" +
- "\n------- END DATASERVER RESPONSE -------"
- );
- }
- ++captured;
- }
- http_response(key request, integer status, list metadata, string body) {
- integer index = llListFindList(req_ids, [request]);
- if (index < 0) {
- if (chat) {
- llOwnerSay(
- "------- HTTP RESPONSE -------" +
- "\nRequest ID: " + (string)request +
- "\nHTTP status: " + (string)status +
- "\nMetadata: " +
- "\n\t{ " + llDumpList2String(metadata, " }\n\t{ ") + " }" +
- "\nParsed message: " +
- "\n\t{ " + llDumpList2String(llParseString2List(body, [" "], []), " }\n\t{ ") + " }" +
- "\n------- END HTTP RESPONSE -------"
- );
- }
- ++captured;
- } else {
- if (status == 200)
- llOwnerSay("Data forwarding succeeded for avatar key " + llList2String(req_keys, index) + " with body:\n" +
- "------- MESSAGE BODY -------\n" + body + "\n------- END MESSAGE BODY -------");
- else {
- llOwnerSay("Data forwarding failed for avatar key " + llList2String(req_keys, index) + " with body:\n" +
- "------- MESSAGE BODY -------\n" + body + "\n------- END MESSAGE BODY -------");
- if (llListFindList(req_fails, llList2List(req_keys, index, index)) < 0) {
- req_fails += [llList2String(req_keys, index)];
- if (llGetListLength(req_fails) > 100)
- req_fails = llList2List(req_fails, -100, -1);
- }
- }
- req_ids = llDeleteSubList(req_ids, index, index);
- req_keys = llDeleteSubList(req_keys, index, index);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement