Talk:LlGetWorldPopulation

From Second Life Wiki
Jump to: navigation, search

Just a quicky example of how to get concurrency with existing tools. For other formats and feeds, see http://community.secondlife.com/t5/Features/New-Data-Feeds-1/ba-p/525446

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
            );
        }
    }
 
}

--Tori 19:53, 18 March 2009 (UTC)