Um script de LSL

[lsl]
// Handles registration with the external database
// Accepts remote calls to trigger animations, send IMs to people etc

string registrationURL = "http://botmover.betatechnologies.info/inworld/registerPosition.php";
string externalURL; // this is what we’ll get from SL to get incoming connections
string webServerURLupdateInventory = "http://botmover.betatechnologies.info/inworld/updateInventory.php";
key registrationRequest; // used to track down the request for registration
key serverKey;
key httpRequestKey;

default
{
state_entry()
{
llSetText("", <1.0,1.0,1.0>, 1.0);
}

on_rez(integer what)
{
llWhisper(0, "Registering position…");
llRequestSecureURL();
}

touch_start(integer total_number)
{
llInstantMessage(llDetectedKey(0), "Registering position…");
llRequestSecureURL();
}

http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == registrationRequest)
{
if (status == 200)
{
llOwnerSay(body);
// switch to inventory reading
state read_inventory;
}
else
{
llOwnerSay("Error " +(string)status + ": " + body);
}
}
}
http_request(key id, string method, string body)
{
if (method == URL_REQUEST_GRANTED)
{
externalURL = body;
string myTimestamp = llGetTimestamp();
registrationRequest = llHTTPRequest(registrationURL, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
"permURL=" + llEscapeURL(externalURL)
+ "&timestamp=" + myTimestamp
+ "&signature=" + llMD5String((string)llGetKey() + myTimestamp, 9876));

llSetTimerEvent(3600.0); // if the registration fails, try later

}
else if (method == URL_REQUEST_DENIED)
{
llOwnerSay("Something went wrong, no url. " + body);
}
else if (method == "POST" || method == "GET")
{
// incoming request for refunds or IMs
//llOwnerSay(body);

list params = llParseStringKeepNulls(body, ["&", "="], []);
string VoucherID;
string Type;
string AvatarName;
key AvatarUUID;
string ItemName;
string ItemRef;
integer Value;

//llOwnerSay("List parsed: " + (string) params);

if (llList2String(params, 0) == "VoucherID")
VoucherID = llList2String(params, 1);
if (llList2String(params, 2) == "Type")
Type = llList2String(params, 3);
if (llList2String(params, 4) == "AvatarName")
AvatarName = llUnescapeURL(llList2String(params, 5));
if (llList2String(params, 6) == "AvatarUUID")
AvatarUUID = llList2Key(params, 7);
if (llList2String(params, 8) == "ItemName")
ItemName = llUnescapeURL(llList2String(params, 9));
if (llList2String(params, 10) == "ItemRef")
ItemRef = llUnescapeURL(llList2String(params, 11));
if (llList2String(params, 12) == "Value")
Value = llList2Integer(params, 13);

//llOwnerSay("Incoming message: VoucherID=" + VoucherID
// + ", Type=" + Type
// + ", AvatarName=" + AvatarName
// + ", AvatarUUID=" + (string)AvatarUUID
// + ", ItemName=" + ItemName
// + ", ItemRef=" + ItemRef
// + ", Value=" + (string)Value + ".");

if (Type == "STAMP-VENDOR")
{
// Process refund
llGiveMoney(AvatarUUID, Value);
llInstantMessage(AvatarUUID, AvatarName + ", here goes your refund of L$" + (string)Value + " for item ‘" + ItemName + "’ (ref #" + ItemRef + ")");
llOwnerSay("Processed refund for " + AvatarName + ". Amount of L$" + (string)Value + " for item ‘" + ItemName + "’ (ref #" + ItemRef + ")");
llHTTPResponse(id, 200, "OK");
}
else
{
llHTTPResponse(id, 405, "Unknown Type: " + Type);
}
}
else
{
llHTTPResponse(id, 405, "Method unsupported");
}
}

changed(integer c)
{
// Region changed, get a new PermURL
if (c & (CHANGED_REGION | CHANGED_REGION_START | CHANGED_TELEPORT) )
{
llRequestSecureURL();
}
// Deal with inventory changes
else if (c & CHANGED_INVENTORY)
state read_inventory;
}

timer()
{
llSetTimerEvent(0.0);
llRequestSecureURL();
}
}

state read_inventory
{
state_entry()
{
llSetText("Sending to webserver – 0%", <0.3, 0.7, 0.2>, 1.0);
// now prepare this line for sending to web server

string httpBody;
string itemName;
string myTimeStamp;
integer i;
integer length = llGetInventoryNumber(INVENTORY_ALL);
serverKey = llGetKey();

llSetTimerEvent(360.00); // timeout if the web server is too slow in responding

// Now add the new items.
// This needs two passes: on the first one, we’ll skip textures
// The second pass will add them later

for (i = 0; i < length; i++)
{
itemName = llGetInventoryName(INVENTORY_ALL, i);

if (llGetInventoryType(itemName) != INVENTORY_SCRIPT && llGetInventoryType(itemName) != INVENTORY_TEXTURE) // skip script, skip textures
{
myTimeStamp = llGetTimestamp();

httpBody = "name=" + llEscapeURL(itemName) +
"&timestamp=" + myTimeStamp +
"&permissions=" + (string) llGetInventoryPermMask(itemName, MASK_NEXT) +
"&itemType=" + (string) llGetInventoryType(itemName) +
"&signature=" + llMD5String((string)serverKey + myTimeStamp, 9876);
llSleep(1.0);

httpRequestKey = llHTTPRequest(webServerURLupdateInventory,
[HTTP_METHOD, "POST",
HTTP_MIMETYPE,"application/x-www-form-urlencoded"],
httpBody);
//llOwnerSay("Object " + (string) i + ": " + httpBody);
if (httpRequestKey == NULL_KEY)
llOwnerSay("Error contacting webserver on item #" + (string)i);

llSetText("Sending to webserver – " + (string) ((integer)((float)i/(float)length*100)) + "%", <0.3, 0.7, 0.2>, 1.0);
}
}
state default;
}

http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == httpRequestKey)
{
if (status != 200)
{
llOwnerSay("HTTP Error " + (string)status + ": " + body);
}
else
{
llOwnerSay("Web-server reply: " + body);
if (body == "closed")
state default;

}
}
}

timer()
{
// HTTP server does not work, go to default state for now
llOwnerSay("Web server did not reply after 3 minutes – not updated – try again later");
}
}
[/lsl]