Talk:LlGetWorldPopulation

From Second Life Wiki
Revision as of 12:53, 18 March 2009 by Viktoria Dovgal (talk | contribs) (info is available now, just a little yucky to retrieve)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Just a quicky example of how to get concurrency with existing tools. For other formats and feeds, see https://blogs.secondlife.com/community/features/blog/2006/10/03/new-data-feeds-1

<lsl> key gConcurrencyRequest = NULL_KEY; // handle for http request string gStatsPage = "http://secondlife.com/httprequest/homepage.php"; integer gPeakConcurrency = 0; // highest count we've seen since reset

default {

   state_entry() {
       // Concurrency is updated every 3 minutes, so there's no urge to check
       // more often.
       llSetTimerEvent(180.);

       // Go get fresh stats from the web
       gConcurrencyRequest = llHTTPRequest(gStatsPage, [], "");
   }


   timer() {
       // Go get fresh stats from the web
       gConcurrencyRequest = llHTTPRequest(gStatsPage, [], "");
   }


   http_response(key request_id, integer status, list metadata, string body) {
       if (request_id == gConcurrencyRequest) {
           // If the web server is acting up, silently give up.
           if (status != 200) {
               return;
           }
           list stats = llParseString2List(body, ["\n"], []);
           integer inworldIndex = llListFindList(stats, ["inworld"]);
           // page format seems to be be broken, silently give up.
           if (inworldIndex == -1) {
               return;
           }
           
           integer concurrency = (integer) llList2String(stats, inworldIndex + 1);
           
           // update high mark
           if (gPeakConcurrency < concurrency) {
               gPeakConcurrency = concurrency;
           }
           // update the prim text with the last concurrency seen
           llSetText(
               "Online now: " + (string)concurrency
                   + "\nMost seen: " + (string)gPeakConcurrency,
               <1.0, 1.0, 1.0>,
               1.0
           );
       }
   }

} </lsl> --Tori 19:53, 18 March 2009 (UTC)