A Drupal framework for interoperating with Second Life objects
Well, it had been a hard day. An important deal feel through and I was depressed. I couldn’t focus, so I did what any hard-core geek would do. I took a nap, and then I did a bit of recreational programming.
Now that I’ve set up a shop in Second Life, I have an interesting place to test out my scripts, and my focus for today was data sharing between Second Life and external sites.
Previously, I’ve done a little work with XML-RPC calls to Second Life. A great starting point is Getting Started With XML-RPC In Second Life. I’ve gotten then to work in the past, but for some reason, my scripts just wouldn’t respond to day using the form that they provided. So, I tried my first pass at calling Second Life XML-RPC from Drupal.
Drupal provides fairly nice XMLRPC integration. This small snippet of code, ought to call my XML-RPC object in Second Life:
$calls[] = array(
'Channel' => "2c67bc74-914d-3a88-2e6a-89cf56058007",
'IntValue' => 0,
'StringValue' => "happy birthday"
);
$test = xmlrpc("http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi","llRemoteData",$calls);
$e = xmlrpc_errno();
$m = xmlrpc_error_msg();
print_r($e);
print_r($m);
print_r($test);
Nothing fancy. Build the XMLRPC string, pass it to Second Life, and print out error messages, error numbers, stuff like that. Right now, it is returning an ‘Invalid channel’, even thought it appears as if my script should be listening on the channel. Once this starts working, it should make sending data between Second Life and Drupal fairly easy.
Meanwhile, I’ve been relying on llEmail() to send me emails from my scripts. It has been working pretty nicely, but for some reason, the commands in my script after the llEmail call do not get executed. More debugging is needed there. There is also the ability to send email into Second Life, using llGetNextEmail(). That will be one of my next tests.
However, the most interesting tests so far, have been to use llHTTPRequest. I created a very simple Drupal module. In my test version, I’m calling it log.module. Whatever pass as a parameter to it gets written in the Watchdog log and saved as a system variable. The System variable can also be displayed in the log block. Try it out, go to http://www.orient-lodge.com/log/this+is+a+test and you’ll see my log block down in the lower right hand corner change to say, “This is a test”. Right now, if you pass a log message to my Drupal installation, you get a blank screen back. I’ll can add messages that I want to send back later.
Sure, its not very secure, but it is a simple test at this point. Using the llHTTPRequest command in Second Life, I modified the picture in my shop so that if you touch the picture it calls my log and leaves your Second Life name on my website. Stop by the shop and give it a test.
With this, I took things to the next level. I modified the picture in my shop so that whenever it starts, it logs a message with the key of the object, the name of the object, the region the object is in, the location of the object in the region, the owner’s key, the owner’s name and a message, in this case ‘State Entry’.
The code I used was took advantage of a new function for version 1.18.3 of Second Life, llGetObjectDetails. It took me a while to figure out why the function wasn’t working. I was still using 1.18.2 and so it wouldn’t compile.
The code snippet I used was:
list a = llGetObjectDetails(llGetKey(), [OBJECT_NAME,
OBJECT_POS, OBJECT_OWNER]);string url = "http://www.orient-lodge.com/log/";
url += (string) llGetKey() + "!+";
url += (string) llList2String(a,0) + "!+" ;
url += (string) llGetRegionName() + "!+";
url += (string) llList2String(a,1) + "!+" ;
url += (string) llList2String(a,2) + "!+" ;
url += (string) llKey2Name(llList2Key(a,2)) + "!+";
url += "State+Entry";
key rid = llHTTPRequest(url,[HTTP_METHOD,"GET"],"");
Using this, an inventory tracking system could easily be created. Object’s owners, locations, and states could easily kept as nodes in Drupal. To the extent that you are providing an object that users would want to wear, using the attach or on_rez events, you could probably track users relatively easily. Either the XML-RPC calls or simply emailing messages to an object could provide means to control an object inside of Second Life from Drupal.
So, establishing a Drupal framework for interoperating with Second Life objects now looks like a viable project. The questions are, who is interested in such a project and what sort of projects can be built upon such a tool.