<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://jul.is.a.n0life.org/blog/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>jul is a nolife - Second Life</title>
  <link>http://jul.is.a.n0life.org/blog/</link>
  <description></description>
  <language>ab</language>
  <pubDate>Thu, 02 Feb 2012 15:26:03 +0100</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Service web rails pour Second Life (2/2)</title>
    <link>http://jul.is.a.n0life.org/blog/post/2008/01/28/Service-web-rails-pour-Second-Life-2/2</link>
    <guid isPermaLink="false">urn:md5:908eab8ca8be9d064d2f80fa588ef540</guid>
    <pubDate>Mon, 28 Jan 2008 16:40:00 +0100</pubDate>
    <dc:creator>jul</dc:creator>
        <category>Ruby On Rails</category><category>Second Life</category>    
    <description>    &lt;p&gt;Pour continuer sur les traces du précédent article, intéressons nous à nouveau à Second Life et Ruby on Rails.
Dans cet article, nous allons voir comment communiquer depuis un objet dans le jeu vers un site Rails.
Plus simplement, nous n'allons cette fois pas utiliser le système de webservice de rails, mais uniquement les arguments d'url. Ce service minuscule aura juste pour but de convertir tous les caractères en majuscule.&lt;/p&gt;


&lt;p&gt;Cette fois nous commençons donc par la partie LSL&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;

string texte=&amp;quot;Hello World&amp;quot;;
string texte_majuscule;

default
{
  state_entry()
    {
    
     string resultat;
     llHTTPRequest(&amp;quot;http://monserveur.fr/second_life/majuscule&amp;quot;, [HTTP_METHOD, &amp;quot;PUT&amp;quot;,HTTP_MIMETYPE,&amp;quot;application/x-www-form-urlencoded&amp;quot;], &amp;quot;texte=&amp;quot;+(string)texte);

    }

  http_response(key request_id, integer status, list metadata, string body) {
    texte_majuscule=body;
  }

}

&lt;/pre&gt;


&lt;p&gt;Le résultat est récupéré dans la fonction http_response.&lt;/p&gt;


&lt;p&gt;La partie rails est bien plus simple encore&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
class SecondLifeController &amp;lt; ApplicationController
 def majuscule
   render :text=&amp;gt;params[:texte].upcase
 end
end
&lt;/pre&gt;


&lt;p&gt;Bien sur il ne s'agit que d'un exemple, je suis sur que vous aurez de bien meilleurs idées que moi!&lt;/p&gt;</description>
    
    
    
          <comments>http://jul.is.a.n0life.org/blog/post/2008/01/28/Service-web-rails-pour-Second-Life-2/2#comment-form</comments>
      <wfw:comment>http://jul.is.a.n0life.org/blog/post/2008/01/28/Service-web-rails-pour-Second-Life-2/2#comment-form</wfw:comment>
      <wfw:commentRss>http://jul.is.a.n0life.org/blog/feed/rss2/comments/24</wfw:commentRss>
      </item>
    
  <item>
    <title>Second Life web service with rails (1/2)</title>
    <link>http://jul.is.a.n0life.org/blog/post/2007/07/11/Second-Life-web-service-with-rails-1/2</link>
    <guid isPermaLink="false">urn:md5:abc7dea589c4a5e3e93fd6125431aea9</guid>
    <pubDate>Wed, 11 Jul 2007 20:27:00 +0200</pubDate>
    <dc:creator>jul</dc:creator>
        <category>Ruby On Rails</category><category>Second Life</category>    
    <description>    &lt;p&gt;In this first part, we will see how to communicate with an in-world object from a ruby on rails application thanks to XML-RPC.
At the beginning, we define a second life structure (app/models/second_life_struct.rb) which represent the API format of second life :&lt;/p&gt;

&lt;pre&gt;

class SecondLifeStruct &amp;lt; ActionWebService::Struct
  member &amp;quot;Channel&amp;quot;, :string
  member &amp;quot;StringValue&amp;quot;, :string
  member &amp;quot;IntValue&amp;quot;, :int
end
&lt;/pre&gt;


&lt;p&gt;Next, we create a new rails API (app/apis/second_life_api.rb) which use the structure :&lt;/p&gt;

&lt;pre&gt;
class SecondLifeApi &amp;lt; ActionWebService::API::Base
  inflect_names false
  api_method &amp;quot;llRemoteData&amp;quot;, :expects=&amp;gt;[SecondLifeStruct], :returns=&amp;gt;[SecondLifeStruct]
end
&lt;/pre&gt;


&lt;p&gt;Before continuing, let's see the object LSL script which receive communication :&lt;/p&gt;

&lt;pre&gt;

default
{
  state_entry()
    {
     llOpenRemoteDataChannel(); 
    }

    remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) 
    {
      if(type==REMOTE_DATA_CHANNEL) {
	llOwnerSay(&amp;quot;Communication channel: &amp;quot;+(string)channel);
      } 

      if(type==REMOTE_DATA_REQUEST) {
        llOwnerSay(sval);
        llRemoteDataReply(channel,message_id,&amp;quot;Everything is alright&amp;quot;,0);
      }
    }
}

