Guest User

Untitled

a guest
May 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.76 KB | None | 0 0
  1. key CORRADE;
  2. string PASSWORD;
  3. string GROUP;
  4. string URL = "";
  5. integer Debug = 1;
  6.  
  7. integer prims = 10;
  8. integer count = 0;
  9. list primsUUID = [];
  10.  
  11. integer line;
  12. list tuples = [];
  13.  
  14. setDebug(string msg)
  15. {
  16.   if(Debug == 1)
  17.   {
  18.     llOwnerSay("[CustomScript] " + msg);
  19.   }
  20. }
  21.  
  22. integer random_integer(integer min, integer max)
  23. {
  24.     return min + (integer)(llFrand(max - min + 1));
  25. }
  26.  
  27. string wasKeyValueGet(string k, string data)
  28. {
  29.   if(llStringLength(data) == 0) return "";
  30.   if(llStringLength(k) == 0) return "";
  31.   list a = llParseStringKeepNulls(data, ["&", "="], []);
  32.   integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
  33.   if(i != -1) return llList2String(a, 2*i+1);
  34.   return "";
  35. }
  36.  
  37. string wasKeyValueEncode(list data)
  38. {
  39.   list k = llList2ListStrided(data, 0, -1, 2);
  40.   list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
  41.   data = [];
  42.   do
  43.   {
  44.     data += llList2String(k, 0) + "=" + llList2String(v, 0);
  45.     k = llDeleteSubList(k, 0, 0);
  46.     v = llDeleteSubList(v, 0, 0);
  47.   } while(llGetListLength(k) != 0);
  48.   return llDumpList2String(data, "&");
  49. }
  50.  
  51. string wasURLEscape(string i)
  52. {
  53.   string o = "";
  54.   do
  55.   {
  56.     string c = llGetSubString(i, 0, 0);
  57.     i = llDeleteSubString(i, 0, 0);
  58.     if(c == "") jump continue;
  59.     if(c == " ")
  60.     {
  61.       o += "+";
  62.       jump continue;
  63.     }
  64.     if(c == "\n")
  65.     {
  66.       o += "%0D" + llEscapeURL(c);
  67.       jump continue;
  68.     }
  69.     o += llEscapeURL(c);
  70. @continue;
  71.   } while(i != "");
  72.   return o;
  73. }
  74.  
  75. string wasURLUnescape(string i)
  76. {
  77.     return llUnescapeURL( llDumpList2String( llParseStringKeepNulls( llDumpList2String( llParseStringKeepNulls( i, ["+"], [] ), " " ), ["%0D%0A"], [] ), "\n" ) );
  78. }
  79.  
  80. string wasListToCSV(list l)
  81. {
  82.     list v = [];
  83.     do
  84.     {
  85.         string a = llDumpList2String( llParseStringKeepNulls( llList2String( l, 0 ), ["\""], [] ), "\"\"" );
  86.         if(llParseStringKeepNulls(a, [" ", ",", "\n", "\""], [] ) !=  (list) a ) a = "\"" + a + "\"";
  87.         v += a;
  88.         l = llDeleteSubList(l, 0, 0);
  89.     } while(l != []);
  90.     return llDumpList2String(v, ",");
  91. }
  92.  
  93. list wasCSVToList(string csv)
  94. {
  95.     list l = [];
  96.     list s = [];
  97.     string m = "";
  98.     do
  99.     {
  100.         string a = llGetSubString(csv, 0, 0);
  101.         csv = llDeleteSubString(csv, 0, 0);
  102.         if(a == ",")
  103.         {
  104.             if(llList2String(s, -1) != "\"")
  105.             {
  106.                 l += m;
  107.                 m = "";
  108.                 jump continue;
  109.             }
  110.             m += a;
  111.             jump continue;
  112.         }
  113.         if(a == "\"" && llGetSubString(csv, 0, 0) == a)
  114.         {
  115.             m += a;
  116.             csv = llDeleteSubString(csv, 0, 0);
  117.             jump continue;
  118.         }
  119.         if(a == "\"")
  120.         {
  121.             if(llList2String(s, -1) != a)
  122.             {
  123.                 s += a;
  124.                 jump continue;
  125.             }
  126.             s = llDeleteSubList(s, -1, -1);
  127.             jump continue;
  128.         }
  129.         m += a;
  130.         @continue;
  131.     } while(csv != "");
  132.     return l + m;
  133. }
  134.  
  135. default
  136. {
  137.     state_entry()
  138.     {
  139.         state ReadConfigurationNotecard;
  140.     }
  141. }
  142.  
  143. state ReadConfigurationNotecard
  144. {
  145.     state_entry()
  146.     {
  147.         if(llGetInventoryType("configuration") != INVENTORY_NOTECARD)
  148.         {
  149.             setDebug("Sorry, could not find a configuration inventory notecard.");
  150.             return;
  151.         }
  152.         setDebug("Reading configuration file...");
  153.         line = 0;
  154.         llGetNotecardLine("configuration", line);    
  155.     }
  156.    
  157.     dataserver(key id, string data)
  158.     {
  159.         if(data == EOF)
  160.         {
  161.             if(llGetListLength(tuples) % 2 != 0)
  162.             {
  163.                 setDebug("Error in configuration notecard.");
  164.                 return;
  165.             }
  166.  
  167.             CORRADE = llList2Key(tuples, llListFindList(tuples, ["BOTID"])+1);
  168.            
  169.             if(CORRADE == NULL_KEY)
  170.             {
  171.                 setDebug("Error in configuration notecard: BOT ID KEY");
  172.                 return;
  173.             }            
  174.            
  175.             GROUP = llList2String(tuples, llListFindList(tuples,["GROUP"])+1);
  176.  
  177.             if(GROUP == "")
  178.             {
  179.                 setDebug("Error in configuration notecard: GROUP");
  180.                 return;
  181.             }
  182.            
  183.             PASSWORD = llList2String(tuples, llListFindList(tuples, ["PASSWORD"])+1);
  184.            
  185.             if(PASSWORD == "")
  186.             {
  187.                 setDebug("Error in configuration notecard: PASSWORD");
  188.                 return;
  189.             }
  190.                  
  191.             state url;
  192.         }
  193.         if(data == "") jump continue;
  194.         integer i = llSubStringIndex(data, "#");
  195.         if(i != -1) data = llDeleteSubString(data, i, -1);
  196.         list o = llParseStringKeepNulls(data, ["="], []);
  197.         string k = llDumpList2String( llParseStringKeepNulls( llStringTrim( llList2String(o,0), STRING_TRIM), ["\""], []), "\"");
  198.         string v = llDumpList2String( llParseStringKeepNulls( llStringTrim( llList2String( o, 1 ), STRING_TRIM), ["\""], [] ), "\"");
  199.         if(k == "" || v == "") jump continue;
  200.         tuples += k;
  201.         tuples += v;
  202.         @continue;
  203.         llGetNotecardLine("configuration", ++line);
  204.     }    
  205. }
  206.  
  207. state url
  208. {
  209.     state_entry()
  210.     {
  211.         setDebug("Requesting URL...");
  212.         llRequestURL();
  213.     }
  214.     http_request(key id, string method, string body)
  215.     {
  216.         if(method != URL_REQUEST_GRANTED) return;
  217.         URL = body;
  218.         setDebug("Got URL...");
  219.         state StartupXFile;
  220.     }
  221. }
  222.  
  223.  
  224. state StartupXFile
  225. {
  226.     state_entry()
  227.     {
  228.        
  229.         setDebug("Execute Startup File...");
  230.           count = 0;
  231. llSay(0,(string)llGetTimestamp());
  232.  
  233. llInstantMessage(CORRADE,
  234.     wasKeyValueEncode(
  235.     [
  236.         "command", "createprimitive",
  237.         "group", wasURLEscape(GROUP),
  238.         "password", wasURLEscape(PASSWORD),
  239.         "position", wasURLEscape((string)(<33,58,31>)),
  240.         "type", "cube",
  241.         "name", "ball100",
  242.         "description", "bouncy",
  243.         "data", wasListToCSV([
  244.         "Material",
  245.         "Glass"
  246.         ]),
  247.         "callback", wasURLEscape(URL)
  248.     ]
  249.     )
  250. );
  251.  
  252.  
  253.     }
  254.  
  255.     http_request(key id, string method, string body)
  256.     {
  257.         llHTTPResponse(id, 200, "");
  258.         llSay(0, body);
  259.         llSay(0,(string)llGetTimestamp());
  260.         count++;
  261.         primsUUID += [wasKeyValueGet("data", body)];
  262.  
  263.        
  264.             state adadsdd;
  265.  
  266.     }
  267.  
  268. }
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. state adadsdd
  277. {
  278.     state_entry()
  279.     {
  280.        
  281.         setDebug("Execute QQQQQQQQQQQQQ File...");
  282.        
  283. llInstantMessage(CORRADE,
  284.     wasKeyValueEncode(
  285.         [
  286.             // updates a script in a
  287.             // primitive's inventory
  288.             "command", "updatescript",
  289.             "group", wasURLEscape(GROUP),
  290.             "password", wasURLEscape(PASSWORD),
  291.             // update a script in-world
  292.             "type", "task",
  293.             // the name or UUID of the
  294.             // script in the primitive's
  295.             // inventory.
  296.             "target", "HelloWorld",
  297.             // the name of the primitive
  298.             // that contains the script...
  299.             "item", "ball100",
  300.             // ...in a 5m range
  301.             "range", 100,
  302.             // Update script source using a text entity.
  303.             "entity", "text",
  304.             "create", "true",
  305.             // Base64 encoded script data
  306.             "data", wasURLEscape(
  307. "default {
  308.   state_entry() {
  309.       llOwnerSay(\"Hello world!\");
  310.   }
  311. }
  312. "),
  313.  
  314.         "callback", wasURLEscape(URL)
  315.         ]
  316.     )
  317. );
  318. //////////
  319.  
  320.     }
  321.  
  322.     http_request(key id, string method, string body)
  323.     {
  324.         llHTTPResponse(id, 200, "");
  325.         llSay(0, body);
  326.  
  327.     }
  328.  
  329. }
  330.  
  331. ////////////////////////////////////
Add Comment
Please, Sign In to add comment