Difference between revisions of "User:Opensource Obscure/AvatarsUnited/SimStats"

From Second Life Wiki
Jump to navigation Jump to search
m (created)
 
(nearly complete?)
Line 1: Line 1:
work in progress
''work in progress!'' contact opensource obscure in-world for more info or look at http://www.secondlifeitalia.com/community/viewtopic.php?p=246536#p246536


contact opensource obscure in-world for more info
== Overview ==


or look at http://www.secondlifeitalia.com/community/viewtopic.php?p=246536#p246536
This is a set of scripts you can use to create a simple Avatars United application - a "gadget".
 
This gadget will display statistics from a Second Life region (how many avatars, FPS/Time Dilation values, server hostname and prim usage). Here's how it will appear in your AU page:
[[File:Aulolmonitor.jpg]]
 
To re-create this application you will need:
* an AU developer account
* Linux-based web hosting for your gadget (a few kbytes, but you will also need both Crontab and Bash scripts support)
* land permissions ''(details needed - to do)''
 
== Steps ==
 
Here's what you should do:
# look at [http://developer.avatarsunited.com Avatars United dev docs] ;-)
# customize and put sensor in your region - ''(details needed - to do)''
# customize and host the gadget XML file - ''(details needed - to do)''
# customize the Bash script, host it and put it into your Crontab -or do something similar- in order to periodically query your sensor and update the gadget XML file with fresh data
# follow Avatars United dev docs to create your application - ''(details needed - to do)''
 
== Code ==
 
=== Gadget XML source ===
 
Note: the 2 lines that begin with "A LOL ci sono..." will be periodically updated by the Bash script with actual data from your region.
 
<lsl>
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="LOL Monitor"
    description="This is a test and you shouldn't install it. It currently monitors my LOL sim in Second Life." >
    <Icon>http://img534.imageshack.us/img534/7471/aroundtheworld.png</Icon>
    <Require feature="opensocial-0.8" />
  </ModulePrefs>
 
  <Content type="html" view="profile">
    <![CDATA[
A LOL ci sono 2 persone - FPS: 44.62 - DILATION: 1.000 - USO PRIMS: Open 2072, Ese 112, Pallina 2373, Gebedia 2853. - server: (DISABLED).Sun Jan 31 10:10:02 CET 2010
    ]]>
  </Content>
  <Content type="html" view="canvas">
    <![CDATA[
A LOL ci sono 2 persone - FPS: 44.62 - DILATION: 1.000 - USO PRIMS: Open 2072, Ese 112, Pallina 2373, Gebedia 2853. - server: (DISABLED).Sun Jan 31 10:10:02 CET 2010
    ]]>
  </Content>
</Module>
</lsl>
 
 
=== Bash script ===
 
It calls the in-world LSL prim, asks for region stats, dumps the results to a file, and updates the XML gadget you can find above.
 
<lsl>
#! /bin/bash
lynx -dump -dont_wrap_pre http://gridurl.appspot.com/go/832fde82-95ce-41bb-b65b-13b70f3f65d2 > /var/www/chromutate/oob1.dat
 
AVATARS="`cat /var/www/chromutate/oob1.dat`"
DATENOW="`date`"
 
sed -i "11s/.*/$AVATARS.$DATENOW/" /var/www/chromutate/oob1.xml
sed -i "16s/.*/$AVATARS.$DATENOW/" /var/www/chromutate/oob1.xml
</lsl>
 
 
=== Crontab ===
 
<lsl>*/2 * * * * /var/www/chromutate/oob1.sh</lsl>
 
 
=== LSL Sim Sensor for stats ===
 
<lsl>
// change these values
 
string gridurl_key="CHANGE-ME";
float intervallo = 120.0;
string messaggio = "waiting for update...";
 
// tip: respect spaces
string owner1 = " First Owner name ";
string owner2 = " Second Owner name ";
string owner3 = " Third Owner name ";
string owner4 = " Fourth Owner name ";
 
vector parcel1 = <64,64,0>;
vector parcel2 = <192,64,0>;
vector parcel3 = <64,192,0>;
vector parcel4 = <192,192,0>;
 
string testo1 = ": ci sono ";
string testo2 = " persone";
string message_prim = " - USO PRIMS: " ;
 
 
// ---------------------------------------------------
// don't change below
// ---------------------------------------------------
 
 
string gridurl_error = "Owner didn't set the Gridurl key yet. Go to http://gridurl.appspot.com/random and copy the UUID that will be generated, then paste it at the begin of this script.";
 
 
string gridurl_indirizzo = "http://gridurl.appspot.com/go/";
string baseurl = "http://gridurl.appspot.com/reg?service=";
 
key mykey;
string url;
string query;
key requestid;
string title_sensor ;
string message_sensor;
string simname;
string sensor_pos;
 
setup()
{
    url = "";
    llRequestURL();
}
 
 
// risponde via HTTP
send_response(key id, string body)
{
    llHTTPResponse(id, 200, messaggio);
}
 
 
// 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"],
    "");   
}
 
 
// get current SLURL
string slurl()
{
    // il nome della regione:
    simname = llEscapeURL(llGetRegionName());   
    // le coordinate:
    vector detectedPos = llGetRootPosition();
    string sx = (string)llRound(detectedPos.x);
    string sy = (string)llRound(detectedPos.y);
    string sz = (string)llRound(detectedPos.z);
    // assemblaggio dello SLURL:
    string  url = "http://slurl.com/secondlife/";
    url += simname;
    url += "/" + sx + "/" + sy + "/" + sz;
    return url;
}
 
 
 
sensore()
{
    llOwnerSay(simname);
    string prim_usage = message_prim +
        owner1 + (string)llGetParcelPrimCount(parcel1, PARCEL_COUNT_TOTAL, FALSE) +
        "," + owner2 + (string)llGetParcelPrimCount(parcel2, PARCEL_COUNT_TOTAL, FALSE) +
        "," + owner3 + (string)llGetParcelPrimCount(parcel3, PARCEL_COUNT_TOTAL, FALSE) +
        "," + owner4 + (string)llGetParcelPrimCount(parcel4, PARCEL_COUNT_TOTAL, FALSE) +
        ".";
                               
    string message_fps = " FPS: " + llGetSubString((string)(0.01*llRound(100*llGetRegionFPS())), 0, 4);
    string message_dil = " - DILATION: " + llGetSubString((string)(0.01*llRound(100*llGetRegionTimeDilation())), 0, 4);
    string persone = (string)llGetRegionAgentCount();         
 
    string message_hostname = " - server: " + llGetSimulatorHostname();
    // you may want to disable this as it takes 10"
    // string message_hostname = "";
 
 
 
    title_sensor =
        simname +
        testo1 +
        persone +
        testo2;
       
    message_sensor =
        message_fps +
        message_dil +
        prim_usage +
        message_prim +
        message_hostname +
        " - " + sensor_pos;
       
    messaggio = title_sensor + " - " + message_sensor; 
}
 
 
 
default
{
    state_entry()
    {
        sensor_pos = slurl();               
        mykey = llGetOwner();           
        setup(); 
        sensore();       
        llSetTimerEvent(intervallo);     
    }
   
    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;
            // DEBUG:           
            // llOwnerSay(" nuovo url = " + url);                 
            update_gridurl(url);           
        }
       
        else if (method == URL_REQUEST_DENIED)
        {
            llInstantMessage(mykey, "Something went wrong, no url. " + body);
        }
        // lo script e' stato richiamato (da un browser, cliccando su un link...)
        else if (method == "GET")
        {
   
                // DEBUG:
                // llInstantMessage(mykey, "query = " + query);     
    llHTTPResponse(id, 200, messaggio);
        }
        else
        {
            llHTTPResponse(id,405,"Unsupported method.");
        }
    }
 
 
