/////////////////////////////////////////////////////////////////////////// // 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 // ////////////////////////////////////////////////////////// // Permanent short URL map name using external database. string SHORT_URL = "sales"; // API key - can be anything, used as a password. string API_KEY = "A1364788-B702-4413-B937-7A57E32B43CE"; /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// string llURL = ""; key nQuery = NULL_KEY; key _owner = NULL_KEY; default { state_entry() { _owner = llGetOwner(); llSetColor(<1,0,0>, ALL_SIDES); state off; } on_rez(integer num) { llResetScript(); } attach(key id) { llResetScript(); } } state on { state_entry() { nQuery = llHTTPRequest("http://server.tld:90/SIM/registerURL.php?action=retrieve&apiKey=" + API_KEY + "&shortURL=" + SHORT_URL, [HTTP_METHOD, "GET"], ""); } http_response(key reqID, integer status, list metadata, string body) { if(nQuery != reqID) return; if(body != "ACK") jump step_url; llSetColor(<0,1,0>, ALL_SIDES); llOwnerSay("ON"); return; @step_url; if(llSubStringIndex(body, "http://") < 0) return; llHTTPResponse(nQuery, 200, "OK"); llURL = body; nQuery = llHTTPRequest(llURL, [HTTP_METHOD, "POST"], "signon=" + (string)_owner + "#" + llKey2Name(_owner)); } touch_start(integer num) { llSetColor(<1,1,0>, ALL_SIDES); state off; } on_rez(integer num) { llResetScript(); } attach(key id) { llResetScript(); } } state off { state_entry() { nQuery = llHTTPRequest("http://server.tld:90/SIM/registerURL.php?action=retrieve&apiKey=" + API_KEY + "&shortURL=" + SHORT_URL, [HTTP_METHOD, "GET"], ""); } http_response(key reqID, integer status, list metadata, string body) { if(nQuery != reqID) return; if(body != "ACK") jump step_url; llSetColor(<1,0,0>, ALL_SIDES); llOwnerSay("OFF"); return; @step_url; if (llSubStringIndex(body, "http://") < 0) return; llHTTPResponse(nQuery, 200, "OK"); llURL = body; nQuery = llHTTPRequest(llURL, [HTTP_METHOD, "POST"], "signoff=" + (string)_owner + "#" + llKey2Name(_owner)); } touch_start(integer num) { llSetColor(<1,1,0>, ALL_SIDES); state on; } on_rez(integer num) { llResetScript(); } attach(key id) { llResetScript(); } }