User:Opensource Obscure/AvatarsUnited/SimStats

From Second Life Wiki
Jump to navigation Jump to search

Go back to Opensource Obscure's userpage



UPDATE: AVATARS UNITED IS NO MORE SO THIS PAGE IS USELESS

this is a work in progress. I'm new to Avatars United. I'm not a real programmer. Contact me (Opensource Obscure) in-world for more info.
Se sei italiano, guarda qui.

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).

Note: I didn't published this gadget to Avatars United yet, but I created it. I think this is the reason I can see this application in my AU Profile page, but nobody else can. To make it public I guess it should be submitted to AU, and then it could be used by everybody. However, this is a sort of private application - I'm not providing a service. Feel free to make what you want of this stuff - JUST PLEASE LET ME KNOW IT and share your improvements with me ;)

Here's how it will appear in your AU page: Aulolmonitor.jpg

To re-create this application you will need:

  • an AU developer account
  • land permissions (details needed - to do)
  • Linux-based web hosting for your gadget (a few kbytes, but you will also need both Crontab and Bash scripts support). You may obviously use other solutions. What you need to do is
    • hosting an XML file
    • periodically query an URL
    • parse the response to get in-world data
    • periodically update the XML file with fresh data

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)
    1. you can get a free copy of the sensor at my LOL region: http://slurl.com/secondlife/LOL/81/49/22
  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

FIX ME: There's a bug and prim usage doesn't show up --oobscure 23:31, 31 January 2010 (UTC)

<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>