// comunico gli URL dello script
    touch_start(integer total_number)
    {
        if(gridurl_key != "CHANGE-ME")
        {
            llInstantMessage(mykey, "Click to test: "
            + gridurl_indirizzo
            + gridurl_key);
        }
        else
        {
            llInstantMessage(mykey, gridurl_error);
        }
    }   
   
   
   
    timer()
    {
        sensore();
        //llOwnerSay(messaggio);
    }   
 
}
<lsl>

Revision as of 12:04, 31 January 2010

work in progress! contact opensource obscure in-world for more info or look at http://www.secondlifeitalia.com/community/viewtopic.php?p=246536#p246536

Overview

This is a set of scripts you can use to create a simple Avatars United application - a "gadget".

This gadget will display statistics from a Second Life region (how many avatars, FPS/Time Dilation values, server hostname and prim usage). Here's how it will appear in your AU page: Aulolmonitor.jpg

To re-create this application you will need:

  • an AU developer account
  • Linux-based web hosting for your gadget (a few kbytes, but you will also need both Crontab and Bash scripts support)
  • land permissions (details needed - to do)

Steps

Here's what you should do:

  1. look at Avatars United dev docs ;-)
  2. customize and put sensor in your region - (details needed - to do)
  3. customize and host the gadget XML file - (details needed - to do)
  4. customize the Bash script, host it and put it into your Crontab -or do something similar- in order to periodically query your sensor and update the gadget XML file with fresh data
  5. follow Avatars United dev docs to create your application - (details needed - to do)

Code

Gadget XML source

Note: the 2 lines that begin with "A LOL ci sono..." will be periodically updated by the Bash script with actual data from your region.

<lsl> <?xml version="1.0" encoding="UTF-8" ?> <Module>

  <ModulePrefs title="LOL Monitor"
    description="This is a test and you shouldn't install it. It currently monitors my LOL sim in Second Life." >
    <Icon>http://img534.imageshack.us/img534/7471/aroundtheworld.png</Icon>
    <Require feature="opensocial-0.8" />
  </ModulePrefs>
  <Content type="html" view="profile">
    <![CDATA[

A LOL ci sono 2 persone - FPS: 44.62 - DILATION: 1.000 - USO PRIMS: Open 2072, Ese 112, Pallina 2373, Gebedia 2853. - server: (DISABLED).Sun Jan 31 10:10:02 CET 2010

    ]]>
  </Content>
  <Content type="html" view="canvas">
    <![CDATA[

A LOL ci sono 2 persone - FPS: 44.62 - DILATION: 1.000 - USO PRIMS: Open 2072, Ese 112, Pallina 2373, Gebedia 2853. - server: (DISABLED).Sun Jan 31 10:10:02 CET 2010

    ]]>
  </Content>

</Module> </lsl>


Bash script

It calls the in-world LSL prim, asks for region stats, dumps the results to a file, and updates the XML gadget you can find above.

<lsl>

  1. ! /bin/bash

lynx -dump -dont_wrap_pre http://gridurl.appspot.com/go/832fde82-95ce-41bb-b65b-13b70f3f65d2 > /var/www/chromutate/oob1.dat

AVATARS="`cat /var/www/chromutate/oob1.dat`" DATENOW="`date`"

sed -i "11s/.*/$AVATARS.$DATENOW/" /var/www/chromutate/oob1.xml sed -i "16s/.*/$AVATARS.$DATENOW/" /var/www/chromutate/oob1.xml </lsl>


Crontab

<lsl>*/2 * * * * /var/www/chromutate/oob1.sh</lsl>


LSL Sim Sensor for stats

<lsl> // change these values

string gridurl_key="CHANGE-ME"; float intervallo = 120.0; string messaggio = "waiting for update...";

// tip: respect spaces string owner1 = " First Owner name "; string owner2 = " Second Owner name "; string owner3 = " Third Owner name "; string owner4 = " Fourth Owner name ";

vector parcel1 = <64,64,0>; vector parcel2 = <192,64,0>; vector parcel3 = <64,192,0>; vector parcel4 = <192,192,0>;

