HTTP<->XML-RPC Interface Example for Second Life

Submit to Digg
Programming — Psilocybeing on February 5, 2008

Recently I joined Second Life and was amazed to find such a highly customizable and interactive world at my disposal. As I worked through the scripting language used in game I found functions that allowed for communication between HTTP servers, as well as communication from an XML-RPC interface. “Great!” I thought, but unfortunately the XML-RPC interface only allows outside sources to initiate communication, which for a two-way communication system was no good.

The below pair of scripts are designed to allow two-way communication between an object in game and an external PHP script. The way this works is as follows: if the object needs to retrieve information from the PHP script, it will send out a request to the server using Second Lifes llHTTPRequest function, the parameters of which contain the objects ID which is required to be able to send information via Second Lifes XML-RPC interface. Once this information is received the PHP script will send a few lines of text back via the HTTP request, confirming that contact has been made. This text is displayed above the object in blue.

Now I know what you’re thinking, if you can send and receive information via the llHTTPRequest function, why use the XML-RPC interface at all? My reasoning is that if an external application or PHP script wishes to communicate with the in game object, they would have to wait for the object to initialize HTTP communication. Using the XML-RPC interface the PHP script has the ability to initiate communication with the object, thus the circle is complete. Back to the flow, once the PHP script receives the objects ID, it submits an XML form to Second Lifes XML-RPC interface, which will then route the information to the object in game. Once this information arrives, in this example it is sent to the owner of the object in the form of a private message.

While this example is limited, it displays methods for two-way communication on both sides of the looking glass, from SL to PHP, and from PHP to SL.

One other advantage of this method is that not all browsers support the ActiveX plug in used in the example from the below URL, however using PHP to send and process the XML allows for any browser to implement this communication method

Download: Second Life LSL Script to Communicate with HTTP Server

Download: PHP Script to Communicate via XML-RPC to Second Life

Further communication methods from PHP to SL, objects, user keys

Ok, so we’ve got a method of communication between object and server, but what about between user and server? Let’s say we are giving away some freebies in Second Life, but instead of providing them by packaging them up into an object and having the user pay the L$0 ‘fee’ to obtain it, we want to provide the object via a simple HTTP form. We now have a problem; we may have the users name, but we do not have the ID tied to that name with which we will use to transfer the object. This can be solved by using a third-party site called ‘w-hat.com’. They provide a service called ‘name2key’ that will take any avatar name from Second Life and perform a look up, returning the users true ID in game. Using llHTTPRequest we can further automate this by automatically retrieving the user ID from w-hat. Below is a sample URL that will retrieve the ID for the user ‘Seidr Giha’.

Input: http://w-hat.com/name2key?terse=1&name=Seidr+Giha
Output: ef1a9326-53b0-411f-a6be-2e7cc4906817

Now that we have our target user ID, we are able to pass the object to them by using the following function:

string requestorKey=”ef1a9326-53b0-411f-a6be-2e7cc4906817″;
string objectName=”testObject”;
llGiveInventory(requestorKey, objectName);
This will transfer the specified object to the target user pretty much instantaneously. The object to be sent must be contained within the parent object that llGiveInventory is being called from.

Using the above methods we should be able to implement SQL integration into SL scripts and services with a relative amount of ease.

Please feel free to comment on this code, either via eMail/MSN(wo0tPYRO AT hotmail.com) or in game contact via the avatar name ‘Seidr Giha’.

Rock on!

Reference links:

Getting Started Second Life XML-RPC (ver. 1) — Ruben Kleiman 11/14/06

http://www.aiai.ed.ac.uk/project/aiai2/MyRPCObject.html

llHTTPRequest – Second Life Wiki

http://wiki.secondlife.com/wiki/LlHTTPRequest

PHP: Socket Functions – Manual

http://uk3.php.net/sockets

12 Comments »

  1. I don’t believe it. thsi appears to be a pre-written script doing exactly what i want. I am stunned
    thank u so much

    Comment by JulietAnn — March 8, 2009 @ 10:33 pm
  2. Absolutely horrid colors on this blog, I had to copy the text and paste it into a text editor to read it, but very solid information and great examples in this post, thanks!!!

    Comment by Takuan — March 15, 2009 @ 9:10 am
  3. Thanks for sharing the info, greatly needed. And well the colours make it hard to read. But Green is nice:)

    Comment by Jonathan — May 17, 2009 @ 9:13 am
  4. brilliant example, and thank you very much, its very rare to come accross a WORKING example along with clear explanations about it. well done

    Comment by tom — March 12, 2010 @ 6:45 pm
  5. hi, lovely site. one for my bookmarks.

    Comment by rabbit vibrator — September 3, 2010 @ 6:11 pm
  6. Hi , I have a excellent way to make lots and lots of money online posting blogs. I suppose this is probably for the website admin but there are probably alot more bloggers reading this. I have already made thousands using the techniques explained in the product and it has only been 2 months. Auto Blog System X – Blog to the bank

    Comment by Galina Reaux — September 4, 2010 @ 11:05 pm
  7. Bookmarking now thanks, a good fast read.

    Comment by Godparent Gifts — September 5, 2010 @ 10:43 am
  8. Hey guys i want to share with you a way i make $500 daily and i only spend 5 minuites doing it a day! I strongly suggest you check their website out as there is really a brilliant video that explains every thing you need to know. Check them out at DOMINATE MOBILE MARKETING

    Comment by Glory Lyford — September 5, 2010 @ 11:08 am
  9. Hey guys i want to share with you a way i make $500 daily and i only spend 5 minuites doing it a day! I strongly suggest you check their site out as there is a brilliant video that explains every thing you have to know. Check them out at DOMINATE MOBILE MARKETING

    Comment by Loris Zabawa — September 5, 2010 @ 8:01 pm
  10. I liked seeing this, do you have a Facebook page for this site?

    Comment by fashion accessories — September 5, 2010 @ 8:20 pm
  11. Wow this definitely takes me back, where are your contact details hmm?

    Comment by NFL Jerseys Store — September 6, 2010 @ 10:05 am
  12. Good post. I found just what I was looking 4.

    Comment by passion wave stimulator rabbit vibrator — September 8, 2010 @ 4:38 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment