Advertisement
salahzar

query scores

Mar 18th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This is free and unencumbered software released into the public domain.
  3.  
  4. Anyone is free to copy, modify, publish, use, compile, sell, or
  5. distribute this software, either in source code form or as a compiled
  6. binary, for any purpose, commercial or non-commercial, and by any
  7. means.
  8.  
  9. Originally written by Salahzar Stenvaag for OpenSim, on March 2016
  10. See http://pastebin.com/Z4m9J5Se for related google app application
  11. */
  12.  
  13. string URL = "http://edmondo-1252.appspot.com/?";
  14. string SESSION = "1";
  15. //////////////////////////////////////////////
  16. key handle;
  17.  
  18. //////////////////////////////////////////////
  19. integer SLEEP = 5;
  20. integer TIMER = 10;
  21.  
  22. debug(string s) {
  23.     // uncomment next line to have some debug
  24.     //llOwnerSay("DEBUG:"+s);
  25. }
  26.  
  27. /***********************************************************
  28.  * Show the string in parameter line on row numbered row
  29.  ***********************************************************/
  30. show(integer row, string line) {
  31.     llMessageLinked(LINK_SET,(row+1)*1000,line,NULL_KEY);
  32. }
  33.  
  34. /***********************************************************
  35.  * Clear the whiteboard
  36.  ***********************************************************/
  37. clear() {
  38.     debug("clearing");
  39.     integer i;
  40.     for(i=0;i<20;i++) {
  41.         show(i,"");
  42.     }
  43. }
  44. /***********************************************************
  45.  * Ask server to display list for session
  46.  ***********************************************************/
  47. httprequest() {
  48.     debug("httprequest");
  49.     string url = URL + "type=list&session="+SESSION;
  50.     list parm = [ HTTP_MIMETYPE, "text/plain; charset=UTF-8",
  51.             HTTP_BODY_MAXLENGTH, 32000 ];
  52.     string body = "";
  53.     handle = llHTTPRequest(url, parm, body);
  54. }
  55.  
  56. string SPACES = "                           ";
  57. string POINTS = "...........................";
  58. /***********************************************************
  59.  * Formatting a string in a field with max len columns,
  60.  * formatType can be "L" for left formatting, "R" for right
  61.  * You can use previous SPACES or POINTS constants to specify
  62.  * characters to be used for padding
  63.  ***********************************************************/
  64. string format(string str,integer len,string formatType,string padding) {
  65.     integer strlen = llStringLength(str);
  66.     if(strlen>=len) return llGetSubString(str,0,len-1);
  67.     if(formatType == "L") {
  68.         return str + llGetSubString(padding, 0,len - strlen - 1);
  69.     } else {
  70.         return  llGetSubString(padding, 0,len - strlen - 1) + str;
  71.     }
  72.    
  73. }
  74.  
  75. // not used unless you want to enable a toggling mechanism when touch
  76. integer toggle = 0;
  77.  
  78. default
  79. {
  80.     state_entry() {
  81.         /* Use this if you want to get SESSION from the object description
  82.         SESSION = llGetObjectDesc();
  83.         list parsing = llParseStringKeepNulls(SESSION,[":"],[]);
  84.         SESSION = llStringTrim(llList2String(parsing,1),STRING_TRIM); */
  85.         //llSay(0,"Setting SESSION: "+SESSION);
  86.        
  87.         clear();
  88.        
  89.         // if NOT TOGGLE be sure not to have any text
  90.         llSetText("",<1,1,1>,1);
  91.         //TOGGLE llSetText("Off",<1,1,1>,1);
  92.        
  93.     }
  94.    
  95.     touch_start(integer count) {
  96.         /* TOGGLE HANDLING
  97.         toggle = 1 - toggle;
  98.         if( toggle == 0 ) {
  99.             clear();
  100.             llSetText("Off",<1,1,1>,1);
  101.             llSetTimerEvent(0);
  102.         } else {
  103.             llSetTimerEvent(0.1);
  104.             llSetText(" ",<1,1,1>,1);
  105.            
  106.         } */
  107.         // if not toggle touch is producing a refresh
  108.         httprequest();
  109.        
  110.     }
  111.     /* TOGGLE
  112.     timer() {
  113.         httprequest();
  114.         llSetTimerEvent(TIMER);
  115.     } */
  116.    
  117.     // evaluate response from server
  118.     http_response(key k, integer status, list meta, string body) {
  119.         // be sure to answer to only our request
  120.         if(k != handle) return;
  121.        
  122.         debug("status: "+(string)status);
  123.         debug("body: "+body);
  124.         clear();
  125.        
  126.         // parse result in various lines separated by CR
  127.         list lines = llParseStringKeepNulls(body,["\n"],[]);
  128.         integer i;
  129.         for(i=0;i<llGetListLength(lines);i++){
  130.            
  131.             // for each line parse it separating with ","
  132.             string line = llList2String(lines,i);
  133.             debug("Line: "+line);
  134.             list array = llParseStringKeepNulls(line,[","],[]);
  135.            
  136.             // amd get name and score
  137.             string name = llList2String(array,0);
  138.             string score = llList2String(array,1);
  139.            
  140.             // show them on the board
  141.             show(i,format(score,4,"R",SPACES) + " " + format(name,30,"L",SPACES));
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement