/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2012 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// string URL = ""; key oKey = NULL_KEY; ////////////////////////////////////////////////////////// // Obtain an URL. ////////////////////////////////////////////////////////// default { state_entry() { llSetText("Getting URL...", <1,1,0>, 1); llSetText("", <0,0,0>, 1); llRequestURL(); } http_request(key id, string method, string body) { if(method != URL_REQUEST_GRANTED) llResetScript(); URL = body; state setup; } on_rez(integer num) { llResetScript(); } } ////////////////////////////////////////////////////////// // Handshake with the bot. ////////////////////////////////////////////////////////// state setup { state_entry() { llSetText("Handshaking...", <1,1,0>, 1); llInstantMessage("ea62501a-12a0-4f9c-a12f-134ae701df10", "auth C55OPS"); llSleep(1.1-llGetRegionTimeDilation()); llInstantMessage("ea62501a-12a0-4f9c-a12f-134ae701df10", "c " + URL); // alarm 60s llSetTimerEvent(60); } http_request(key id, string method, string body) { if(method != "POST") return; list data = llParseString2List(body, ["->"], []); // Test to see whether we have a complete handshake. // Did we get an answer from convey? if(llList2String(data, 0) != "CONVEY") return; // Is it going to relay messages to our URL? if(llList2String(data, 1) != URL) llResetScript(); // Be polite and answer the request. llHTTPResponse(id, 200, "OK"); // Handshake completed at this point, switch to main. state main; } timer() { llResetScript(); } on_rez(integer num) { llResetScript(); } } ////////////////////////////////////////////////////////// // Process messages and periodically re-auth. ////////////////////////////////////////////////////////// state main { state_entry() { llSetText("Processing Messages", <0,1,0>, 1); llSetTimerEvent(60); } http_request(key id, string method, string body) { /////////////////////////////////// // This block answers a re-auth. /////////////////////////////////// if(method != "POST") jump try_PUT; list data = llParseString2List(body, ["->"], []); // Test to see whether we have a complete handshake. // Did we get an answer from convey? if(llList2String(data, 0) != "CONVEY") return; // Is it going to relay messages to our URL? if(llList2String(data, 1) != URL) llResetScript(); // Be polite and answer the request. llHTTPResponse(id, 200, "OK"); return; @try_PUT; /////////////////////////////////// // This block processes an instant // message sent to the bot. /////////////////////////////////// // Was it an instant message from the bot? if(method != "PUT") return; // Be courteous and answer Convey's message first. llHTTPResponse(id, 200, "OK"); ///////////////EDIT//////////////// // Now "body" contains the message. /////////////////////////////////// llSay(0, body); /////////////////////////////////// } timer() { llInstantMessage("ea62501a-12a0-4f9c-a12f-134ae701df10", "auth C55OPS"); llSleep(1.1-llGetRegionTimeDilation()); llInstantMessage("ea62501a-12a0-4f9c-a12f-134ae701df10", "c " + URL); } on_rez(integer num) { llResetScript(); } }