Advertisement
LethBaumann

Online Now - Borked

Oct 15th, 2018
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. key gConcurrencyRequest = NULL_KEY; // handle for http request
  2. string gStatsPage = "http://secondlife.com/httprequest/homepage.php";
  3. integer gPeakConcurrency = 0; // highest count we've seen since reset
  4.  
  5. default
  6. {
  7.     state_entry() {
  8.         // Concurrency is updated every 3 minutes, so there's no urge to check
  9.         // more often.
  10.         llSetTimerEvent(180.);
  11.  
  12.         // Go get fresh stats from the web
  13.         gConcurrencyRequest = llHTTPRequest(gStatsPage, [], "");
  14.     }
  15.  
  16.  
  17.     timer() {
  18.         // Go get fresh stats from the web
  19.         gConcurrencyRequest = llHTTPRequest(gStatsPage, [], "");
  20.     }
  21.  
  22.  
  23.     http_response(key request_id, integer status, list metadata, string body) {
  24.         if (request_id == gConcurrencyRequest) {
  25.  
  26.             // If the web server is acting up, silently give up.
  27.             if (status != 200) {
  28.                 return;
  29.             }
  30.  
  31.             list stats = llParseString2List(body, ["\n"], []);
  32.             integer inworldIndex = llListFindList(stats, ["inworld"]);
  33.  
  34.             // page format seems to be be broken, silently give up.
  35.             if (inworldIndex == -1) {
  36.                 return;
  37.             }
  38.  
  39.             integer concurrency = (integer) llList2String(stats, inworldIndex + 1);
  40.  
  41.             // update high mark
  42.             if (gPeakConcurrency < concurrency) {
  43.                 gPeakConcurrency = concurrency;
  44.             }
  45.  
  46.             // update the prim text with the last concurrency seen
  47.             llSetText(
  48.                 "Online now: " + (string)concurrency
  49.                     + "\nMost seen: " + (string)gPeakConcurrency,
  50.                 <1.0, 1.0, 1.0>,
  51.                 1.0
  52.             );
  53.         }
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement