Strillone per OpenSim

May 2, 2009 da salahzar

Fatto uno “strillone” per dare notecard con notizie importanti su una sim.

Utilizza un database su opensimita. Per utilizzarlo basta cambiare la descrizione con un nome non utilizzato esempio: nomesim.notizia. Più strilloni anche su sim diverse non distribuiranno MAI la stessa notizia alla stessa persona perchè i dati vengono caricati su un db centrale

Programma lsl

list requests;
list avatars; // lista degli avatars complessivi
list newavatars; // only new avatars
list newavatarkeys;

string URL="http://opensimita.org/lsl/server-key.php?";

default
{
    state_entry()
    {
        llSetText("Distribuisco "+llGetObjectDesc(),<1,1,1>,1);
        llSensorRepeat("",NULL_KEY,AGENT,256,PI,10);
        newavatars=[];
        URL+="cat="+llGetObjectDesc();
    }
    no_sensor()
    {
        //llSetText("Individuato finora "+(string)llGetListLength(avatars),<1,1,1>,1);
    }
    sensor(integer num)
    {
        integer i;
        llSetText("Distribuisco "+llGetObjectDesc()+ " ("+(string)llGetListLength(avatars)+")",<1,1,1>,1);
        requests=[]; newavatars=[]; newavatarkeys=[];
        for(i=0;i
        {
            //llOwnerSay(llDetectedName(i)+" "+(string)llVecDist(llDetectedPos(i),llGetPos()));

            string avatar=llDetectedName(i);
            integer found=llListFindList(avatars,avatar);
            //llOwnerSay("Looking for "+avatar+" Found: "+(string)found);
            if(found<0)
            {
                newavatars+= [ avatar ]; newavatarkeys+= [ llDetectedKey(i) ];
                //llSay(0,"Verifico se ho già dato a "+avatar);
                requests+=[ llHTTPRequest( URL+"&get="+llEscapeURL(avatar),[],"") ] ;
            }
        }

    }
    touch_start(integer count)
    {
        //llSetText("Individuato finora "+(string)llGetListLength(avatars),<1,1,1>,1);
        integer i;

        llSay(0,"========\nDall'ultimo reset ho avvertito i seguenti av:");
        for(i=0;i
        {
            llSay(0,llList2String(avatars,i));

        }
        llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD,0));
    }
    http_response(key id, integer status, list metadata, string body)
    {
        //llOwnerSay("Receiving body: "+body+" status: "+(string)status);
        integer index=llListFindList(requests, [id]);
        if(index>=0)
        {
            string avatar=llList2String(newavatars,index);
            avatars+=[avatar];
            if(body=="*NOTFOUND*")
            {
                llSay(0,"Do informazioni a "+avatar);
                llGiveInventory(llList2Key(newavatarkeys,index),llGetInventoryName(INVENTORY_NOTECARD,0));
                string cmd=URL+"&add="+llEscapeURL(avatar)+"&val="+llEscapeURL(llGetDate()+" "+llGetTimestamp());
                //llSay(0,cmd);
                llHTTPRequest( cmd,[],"") ;
            }

            //else
            //llOwnerSay("Found avatar "+avatar);
        }
    }
}

Programma php che riceve i comandi

 <?
//
// call with
// ?cat=c&get=key => returns key or *NOTFOUND*
// ?cat=c&add=key&val=value
// ?cat=c&del=key
// ?cat=c&upd=key&val=value
// ?cat=c&list=%
// ?cat=c&count= to get how many entries
// ?cat=c&item=i 0..n to get nth entry (sorted by key)
//
include 'connect-lsl.php';

// cat helps separating various subtables in the main table
$cat=$_GET['cat'];

// gets the specific commands
$get=$_GET['get'];
$add=$_GET['add'];
$del=$_GET['del'];
$upd=$_GET['upd'];
$list=$_GET['list'];
$count=$_GET['count'];
$item=$_GET['item'];
$value=$_GET['val'];

// adding a new key, value key MUST NOT be existent if so we are updating it
if($add!="")
{
  $query="select chiave from chiavi where cat='$cat' and chiave='".addslashes($add)."'";
  $result=mysql_query($query) or die(mysql_error());
  // echo "$query Found ".mysql_num_rows($result)." lines";
  if(mysql_num_rows($result)==0)
  {
    // adding this key                      , val
    // should check key is not existent
    $query="insert into chiavi values('$cat','".addslashes($add)."','".addslashes($value)."')";
    mysql_query($query) or die(mysql_error());
    die("OK $query");
  }
  // if already existent then we are actually updating
  else $upd=$add;

}

// updating the key
if($upd!="")
{
  $query="update chiavi set valore='".addslashes($value)."' where cat='$cat' and chiave='".addslashes($upd)."'";
  mysql_query($query) or die(mysql_error());
  die("OK $query");
}

// deleting the key
if($del!="")
{
  $query="delete from chiavi where cat='$cat' and chiave='".addslashes($del)."'";
  mysql_query($query) or die(mysql_error());
  die("OK $query");
}

// getting a key note stripslashes which were added in insert to solve problems with ' "
if($get!="")
{
  $query= "select * FROM chiavi where cat='$cat' and chiave='".addslashes($get)."'";
  $result = mysql_query($query) or die(mysql_error());
  if($row = mysql_fetch_array($result))
  {
    echo stripslashes($row['valore']);
  }
  else echo "*NOTFOUND*";
  die();
}

// listing all elements having the substring in the key
if($list!="")
{
  $query1="select * from chiavi where cat='$cat' and chiave like '".$list."'";

  $result=mysql_query($query1) or die(mysql_error());
  while($row=mysql_fetch_array($result))
  {
    echo stripslashes($row['chiave'])."\n";
    echo stripslashes($row['valore'])."\n";
  }
  die();
}

// counting how many elements in this table
if($count!="")
{
  $query= "select count(*) as num FROM chiavi where cat='$cat'";

  $result = mysql_query($query) or die(mysql_error());
  if($row = mysql_fetch_array($result))
  {
    echo $row['num'];
  }
  die();
}

// selecting nth element sorted by key name
if($item!="")
{
  $query="SELECT * FROM chiavi where cat='".$cat."' order by chiave limit 1 offset ".$item;

  $result = mysql_query($query) or die(mysql_error());
  if($row = mysql_fetch_array($result))
  {
    echo stripslashes($row['chiave'])."\n".stripslashes($row['valore'])."\n";
  }
  else echo "*NOTFOUND*";

}
?>

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>