A few people have asked me how I'm distributing the free Elemental Multiform Craft. Below are the scripts and the PHP files to do it. To run a setup like this, you will need a PHP-enabled website. Pretty much all non-free webhosting supports PHP.
The system works like this:
--an interested person clicks on an inworld copy of the doodad (rezzed from a HUD).
--The doodad contacts your website, which tells it the key of your item server.
--The doodad then contacts the server with the person's key
--The server sends a fresh HUD to the person, who can now rez doodads via the HUD.
--The HUD also checks for updates via the same mechanism.
1) Put this in your doodad:
CODE
//script by Kage Seraph
//use, sell, give away, but most importantly enjoy.
default
{
touch_start(integer total_number_touching)
{
if( llDetectedKey(0) == llGetOwner() )
{
//put code here if you want your doodad to respond to its owner's touch.
}
else
{ //it was not the owner
llInstantMessage(llDetectedKey(0), "Hi! I'm the doodad!");
key requestor = llDetectedKey(0);
llInstantMessage(requestor,"Contacting server for your free doodad");
llInstantMessage(requestor,"Have a nice day.");
//set the following web address to your website, including "update-relay.php" at the end.
string geturl = "http://www.YOUR-COOL-WEBSITE.net/update-relay.php";
llHTTPRequest(geturl, [HTTP_METHOD, "GET"], "");
}
}
http_response(key request_id, integer status, list metadata, string body)
{
key x = llList2Key(llParseString2List(body, ["|"], [""]),1);
llOwnerSay("Server contacted!");
llEmail((string)x+"@lsl.secondlife.com",requestor,(string)-1);
// the format is subject = requestor's key
// body = version. This server will interpret the -1 above as a special command to pass the HUD to the requestor.
}
}
2) Save the next bit as "update-relay.php" file on your computer, then upload it to YOUR-COOL-WEBSITE.net, to the address corresponding to what you set in the above touch-script. Remember, your website must support PHP.
CODE
<?php
$answer = "THE-KEY-OF-YOUR-INWORLD-SERVER-PRIM/OBJECT";
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>|' . strval($answer) . '|';
header('Content-type: text/xml');
echo($xml);
?>
Be sure to change "THE-KEY-OF-YOUR-INWORLD-SERVER-PRIM/OBJECT" to the proper value.
3) Put the following script in your inworld server object.
CODE
float newestVersion = 0.1; //Be sure to update the version here AND in the HUD script
//as new versions come along. =)
string senderName;
string objectName = "Doodad HUD"; //change this to your HUD object
integer numberServed = 0;
default
{
on_rez(integer start_param)
{
llOwnerSay((string)llGetKey());
}
state_entry()
{
llSetTimerEvent(5); //the time in seconds between polls for emails.
llSetText("",<1,1,1>,1);
llInstantMessage(llGetOwner(),"Did you remember to update the numberServed?");
llInstantMessage(llGetOwner(),(string)llGetKey()); // copy and paste the key spoken to chat to the update-relay.php file.
}
timer()
{
llGetNextEmail("","");
}
//this inworld server receives emails from HUDs trying to update and from doodads that have been clicked.
//here, we parse the email and figure out what kind of request we're getting.
email(string time, string address, string subject, string message, integer num_left)
{
key requestorKey = (key)subject; //who is doing the asking?
string messageWithoutHeaders = llDeleteSubString(message, 0, llSubStringIndex(message, "\n\n") + 1); //clean off the info prepended to the body of every SL email
if( (float)messageWithoutHeaders < 0 )//then someone's clicked a doodad and wants one.
{
++numberServed;
llInstantMessage(requestorKey,"Sending the latest doodad to you now.");
llGiveInventory(requestorKey, objectName);
}
else if((float)messageWithoutHeaders < newestVersion)
{
llInstantMessage(requestorKey,"Your doodad is obsolete. Sending the latest version to you now.");
llGiveInventory(requestorKey, objectName);
llInstantMessage(requestorKey,"Changes since last version: X Y Z");
}
else
{
llInstantMessage(requestorKey,"Your doodad HUD is up-to-date.");
}
}
}
4) Put the following into your doodad HUD. It checks for updates once a day when it rezzes (when you wear it)
CODE
string geturl = "http://www.YOUR-COOL-WEBSITE.net/update-relay.php";
key initiator_key;
string version = "0.1"; //update this and the version number on the server too as necessary.
string lastChecked = "2006-01-30";
default
{
on_rez(integer start_parameter)
{
llSleep(1);
if(lastChecked != llGetDate())
{
lastChecked = llGetDate();
//poll for updated version with the following email.
//if there is an updated version, the server will send it.
initiator_key = llGetOwner();
string outgoing_url = geturl + "?key=" + (string)initiator_key;
llHTTPRequest(outgoing_url, [HTTP_METHOD, "GET"], "");
}
else
{
//we've already checked for today
//so we won't bother the resi again
}
}
state_entry()
{
llSleep(1);
if(lastChecked != llGetDate())
{
lastChecked = llGetDate();
//poll for updated version with the following email.
//if there is an updated version, the server will send it.
initiator_key = llGetOwner();
string outgoing_url = geturl;
llHTTPRequest(outgoing_url, [HTTP_METHOD, "GET"], "");
}
else
{
//we've already checked for today
//so we won't bother the resi again
//also, this reduces load on the server for popular objects (!).
}
}
http_response(key request_id, integer status, list metadata, string body)
{
//llOwnerSay("http ok");
key x = llList2Key(llParseString2List(body, ["|"], [""]),1);
llEmail((string)x+"@lsl.secondlife.com",llGetOwner(),(string)version);
}
}
So there you go. It isn't secure communication, and it doesn't handle money. Like the earlier, non-http server, an unscrupulous person could potentially use this to harm your privacy. But it is a nice, reasonably simple way to keep people who like your doodad updated.
zOMG.
.