string testo1 = ": ci sono "; string testo2 = " persone"; string message_prim = " - USO PRIMS: " ;


// --------------------------------------------------- // don't change below // ---------------------------------------------------


string gridurl_error = "Owner didn't set the Gridurl key yet. Go to http://gridurl.appspot.com/random and copy the UUID that will be generated, then paste it at the begin of this script.";


string gridurl_indirizzo = "http://gridurl.appspot.com/go/"; string baseurl = "http://gridurl.appspot.com/reg?service=";

key mykey; string url; string query; key requestid; string title_sensor ; string message_sensor; string simname; string sensor_pos;

setup() {

   url = "";
   llRequestURL();

}


// risponde via HTTP send_response(key id, string body) {

   llHTTPResponse(id, 200, messaggio);

}


// 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"],
   "");    

}


// get current SLURL string slurl() {

   // il nome della regione:
   simname = llEscapeURL(llGetRegionName());    
   // le coordinate:
   vector detectedPos = llGetRootPosition();
   string sx = (string)llRound(detectedPos.x);
   string sy = (string)llRound(detectedPos.y);
   string sz = (string)llRound(detectedPos.z);
   // assemblaggio dello SLURL:
   string  url = "http://slurl.com/secondlife/";
   url += simname;
   url += "/" + sx + "/" + sy + "/" + sz;
   return url;

}


sensore() {

   llOwnerSay(simname);
   string prim_usage = message_prim + 
       owner1 + (string)llGetParcelPrimCount(parcel1, PARCEL_COUNT_TOTAL, FALSE) +
       "," + owner2 + (string)llGetParcelPrimCount(parcel2, PARCEL_COUNT_TOTAL, FALSE) +
       "," + owner3 + (string)llGetParcelPrimCount(parcel3, PARCEL_COUNT_TOTAL, FALSE) +
       "," + owner4 + (string)llGetParcelPrimCount(parcel4, PARCEL_COUNT_TOTAL, FALSE) + 
       ".";
                               
   string message_fps = " FPS: " + llGetSubString((string)(0.01*llRound(100*llGetRegionFPS())), 0, 4);
   string message_dil = " - DILATION: " + llGetSubString((string)(0.01*llRound(100*llGetRegionTimeDilation())), 0, 4); 
   string persone = (string)llGetRegionAgentCount();           
    string message_hostname = " - server: " + llGetSimulatorHostname(); 
    // you may want to disable this as it takes 10"
    // string message_hostname = "";


   title_sensor =
       simname +
       testo1 +
       persone +
       testo2; 
       
   message_sensor =
       message_fps +
       message_dil +
       prim_usage +
       message_prim +
       message_hostname +
       " - " + sensor_pos;
       
   messaggio = title_sensor + " - " + message_sensor;   

}


default {

   state_entry()
   {
       sensor_pos = slurl();                
       mykey = llGetOwner();            
       setup();  
       sensore();        
       llSetTimerEvent(intervallo);      
   }
   
   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;
           // DEBUG:            
           // llOwnerSay(" nuovo url = " + url);                   
           update_gridurl(url);            
       }
       
       else if (method == URL_REQUEST_DENIED)
       {
           llInstantMessage(mykey, "Something went wrong, no url. " + body);
       }
       // lo script e' stato richiamato (da un browser, cliccando su un link...)
       else if (method == "GET")
       {
   
               // DEBUG:
               // llInstantMessage(mykey, "query = " + query);       
   llHTTPResponse(id, 200, messaggio);
       }
       else
       {
           llHTTPResponse(id,405,"Unsupported method.");
       }
   }


// comunico gli URL dello script

   touch_start(integer total_number)
   {
       if(gridurl_key != "CHANGE-ME")
       {
           llInstantMessage(mykey, "Click to test: " 
           + gridurl_indirizzo
           + gridurl_key);
       }
       else
       {
           llInstantMessage(mykey, gridurl_error); 
       }
   }    
   
   
   
   timer()
   {
       sensore();
       //llOwnerSay(messaggio);
   }    
  

} <lsl>