Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key CORRADE;
- string PASSWORD;
- string GROUP;
- string URL = "";
- integer Debug = 1;
- integer prims = 10;
- integer count = 0;
- list primsUUID = [];
- integer line;
- list tuples = [];
- setDebug(string msg)
- {
- if(Debug == 1)
- {
- llOwnerSay("[CustomScript] " + msg);
- }
- }
- integer random_integer(integer min, integer max)
- {
- return min + (integer)(llFrand(max - min + 1));
- }
- string wasKeyValueGet(string k, string data)
- {
- if(llStringLength(data) == 0) return "";
- if(llStringLength(k) == 0) return "";
- list a = llParseStringKeepNulls(data, ["&", "="], []);
- integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
- if(i != -1) return llList2String(a, 2*i+1);
- return "";
- }
- string wasKeyValueEncode(list data)
- {
- list k = llList2ListStrided(data, 0, -1, 2);
- list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
- data = [];
- do
- {
- data += llList2String(k, 0) + "=" + llList2String(v, 0);
- k = llDeleteSubList(k, 0, 0);
- v = llDeleteSubList(v, 0, 0);
- } while(llGetListLength(k) != 0);
- return llDumpList2String(data, "&");
- }
- string wasURLEscape(string i)
- {
- string o = "";
- do
- {
- string c = llGetSubString(i, 0, 0);
- i = llDeleteSubString(i, 0, 0);
- if(c == "") jump continue;
- if(c == " ")
- {
- o += "+";
- jump continue;
- }
- if(c == "\n")
- {
- o += "%0D" + llEscapeURL(c);
- jump continue;
- }
- o += llEscapeURL(c);
- @continue;
- } while(i != "");
- return o;
- }
- string wasURLUnescape(string i)
- {
- return llUnescapeURL( llDumpList2String( llParseStringKeepNulls( llDumpList2String( llParseStringKeepNulls( i, ["+"], [] ), " " ), ["%0D%0A"], [] ), "\n" ) );
- }
- string wasListToCSV(list l)
- {
- list v = [];
- do
- {
- string a = llDumpList2String( llParseStringKeepNulls( llList2String( l, 0 ), ["\""], [] ), "\"\"" );
- if(llParseStringKeepNulls(a, [" ", ",", "\n", "\""], [] ) != (list) a ) a = "\"" + a + "\"";
- v += a;
- l = llDeleteSubList(l, 0, 0);
- } while(l != []);
- return llDumpList2String(v, ",");
- }
- list wasCSVToList(string csv)
- {
- list l = [];
- list s = [];
- string m = "";
- do
- {
- string a = llGetSubString(csv, 0, 0);
- csv = llDeleteSubString(csv, 0, 0);
- if(a == ",")
- {
- if(llList2String(s, -1) != "\"")
- {
- l += m;
- m = "";
- jump continue;
- }
- m += a;
- jump continue;
- }
- if(a == "\"" && llGetSubString(csv, 0, 0) == a)
- {
- m += a;
- csv = llDeleteSubString(csv, 0, 0);
- jump continue;
- }
- if(a == "\"")
- {
- if(llList2String(s, -1) != a)
- {
- s += a;
- jump continue;
- }
- s = llDeleteSubList(s, -1, -1);
- jump continue;
- }
- m += a;
- @continue;
- } while(csv != "");
- return l + m;
- }
- default
- {
- state_entry()
- {
- state ReadConfigurationNotecard;
- }
- }
- state ReadConfigurationNotecard
- {
- state_entry()
- {
- if(llGetInventoryType("configuration") != INVENTORY_NOTECARD)
- {
- setDebug("Sorry, could not find a configuration inventory notecard.");
- return;
- }
- setDebug("Reading configuration file...");
- line = 0;
- llGetNotecardLine("configuration", line);
- }
- dataserver(key id, string data)
- {
- if(data == EOF)
- {
- if(llGetListLength(tuples) % 2 != 0)
- {
- setDebug("Error in configuration notecard.");
- return;
- }
- CORRADE = llList2Key(tuples, llListFindList(tuples, ["BOTID"])+1);
- if(CORRADE == NULL_KEY)
- {
- setDebug("Error in configuration notecard: BOT ID KEY");
- return;
- }
- GROUP = llList2String(tuples, llListFindList(tuples,["GROUP"])+1);
- if(GROUP == "")
- {
- setDebug("Error in configuration notecard: GROUP");
- return;
- }
- PASSWORD = llList2String(tuples, llListFindList(tuples, ["PASSWORD"])+1);
- if(PASSWORD == "")
- {
- setDebug("Error in configuration notecard: PASSWORD");
- return;
- }
- state url;
- }
- if(data == "") jump continue;
- integer i = llSubStringIndex(data, "#");
- if(i != -1) data = llDeleteSubString(data, i, -1);
- list o = llParseStringKeepNulls(data, ["="], []);
- string k = llDumpList2String( llParseStringKeepNulls( llStringTrim( llList2String(o,0), STRING_TRIM), ["\""], []), "\"");
- string v = llDumpList2String( llParseStringKeepNulls( llStringTrim( llList2String( o, 1 ), STRING_TRIM), ["\""], [] ), "\"");
- if(k == "" || v == "") jump continue;
- tuples += k;
- tuples += v;
- @continue;
- llGetNotecardLine("configuration", ++line);
- }
- }
- state url
- {
- state_entry()
- {
- setDebug("Requesting URL...");
- llRequestURL();
- }
- http_request(key id, string method, string body)
- {
- if(method != URL_REQUEST_GRANTED) return;
- URL = body;
- setDebug("Got URL...");
- state StartupXFile;
- }
- }
- state StartupXFile
- {
- state_entry()
- {
- setDebug("Execute Startup File...");
- count = 0;
- llSay(0,(string)llGetTimestamp());
- llInstantMessage(CORRADE,
- wasKeyValueEncode(
- [
- "command", "createprimitive",
- "group", wasURLEscape(GROUP),
- "password", wasURLEscape(PASSWORD),
- "position", wasURLEscape((string)(<33,58,31>)),
- "type", "cube",
- "name", "ball100",
- "description", "bouncy",
- "data", wasListToCSV([
- "Material",
- "Glass"
- ]),
- "callback", wasURLEscape(URL)
- ]
- )
- );
- }
- http_request(key id, string method, string body)
- {
- llHTTPResponse(id, 200, "");
- llSay(0, body);
- llSay(0,(string)llGetTimestamp());
- count++;
- primsUUID += [wasKeyValueGet("data", body)];
- state adadsdd;
- }
- }
- state adadsdd
- {
- state_entry()
- {
- setDebug("Execute QQQQQQQQQQQQQ File...");
- llInstantMessage(CORRADE,
- wasKeyValueEncode(
- [
- // updates a script in a
- // primitive's inventory
- "command", "updatescript",
- "group", wasURLEscape(GROUP),
- "password", wasURLEscape(PASSWORD),
- // update a script in-world
- "type", "task",
- // the name or UUID of the
- // script in the primitive's
- // inventory.
- "target", "HelloWorld",
- // the name of the primitive
- // that contains the script...
- "item", "ball100",
- // ...in a 5m range
- "range", 100,
- // Update script source using a text entity.
- "entity", "text",
- "create", "true",
- // Base64 encoded script data
- "data", wasURLEscape(
- "default {
- state_entry() {
- llOwnerSay(\"Hello world!\");
- }
- }
- "),
- "callback", wasURLEscape(URL)
- ]
- )
- );
- //////////
- }
- http_request(key id, string method, string body)
- {
- llHTTPResponse(id, 200, "");
- llSay(0, body);
- }
- }
- ////////////////////////////////////
Add Comment
Please, Sign In to add comment