Envoyer des donnees depuis le Web vers SL
Publié : mar. févr. 02, 2010 4:47 pm
Fabriquer un objet dans second life qui reçoit des informations en provenance du web, et les affiches dans le chat dans Second Life.
1-Code à mettre dans une page web .php
2-Script a mettre dans l'objet dans second life
http://wiki.secondlife.com/wiki/Categor ... erver_Code
Voir aussi
http://wiki.secondlife.com/wiki/User:Op ... Chromutate
1- code à mettre dans page web .php
2 script objet dans SL
------------------------------------------
Version plus complexe
Creer dans SL un objet Maitre (papa) et 3 cubes enfants...
Voir le site web
http://wiki.secondlife.com/wiki/User:Op ... Chromutate
Mettre le script "Controller Script" dans l'objet master sur second life...
Mettre le script "color change script" dans chacun des cubes
Controller Script :
Color Change script
Script de la page HTML permettant de commander les couleurs
1-Code à mettre dans une page web .php
2-Script a mettre dans l'objet dans second life
http://wiki.secondlife.com/wiki/Categor ... erver_Code
Voir aussi
http://wiki.secondlife.com/wiki/User:Op ... Chromutate
1- code à mettre dans page web .php
Code : Tout sélectionner
<?php
echo '<pre>';
$channel = "51f044bc-4797-b8c8-e2b7-b2d4dca5ef53"; //Fill in the channel you are using (key)
$intvalue = "42"; //Fill in the intvalue you are using (integer)
$strvalue = "bonjour"; //Fill in the strvalue you are using (string)
$xmldata = "<?xml version=\"1.0\"?><methodCall><methodName>llRemoteData</methodName>
<params><param><value><struct>
<member><name>Channel</name><value><string>".$channel."</string></value></member>
<member><name>IntValue</name><value><int>".$intvalue."</int></value></member>
<member><name>StringValue</name><value><string>".$strvalue."</string></value></member>
</struct></value></param></params></methodCall>";
echo sendToHost("xmlrpc.secondlife.com", "POST", "/cgi-bin/xmlrpc.cgi", $xmldata);
echo '</pre>';
function sendToHost($host,$method,$path,$data,$useragent=0)
{
$buf="";
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if( !$fp )
{
$buf = "$errstr ($errno)<br />\n";
}else
{
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: text/xml\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
if ($useragent)
fputs($fp, "User-Agent: MSIE\r\n");
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
}
return $buf;
}
?>Code : Tout sélectionner
key remoteChannel;
init() {
llOpenRemoteDataChannel(); // create an XML-RPC channel
llOwnerSay("My key is " + (string)llGetKey());
}
default {
state_entry() {
init();
}
state_exit() {
return;
}
on_rez(integer param) {
llResetScript();
}
remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
if (type == REMOTE_DATA_CHANNEL) { // channel created
llSay(DEBUG_CHANNEL,"Channel opened for REMOTE_DATA_CHANNEL" +
(string)channel + " " + (string)message_id + " " + (string)sender + " " +
(string)ival + " " + (string)sval);
remoteChannel = channel;
llOwnerSay("Ready to receive requests on channel \"" + (string)channel + "\"");
state receiving; // start handling requests
} else {
llSay(DEBUG_CHANNEL,"Unexpected event type");
}
}
}
state receiving {
state_entry() {
llOwnerSay("Ready to receive information from outside SL");
}
state_exit() {
llOwnerSay("No longer receiving information from outside SL.");
llCloseRemoteDataChannel(remoteChannel);
}
on_rez(integer param) {
llResetScript();
}
remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
if (type == REMOTE_DATA_REQUEST) { // handle requests sent to us
llSay(DEBUG_CHANNEL,"Request received for REMOTE_DATA_REQUEST " + (string)channel + " " +
(string)message_id + " " + (string)sender + " " + (string)ival + " " + (string)sval);
llRemoteDataReply(channel,NULL_KEY,"I got it",2008);
llOwnerSay("I just received data in "+ llGetRegionName() +
" at position " + (string)llGetPos() + "\n" +
"The string was " + sval + "\nThe number was " + (string)ival + ".");
}
}
}------------------------------------------
Version plus complexe
Creer dans SL un objet Maitre (papa) et 3 cubes enfants...
Voir le site web
http://wiki.secondlife.com/wiki/User:Op ... Chromutate
Mettre le script "Controller Script" dans l'objet master sur second life...
Mettre le script "color change script" dans chacun des cubes
Controller Script :
Code : Tout sélectionner
string name1 = "LOL_color_controller";
string name2 = "Someone at www.armaghia.fr: ";
string risposta = "Thanks! Please use the button in your browser to go back.";
key mykeyEd = "e1828fa6-f540-43be-b6c9-015d46d29679"; // my SL UUID - change this!
key mykeyJul = "7fde0a28-7198-431f-948d-0944f2a4710c"; // my SL UUID - change this!
key mykeyNico = "3366a03d-0ea5-40ff-ac1b-b311a1cc6d3e"; // my SL UUID - change this!
key mykeyBoris = "51520917-a3d9-4417-91e0-fe29ec0d26c8"; // my SL UUID - change this!
key mykeyYann = "0b9b2536-fd9a-43d9-8dc4-39b46002c22c"; // my SL UUID - change this!
string gridurl_key="757f8ad1-b853-47cf-a1d0-dfd852219a31"; // change this!
string gridurl_indirizzo = "http://gridurl.appspot.com/go/757f8ad1-b853-47cf-a1d0-dfd852219a31"; // change this!
string baseurl = "http://gridurl.appspot.com/reg?service=";
integer chan1 = -20241; // you may want to change this as well
integer chan2 = -20242; // you may want to change this as well
integer chan3 = -20243; // you may want to change this as well
integer channel_avvertore = -20247; // you may want to change this as well
string strReplace(string str, string search, string replace)
{
return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
}
vector sbColorConvert(string strData) {
integer mode = -1; // llListFindList(lstHTML, [llToLower(strData)]);
integer intColor = 0;
{
string strStart = llGetSubString(strData, 0, 1);
if (strStart != "0x") {
if (llGetSubString(strStart, 0, 0) == "#") {
strData = "0x" + llDeleteSubString(strData, 0, 0);
}
else {
vector vecColor = (vector)("<"+strData+">");
if (vecColor) {
return (vector)("<"+strData+">") / 255;
}
strData = "0x" + strData;
}
}
intColor = (integer)strData;
mode = llStringLength(strData);
}
if (mode == 8) {//RRGGBB
return <(intColor >> 16) & 0xFF, (intColor >> 8) & 0xFF, (intColor & 0xFF)> / 0xFF;
}
return ZERO_VECTOR;//black
}
string url;
string query;
string nome;
string t1 = "il mio indirizzo e' ";
key requestid;
integer status = FALSE;
list requests;
vector pos_orig;
////////////////////////////////////////////////////////////////////////////////
// richiedo un nuovo URL per lo script
setup()
{
url = "";
llRequestURL();
}
// risponde via HTTP
send_response(key id, string body)
{
llHTTPResponse(id, 200, risposta);
}
// http://gridurl.appspot.com/
update_gridurl(string testo)
{
query = gridurl_key + "&url=" + llEscapeURL(testo) + "/";
requestid = llHTTPRequest(baseurl + query,[HTTP_METHOD,"GET", HTTP_MIMETYPE,"application/x-www-form-urlencoded"], "");
}
// fa qualcosa
fa(key id, string asd)
{
string a = llUnescapeURL(asd);
send_response(id, a);
list variabili = llParseString2List(asd, ["rez=", "&color1=", "&color2=","&color3=", "&a="], [""]);
integer rez_choice = (integer)llList2String(variabili, 0);
string color1 = llUnescapeURL(llList2String(variabili, 1));
string color2 = llUnescapeURL(llList2String(variabili, 2));
string color3 = llUnescapeURL(llList2String(variabili, 3));
string messaggio = llUnescapeURL(llList2String(variabili, 4));
llRegionSay(chan1, (string)sbColorConvert(color1));
llRegionSay(chan2, (string)sbColorConvert(color2));
llRegionSay(chan3, (string)sbColorConvert(color3));
// llOwnerSay("> " + llList2String(variabili, 0));
if(rez_choice == 1)
{
altro();
}
if(messaggio)
{
messaggio = strReplace(messaggio, "+", " ");
llSetObjectName(name2);
llShout(0, messaggio);
llSetObjectName(name1);
}
llInstantMessage(mykeyEd, messaggio);
llInstantMessage(mykeyJul, messaggio);
llInstantMessage(mykeyNico, messaggio);
llInstantMessage(mykeyBoris, messaggio);
llInstantMessage(mykeyYann, messaggio);
}
altro()
{
string obj = llGetInventoryName(INVENTORY_OBJECT,0);
// llOwnerSay("Da web mi fanno rezzare");
llRezObject(obj, pos_orig + <0,0,2>, <0,0,0>, <0,0,0,0>, 1);
llRegionSay(channel_avvertore,"spara");
}
default
{
state_entry()
{
setup();
pos_orig = llGetPos();
}
on_rez(integer n)
{
setup();
}
changed(integer c)
{
if (c & (CHANGED_REGION | CHANGED_REGION_START | CHANGED_TELEPORT) )
{
setup();
}
}
// scatta in risposta a setup() cioe' alla richiesta di un nuovo URL
http_request(key id, string method, string body)
{
// ci e' stato correttamente assegnato un nuovo URL
if (method == URL_REQUEST_GRANTED)
{
url = body;
llOwnerSay(" nuovo url = " + url);
update_gridurl(body);
}
else if (method == URL_REQUEST_DENIED)
{
llInstantMessage(mykeyEd, "Something went wrong, no url. " + body);
}
// lo script e' stato richiamato (da un browser, cliccando su un link...)
// fa qualcosa
else if (method == "GET")
{
string asd = llGetHTTPHeader(id, "x-query-string");
//llOwnerSay(" query = " + asd);
fa(id,asd);
}
else
{
llHTTPResponse(id,405,"Unsupported method.");
}
}
// comunico gli URL dello script
touch_start(integer total_number)
{
llInstantMessage(mykeyEd, "Il mio indirizzo attualmente e' "
+ url + " - il link permanente per utilizzarmi e' " + gridurl_indirizzo);
}
}
Code : Tout sélectionner
default
{
state_entry()
{
llListen(-20241, "", "", ""); // you may need to change this, if you changed it in the first script
}
listen(integer chan, string name, key id, string msg)
{
llSetLinkColor(-1, (vector)msg, ALL_SIDES);
}
}Script de la page HTML permettant de commander les couleurs
Code : Tout sélectionner
<html>
<head>
<title>
CHROMUTATE _ Test par Edwige
</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<meta name="google-site-verification" content="eRmiOY44Kpj7jUeQ88lcBvgjWU03El7ApnZgJGMQ_uE" />
<!-- flooble Color Picker header start -->
<script language="Javascript" type="text/javascript">
var perline = 9;
var divSet = false;
var curId;
var colorLevels = Array('0', '3', '6', '9', 'C', 'F');
var colorArray = Array();
var ie = false;
var nocolor = 'none';
if (document.all) { ie = true; nocolor = ''; }
function getObj(id) {
if (ie) { return document.all[id]; }
else { return document.getElementById(id); }
}
function addColor(r, g, b) {
var red = colorLevels[r];
var green = colorLevels[g];
var blue = colorLevels[b];
addColorValue(red, green, blue);
}
function addColorValue(r, g, b) {
colorArray[colorArray.length] = '#' + r + r + g + g + b + b;
}
function setColor(color) {
var link = getObj(curId);
var field = getObj(curId + 'field');
var picker = getObj('colorpicker');
field.value = color;
if (color == '') {
link.style.background = nocolor;
link.style.color = nocolor;
color = nocolor;
} else {
link.style.background = color;
link.style.color = color;
}
picker.style.display = 'none';
eval(getObj(curId + 'field').title);
}
function setDiv() {
if (!document.createElement) { return; }
var elemDiv = document.createElement('div');
if (typeof(elemDiv.innerHTML) != 'string') { return; }
genColors();
elemDiv.id = 'colorpicker';
elemDiv.style.position = 'absolute';
elemDiv.style.display = 'none';
elemDiv.style.border = '#000000 1px solid';
elemDiv.style.background = '#FFFFFF';
elemDiv.innerHTML = getColorTable();
document.body.appendChild(elemDiv);
divSet = true;
}
function pickColor(id) {
if (!divSet) { setDiv(); }
var picker = getObj('colorpicker');
if (id == curId && picker.style.display == 'block') {
picker.style.display = 'none';
return;
}
curId = id;
var thelink = getObj(id);
picker.style.top = getAbsoluteOffsetTop(thelink) + 20;
picker.style.left = getAbsoluteOffsetLeft(thelink);
picker.style.display = 'block';
}
function genColors() {
addColorValue('0','0','0');
addColorValue('3','3','3');
addColorValue('6','6','6');
addColorValue('8','8','8');
addColorValue('9','9','9');
addColorValue('A','A','A');
addColorValue('C','C','C');
addColorValue('E','E','E');
addColorValue('F','F','F');
for (a = 1; a < colorLevels.length; a++)
addColor(0,0,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,a,5);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,a);
for (a = 1; a < colorLevels.length; a++)
addColor(a,a,0);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,5,a);
for (a = 1; a < colorLevels.length; a++)
addColor(0,a,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(a,5,5);
for (a = 1; a < colorLevels.length; a++)
addColor(a,0,a);
for (a = 1; a < colorLevels.length - 1; a++)
addColor(5,a,5);
return colorArray;
}
function getColorTable() {
var colors = colorArray;
var tableCode = '';
tableCode += '<table border="0" cellspacing="1" cellpadding="1">';
for (i = 0; i < colors.length; i++) {
if (i % perline == 0) { tableCode += '<tr>'; }
tableCode += '<td bgcolor="#000000"><a style="outline: 1px solid #000000; color: '
+ colors[i] + '; background: ' + colors[i] + ';font-size: 10px;" title="'
+ colors[i] + '" href="javascript:setColor(\'' + colors[i] + '\');"> </a></td>';
if (i % perline == perline - 1) { tableCode += '</tr>'; }
}
if (i % perline != 0) { tableCode += '</tr>'; }
tableCode += '</table>';
return tableCode;
}
function relateColor(id, color) {
var link = getObj(id);
if (color == '') {
link.style.background = nocolor;
link.style.color = nocolor;
color = nocolor;
} else {
link.style.background = color;
link.style.color = color;
}
eval(getObj(id + 'field').title);
}
function getAbsoluteOffsetTop(obj) {
var top = obj.offsetTop;
var parent = obj.offsetParent;
while (parent != document.body) {
top += parent.offsetTop;
parent = parent.offsetParent;
}
return top;
}
function getAbsoluteOffsetLeft(obj) {
var left = obj.offsetLeft;
var parent = obj.offsetParent;
while (parent != document.body) {
left += parent.offsetLeft;
parent = parent.offsetParent;
}
return left;
}
</script>
<!-- flooble Color Picker header end -->
</head>
<body>
<FORM action="http://gridurl.appspot.com/go/757f8ad1-b853-47cf-a1d0-dfd852219a31/?" method="get" enctype="multipart/form-data" target="myframe">
<h4>Rez objects?</h4>
<INPUT type="radio" name="rez" value="0" CHECKED> no<BR />
<INPUT type="radio" name="rez" value="1"> yes
<h4>Click the squares to change the colors of the building</h4>
<ul>
<li>color 1
<!-- flooble.com Color Picker start -->
<a href="javascript:pickColor('pick1254101223');" id="pick1254101223"
style="border: 1px solid #000000; font-family:Verdana; font-size:10px;
text-decoration: none;"> </a>
<input id="pick1254101223field" size="7"
type="hidden" name="color1" value="#000060">
<script language="javascript">relateColor('pick1254101223', getObj('pick1254101223field').value);</script>
<noscript><a href="http://www.flooble.com/scripts/colorpicker.php">javascript color picker by flooble</a> | <a href="http://perplexus.info/tree.php">puzzles, problems, riddles by category</a>
</noscript>
<!-- flooble Color Picker end -->
</li>
<li>color 2
<!-- flooble.com Color Picker start -->
<a href="javascript:pickColor('pick1254101723');" id="pick1254101723"
style="border: 1px solid #000000; font-family:Verdana; font-size:10px;
text-decoration: none;"> </a>
<input id="pick1254101723field" size="7"
type="hidden" name="color2" value="#006000">
<script language="javascript">relateColor('pick1254101723', getObj('pick1254101723field').value);</script>
<noscript><a href="http://www.flooble.com/scripts/colorpicker.php">javascript color picker by flooble</a> | Read free <a href="http://perplexus.info/">brainteasers</a>
</noscript>
<!-- flooble Color Picker end -->
</li>
<li>color 3
<!-- flooble.com Color Picker start -->
<a href="javascript:pickColor('pick1254101741');" id="pick1254101741"
style="border: 1px solid #000000; font-family:Verdana; font-size:10px;
text-decoration: none;"> </a>
<input id="pick1254101741field" size="7"
type="hidden" name="color3" value="#600000">
<script language="javascript">relateColor('pick1254101741', getObj('pick1254101741field').value);</script>
<noscript><a href="http://www.flooble.com/scripts/colorpicker.php">javascript color picker by flooble</a> | <a href="http://www.flooble.com/scripts/">get free javascript games and effects</a>
</noscript>
<!-- flooble Color Picker end -->
</li>
</ul>
<h4>Send a message to public local chat</h4>
<INPUT type="text" name="a" onclick="this.value='';" value="Write here your message" size="70">
<h4>When you're done, click 'Send'</h4>
<INPUT type="submit" value="Send">
<!-- <INPUT type="Reset"> -->
</FORM>
<iframe src ="" width="500" height="50" name="myframe">
<p>Your browser does not support iframes.</p>
</iframe>
</body> </html>