&lt;/pre&gt;


&lt;p&gt;Communication channel is an unique key which permit to communicate back with this object from the Linden's webservice. We must copy this key for loading our rails web page (/second_life/test_object?channel=key)&lt;/p&gt;


&lt;p&gt;We just have to define the controller now:&lt;/p&gt;

&lt;pre&gt;
class SecondLifeController &amp;lt; ApplicationController
  web_client_api :second_life, :xmlrpc, &amp;quot;http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi&amp;quot;, :timeout=&amp;gt;90

  def test_object
    canal=params[:channel]
    begin
      resultat=second_life.llRemoteData(SecondLifeStruct.new(&amp;quot;Channel&amp;quot;=&amp;gt;canal,&amp;quot;StringValue&amp;quot;=&amp;gt;&amp;quot;Hello World!&amp;quot;,&amp;quot;IntValue&amp;quot;=&amp;gt;&amp;quot;0&amp;quot;))
      render :text=&amp;gt;resultat[&amp;quot;StringValue&amp;quot;]
    rescue
     render :text=&amp;gt;&amp;quot;Object doesn't respond&amp;quot;
    end
  end
end

&lt;/pre&gt;


&lt;p&gt;That's all! When we load the page, second life object says &quot;Hello World!&quot;
In the next post, we will see how to communicate in the other way : from in-world object to rails application.&lt;/p&gt;


&lt;p&gt;More informations about second life XML-RPC format  &lt;a href=&quot;http://www.lslwiki.net/lslwiki/wakka.php?wakka=XMLRPC&quot; hreflang=&quot;en&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://jul.is.a.n0life.org/blog/post/2007/07/11/Second-Life-web-service-with-rails-1/2#comment-form</comments>
      <wfw:comment>http://jul.is.a.n0life.org/blog/post/2007/07/11/Second-Life-web-service-with-rails-1/2#comment-form</wfw:comment>
      <wfw:commentRss>http://jul.is.a.n0life.org/blog/feed/rss2/comments/23</wfw:commentRss>
      </item>
    
  <item>
    <title>Service web rails pour Second Life (1/2)</title>
    <link>http://jul.is.a.n0life.org/blog/post/2007/06/13/Service-web-rails-pour-Second-Life-1/2</link>
    <guid isPermaLink="false">urn:md5:22be8367b1df9264642a8c1b14037bbc</guid>
    <pubDate>Wed, 13 Jun 2007 18:33:00 +0200</pubDate>
    <dc:creator>jul</dc:creator>
        <category>Ruby On Rails</category><category>Second Life</category>    
    <description>    &lt;p&gt;Dans cette première partie, nous verrons comment communiquer avec un objet in-world depuis une application ruby on rails grâce à XML-RPC.
