corrade-lsl-templates – Diff between revs 41 and 42

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 41 Rev 42
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // An eggdrop-like group bot using Corrade. 5 // An eggdrop-like group bot using Corrade.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
Line 17... Line 17...
17 if(i != -1) return llList2String(a, 2*i+1); 17 if(i != -1) return llList2String(a, 2*i+1);
18 return ""; 18 return "";
19 } 19 }
Line 20... Line 20...
20 20  
21 /////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////
-   22 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 //
-   23 ///////////////////////////////////////////////////////////////////////////
-   24 string wasKeyValueDelete(string k, string data) {
-   25 if(llStringLength(data) == 0) return "";
-   26 if(llStringLength(k) == 0) return "";
-   27 integer i = llListFindList(
-   28 llList2ListStrided(
-   29 llParseString2List(data, ["&", "="], []),
-   30 0, -1, 2
-   31 ),
-   32 [ k ]);
-   33 if(i != -1) return llDumpList2String(
-   34 llDeleteSubList(
-   35 llParseString2List(data, ["&"], []),
-   36 i, i),
-   37 "&");
-   38 return data;
-   39 }
-   40  
-   41 ///////////////////////////////////////////////////////////////////////////
-   42 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 //
-   43 ///////////////////////////////////////////////////////////////////////////
-   44 string wasKeyValueSet(string k, string v, string data) {
-   45 if(llStringLength(k) == 0) return "";
-   46 if(llStringLength(v) == 0) return "";
-   47 if(llStringLength(data) == 0) return k + "=" + v;
-   48 integer i = llListFindList(
-   49 llList2ListStrided(
-   50 llParseString2List(data, ["&", "="], []),
-   51 0, -1, 2
-   52 ),
-   53 [ k ]);
-   54 if(i != -1) return llDumpList2String(
-   55 llListReplaceList(
-   56 llParseString2List(data, ["&"], []),
-   57 [ k + "=" + v ],
-   58 i, i),
-   59 "&");
-   60 return data + "&" + k + "=" + v;
-   61 }
-   62  
-   63 ///////////////////////////////////////////////////////////////////////////
22 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 64 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
23 /////////////////////////////////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////////////
24 string wasKeyValueEncode(list data) { 66 string wasKeyValueEncode(list data) {
25 list k = llList2ListStrided(data, 0, -1, 2); 67 list k = llList2ListStrided(data, 0, -1, 2);
26 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 68 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
Line 32... Line 74...
32 } while(llGetListLength(k) != 0); 74 } while(llGetListLength(k) != 0);
33 return llDumpList2String(data, "&"); 75 return llDumpList2String(data, "&");
34 } 76 }
Line 35... Line 77...
35   77  
36 /////////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////////
37 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 79 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
38 /////////////////////////////////////////////////////////////////////////// 80 ///////////////////////////////////////////////////////////////////////////
39 // escapes a string in conformance with RFC1738 81 // escapes a string in conformance with RFC1738
40 string wasURLEscape(string i) { 82 string wasURLEscape(string i) {
41 string o = ""; 83 string o = "";
Line 56... Line 98...
56 } while(i != ""); 98 } while(i != "");
57 return o; 99 return o;
58 } 100 }
Line 59... Line 101...
59   101  
60 /////////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////////
61 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 103 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
62 /////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////
63 // unescapes a string in conformance with RFC1738 105 // unescapes a string in conformance with RFC1738
64 string wasURLUnescape(string i) { 106 string wasURLUnescape(string i) {
65 return llUnescapeURL( 107 return llUnescapeURL(
Line 80... Line 122...
80 ) 122 )
81 ); 123 );
82 } 124 }
Line 83... Line 125...
83   125  
84 /////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////
85 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 127 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
86 /////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////
87 string wasListToCSV(list l) { 129 string wasListToCSV(list l) {
88 list v = []; 130 list v = [];
89 do { 131 do {
Line 108... Line 150...
108 l = llDeleteSubList(l, 0, 0); 150 l = llDeleteSubList(l, 0, 0);
109 } while(l != []); 151 } while(l != []);
110 return llDumpList2String(v, ","); 152 return llDumpList2String(v, ",");
111 } 153 }
Line -... Line 154...
-   154  
-   155 ///////////////////////////////////////////////////////////////////////////
-   156 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
-   157 ///////////////////////////////////////////////////////////////////////////
-   158 list wasCSVToList(string csv) {
-   159 list l = [];
-   160 list s = [];
-   161 string m = "";
-   162 do {
-   163 string a = llGetSubString(csv, 0, 0);
-   164 csv = llDeleteSubString(csv, 0, 0);
-   165 if(a == ",") {
-   166 if(llList2String(s, -1) != "\"") {
-   167 l += m;
-   168 m = "";
-   169 jump continue;
-   170 }
-   171 m += a;
-   172 jump continue;
-   173 }
-   174 if(a == "\"" && llGetSubString(csv, 0, 0) == a) {
-   175 m += a;
-   176 csv = llDeleteSubString(csv, 0, 0);
-   177 jump continue;
-   178 }
-   179 if(a == "\"") {
-   180 if(llList2String(s, -1) != a) {
-   181 s += a;
-   182 jump continue;
-   183 }
-   184 s = llDeleteSubList(s, -1, -1);
-   185 jump continue;
-   186 }
-   187 m += a;
-   188 @continue;
-   189 } while(csv != "");
-   190 // postcondition: length(s) = 0
-   191 return l + m;
-   192 }
112   193  
113 // for notecard reading 194 // for notecard reading
Line 114... Line 195...
114 integer line = 0; 195 integer line = 0;
115 196  
Line 199... Line 280...
199 // GC 280 // GC
200 tuples = []; 281 tuples = [];
201 state request_url_notifications; 282 state request_url_notifications;
202 } 283 }
203 if(data == "") jump continue; 284 if(data == "") jump continue;
-   285 // No support for inline comments for this one! Needs parsing!
204 integer i = llSubStringIndex(data, "#"); 286 integer i = llSubStringIndex(data, "#");
205 if(i != -1) data = llDeleteSubString(data, i, -1); 287 if(i == 0) data = llDeleteSubString(data, i, -1);
206 list o = llParseString2List(data, ["="], []); 288 list o = llParseString2List(data, ["="], []);
207 // get rid of starting and ending quotes 289 // get rid of starting and ending quotes
208 string k = llDumpList2String( 290 string k = llDumpList2String(
209 llParseString2List( 291 llParseString2List(
210 llStringTrim( 292 llStringTrim(
Line 392... Line 474...
392 wasKeyValueGet("error", body) 474 wasKeyValueGet("error", body)
393 ) 475 )
394 ); 476 );
395 llResetScript(); 477 llResetScript();
396 } 478 }
397 state serve_configuration; 479 state version_check;
398 } 480 }
399 timer() { 481 timer() {
400 llOwnerSay("[Control] Timeout binding notifications"); 482 llOwnerSay("[Control] Timeout binding notifications");
401 llResetScript(); 483 llResetScript();
402 } 484 }
Line 413... Line 495...
413 state_exit() { 495 state_exit() {
414 llSetTimerEvent(0); 496 llSetTimerEvent(0);
415 } 497 }
416 } 498 }
Line 417... Line 499...
417   499  
418 state serve_configuration { 500 state version_check {
419 state_entry() { 501 state_entry() {
420 // DEBUG 502 // DEBUG
421 llOwnerSay("[Control] Checking version..."); 503 llOwnerSay("[Control] Checking version...");
422 llInstantMessage( 504 llInstantMessage(
Line 446... Line 528...
446 llSetTimerEvent(60); 528 llSetTimerEvent(60);
447 } 529 }
448 http_request(key id, string method, string body) { 530 http_request(key id, string method, string body) {
449 llHTTPResponse(id, 200, "OK"); 531 llHTTPResponse(id, 200, "OK");
450 llSetTimerEvent(0); 532 llSetTimerEvent(0);
451 if(wasKeyValueGet("command", body) != "version") { -  
452 llMessageLinked(LINK_THIS, 0, body, "notification"); -  
453 return; -  
454 } -  
Line 455... Line 533...
455 533  
456 if(wasKeyValueGet("success", body) != "True") { 534 if(wasKeyValueGet("success", body) != "True") {
457 llOwnerSay("[Control] Version check failed..."); 535 llOwnerSay("[Control] Version check failed...");
458 return; 536 return;
Line 483... Line 561...
483 configuration 561 configuration
484 ) + 562 ) +
485 " for this template." 563 " for this template."
486 ); 564 );
487 compatible = FALSE; 565 compatible = FALSE;
488 //llReleaseURL(URL); -  
489 return; 566 return;
490 } 567 }
-   568  
-   569 // Add the URL to the configuration so it can be used for all components.
-   570 configuration = wasKeyValueSet("URL", URL, configuration);
-   571  
491 // DEBUG 572 // DEBUG
492 llOwnerSay("[Control] Version is compatible!"); 573 llOwnerSay("[Control] Version is compatible!");
493 compatible = TRUE; 574 compatible = TRUE;
-   575  
-   576 state serve_configuration;
-   577 }
-   578 timer() {
-   579 llOwnerSay("[Control] Timeout checking version...");
494 //llReleaseURL(URL); 580 llResetScript();
-   581 }
-   582 on_rez(integer num) {
-   583 llResetScript();
-   584 }
-   585 changed(integer change) {
-   586 if((change & CHANGED_INVENTORY) ||
-   587 (change & CHANGED_REGION_START) ||
-   588 (change & CHANGED_OWNER)) {
-   589 llResetScript();
-   590 }
-   591 }
-   592 state_exit() {
-   593 llSetTimerEvent(0);
-   594 }
-   595 }
-   596  
-   597 state serve_configuration {
-   598 state_entry() {
-   599 // DEBUG
-   600 llOwnerSay("[Control] Serving configuration and passing callbacks...");
-   601 }
-   602 http_request(key id, string method, string body) {
-   603 llHTTPResponse(id, 200, "OK");
-   604  
-   605 if(wasKeyValueGet("command", body) != "") {
-   606 llMessageLinked(LINK_THIS, 0, body, "callback");
495 return; 607 return;
496 } 608 }
-   609  
-   610 // Check if this group message is from Corrade and passed through Discord.
-   611 if(wasKeyValueGet("type", body) == "group" &&
-   612 llToUpper(wasKeyValueGet("agent", body)) == llToUpper(wasKeyValueGet("corrade", configuration)) &&
-   613 llSubStringIndex(wasURLUnescape(wasKeyValueGet("message", body)), "[Discord]:") != -1) {
-   614  
-   615 // Split message in Discord discriminator and message body.
-   616 list messageSplit = llParseString2List(
-   617 wasURLUnescape(
-   618 wasKeyValueGet("message", body)
-   619 ),
-   620 ["[Discord]:"],
-   621 []
-   622 );
-   623  
-   624 // Retrive the Discord discriminator.
-   625 string did = llStringTrim(
-   626 llList2String(
-   627 messageSplit,
-   628 0
-   629 ),
-   630 STRING_TRIM
-   631 );
-   632  
-   633  
-   634 // Retrieve a list of Discord discriminator that are allowed to send administrative commands.
-   635 list admins = wasCSVToList(wasKeyValueGet("discord admin", configuration));
-   636  
-   637 // If the sender is not amongst the administrative Discord discriminators, then strip the agent details.
-   638 if(llListFindList(admins, [ did ]) == -1) {
-   639 // DEBUG
-   640 llOwnerSay("[Control] Non admin, issuing command, strip the agent details from the command.");
-   641  
-   642 body = wasKeyValueDelete("firstname", body);
-   643 body = wasKeyValueDelete("lastname", body);
-   644 body = wasKeyValueDelete("agent", body);
-   645 }
-   646  
-   647 // Pack the message back without the Discord discriminator identifier.
-   648 body = wasKeyValueSet(
-   649 "message",
-   650 wasURLEscape(
-   651 llStringTrim(
-   652 llList2String(
-   653 messageSplit,
-   654 1
-   655 ),
-   656 STRING_TRIM
-   657 )
-   658 ),
-   659 body
-   660 );
-   661 }
-   662  
-   663 llMessageLinked(LINK_THIS, 0, body, "notification");
-   664 }
497 link_message(integer sender, integer num, string message, key id) { 665 link_message(integer sender, integer num, string message, key id) {
498 if(message != "configuration") return; 666 if(message != "configuration") return;
-   667  
499 llMessageLinked(LINK_THIS, 0, configuration, "configuration"); 668 llMessageLinked(LINK_THIS, 0, configuration, "configuration");
500 } 669 }
501 timer() { -  
502 llOwnerSay("[Control] Timeout checking version..."); -  
503 llResetScript(); -  
504 } -  
505 on_rez(integer num) { 670 on_rez(integer num) {
506 llResetScript(); 671 llResetScript();
507 } 672 }
508 changed(integer change) { 673 changed(integer change) {
509 if((change & CHANGED_INVENTORY) || 674 if((change & CHANGED_INVENTORY) ||