/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // CONFIGURATION // ////////////////////////////////////////////////////////// string SHORT_URL = "sales"; string API_KEY = "A1364788-B702-4413-B937-7A57E32B43CE"; /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// key uReq = NULL_KEY; string llURL = ""; default { state_entry() { llReleaseURL(llURL); llURL = ""; llSetTimerEvent(5); llRequestURL(); } on_rez(integer param) { llReleaseURL(llURL); llResetScript(); } timer() { if(llURL != "") { llSetTimerEvent(0); uReq = llHTTPRequest("http://grimore.org/SIM/registerURL.php?action=register&apiKey=" + API_KEY + "&shortURL=" + SHORT_URL + "&llURL=" + llURL, [HTTP_METHOD, "GET"], ""); return; } } http_request(key id, string method, string body) { if (method == URL_REQUEST_GRANTED) { llURL = body; return; } if(method == URL_REQUEST_DENIED) { llReleaseURL(llURL); llResetScript(); return; } } http_response(key reqID, integer status, list metadata, string body) { if (uReq == reqID && body == SHORT_URL) { llHTTPResponse(uReq, 200, "OK"); state registered; } } } state registered { state_entry() { llSetTimerEvent(60); llOwnerSay("[K] REG URL: URL registered: " + llURL); } timer() { llSetTimerEvent(0); uReq = llHTTPRequest(llURL, [HTTP_METHOD, "POST"], "STATUS"); } http_request(key id, string method, string body) { // alarm if(method == "POST" && body == "STATUS") { llHTTPResponse(id, 200, ""); llSetTimerEvent(60); return; } llOwnerSay("[K] REG URL: Requesting URL."); llReleaseURL(llURL); llResetScript(); } changed(integer change) { llOwnerSay("[K] REG URL: Requesting URL."); llReleaseURL(llURL); llResetScript(); } }