Difference between revisions of "Talk:LlGetWorldPopulation"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
Line 1: Line 1:
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
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


<lsl>
<source lang="lsl2">
key gConcurrencyRequest = NULL_KEY; // handle for http request
key gConcurrencyRequest = NULL_KEY; // handle for http request
string gStatsPage = "http://secondlife.com/httprequest/homepage.php";
string gStatsPage = "http://secondlife.com/httprequest/homepage.php";
Line 58: Line 58:
   
   
}
}
</lsl>
</source>
--[[User:Viktoria Dovgal|Tori]] 19:53, 18 March 2009 (UTC)
--[[User:Viktoria Dovgal|Tori]] 19:53, 18 March 2009 (UTC)

Latest revision as of 21:17, 15 February 2015

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)