Pour commencer on définit une structure second life (app/models/second_life_struct.rb) qui représentera le format de l'api second life&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
class SecondLifeStruct &amp;lt; ActionWebService::Struct
  member &amp;quot;Channel&amp;quot;, :string
  member &amp;quot;StringValue&amp;quot;, :string
  member &amp;quot;IntValue&amp;quot;, :int
end
&lt;/pre&gt;


&lt;p&gt;Ensuite, on créé une nouvelle api (app/apis/second_life_api.rb) qui utilise cette structure:&lt;/p&gt;
&lt;pre&gt;
class SecondLifeApi &amp;lt; ActionWebService::API::Base
  inflect_names false
  api_method &amp;quot;llRemoteData&amp;quot;, :expects=&amp;gt;[SecondLifeStruct], :returns=&amp;gt;[SecondLifeStruct]
end
&lt;/pre&gt;


&lt;p&gt;Avant de continuer, intéressons nous rapidement au script LSL de l'objet qui permettra de recevoir la communication&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
default
{
  state_entry()
    {
     llOpenRemoteDataChannel(); 
    }

    remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) 
    {
      if(type==REMOTE_DATA_CHANNEL) {
	llOwnerSay(&amp;quot;Canal de communication : &amp;quot;+(string)channel);
      } 

      if(type==REMOTE_DATA_REQUEST) {
        llOwnerSay(sval);
        llRemoteDataReply(channel,message_id,&amp;quot;Tout va bien&amp;quot;,0);
      }
    }
}
&lt;/pre&gt;

&lt;p&gt;Le canal de communication correspond à un identifiant unique permettant de communiquer par la suite avec cet objet depuis le service web de Linden. Il faudra copier cet identifiant pour pouvoir appeler notre page dans rails (/second_life/tester_objet?canal=identifiant).&lt;/p&gt;


&lt;p&gt;Il ne reste plus qu'à définir le controlleur&amp;nbsp;:&lt;/p&gt;
&lt;pre&gt;
class SecondLifeController &amp;lt; ApplicationController
  web_client_api :second_life, :xmlrpc, &amp;quot;http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi&amp;quot;, :timeout=&amp;gt;90

  def tester_objet
    canal=params[:canal]
    begin
      resultat=second_life.llRemoteData(SecondLifeStruct.new(&amp;quot;Channel&amp;quot;=&amp;gt;canal,&amp;quot;StringValue&amp;quot;=&amp;gt;&amp;quot;Bonjour tout le monde !&amp;quot;,&amp;quot;IntValue&amp;quot;=&amp;gt;&amp;quot;0&amp;quot;))
      render :text=&amp;gt;resultat[&amp;quot;StringValue&amp;quot;]
    rescue
     render :text=&amp;gt;&amp;quot;L'objet ne répond pas&amp;quot;
    end
  end
end
&lt;/pre&gt;


&lt;p&gt;Et voila, lorsque l'on se connecte à la page, l'objet dans second life nous dira &quot;Bonjour tout le monde !&quot;.&lt;/p&gt;


&lt;p&gt;Comme on vient de le voir, le système de service web de ruby on rails permet d'interfacer facilement votre application à second life.
Le prochain article montrera comment faire l'opération inverse&amp;nbsp;: communiquer depuis un objet second life vers une application rails.&lt;/p&gt;


&lt;p&gt;Pour plus d'information sur le format XML-RPC de second life, voir &lt;a href=&quot;http://www.lslwiki.net/lslwiki/wakka.php?wakka=XMLRPC&quot; hreflang=&quot;en&quot;&gt;ici&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://jul.is.a.n0life.org/blog/post/2007/06/13/Service-web-rails-pour-Second-Life-1/2#comment-form</comments>
      <wfw:comment>http://jul.is.a.n0life.org/blog/post/2007/06/13/Service-web-rails-pour-Second-Life-1/2#comment-form</wfw:comment>
      <wfw:commentRss>http://jul.is.a.n0life.org/blog/feed/rss2/comments/22</wfw:commentRss>
      </item>
    
</channel>
</rss>
