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 // A wiki module that can memorize strings and recall them by path. 5 // A wiki module that can memorize strings and recall them by path.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
Line 8... Line 8...
8   8  
9 /////////////////////////////////////////////////////////////////////////// 9 ///////////////////////////////////////////////////////////////////////////
10 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 // 10 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
11 /////////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////////
12 integer wasIsAlNum(string a) { 12 integer wasIsAlNum(string a) {
13 if(a == "") return FALSE; 13 if(a == "") return FALSE;
14 integer x = llBase64ToInteger("AAAA" + 14 integer x = llBase64ToInteger("AAAA" +
Line 28... Line 28...
28 if(i != -1) return llList2String(a, 2*i+1); 28 if(i != -1) return llList2String(a, 2*i+1);
29 return ""; 29 return "";
30 } 30 }
Line 31... Line 31...
31 31  
32 /////////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////////
33 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 33 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
34 /////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////
35 string wasKeyValueEncode(list data) { 35 string wasKeyValueEncode(list data) {
36 list k = llList2ListStrided(data, 0, -1, 2); 36 list k = llList2ListStrided(data, 0, -1, 2);
37 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 37 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
Line 43... Line 43...
43 } while(llGetListLength(k) != 0); 43 } while(llGetListLength(k) != 0);
44 return llDumpList2String(data, "&"); 44 return llDumpList2String(data, "&");
45 } 45 }
Line 46... Line 46...
46   46  
47 /////////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////////
48 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 48 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
49 /////////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////////
50 // escapes a string in conformance with RFC1738 50 // escapes a string in conformance with RFC1738
51 string wasURLEscape(string i) { 51 string wasURLEscape(string i) {
52 string o = ""; 52 string o = "";
Line 67... Line 67...
67 } while(i != ""); 67 } while(i != "");
68 return o; 68 return o;
69 } 69 }
Line 70... Line 70...
70   70  
71 /////////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////////
72 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 72 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
73 /////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////
74 list wasCSVToList(string csv) { 74 list wasCSVToList(string csv) {
75 list l = []; 75 list l = [];
76 list s = []; 76 list s = [];
Line 106... Line 106...
106 // postcondition: length(s) = 0 106 // postcondition: length(s) = 0
107 return l + m; 107 return l + m;
108 } 108 }
Line 109... Line 109...
109   109  
110 /////////////////////////////////////////////////////////////////////////// 110 ///////////////////////////////////////////////////////////////////////////
111 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 111 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
112 /////////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////
113 string wasListToCSV(list l) { 113 string wasListToCSV(list l) {
114 list v = []; 114 list v = [];
115 do { 115 do {
Line 135... Line 135...
135 } while(l != []); 135 } while(l != []);
136 return llDumpList2String(v, ","); 136 return llDumpList2String(v, ",");
137 } 137 }
Line 138... Line 138...
138   138  
139 /////////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////////
140 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 140 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
141 /////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////
142 // unescapes a string in conformance with RFC1738 142 // unescapes a string in conformance with RFC1738
143 string wasURLUnescape(string i) { 143 string wasURLUnescape(string i) {
144 return llUnescapeURL( 144 return llUnescapeURL(
Line 160... Line 160...
160 ); 160 );
161 } 161 }
Line 162... Line 162...
162   162  
163 // configuration data 163 // configuration data
164 string configuration = ""; -  
165 // callback URL -  
166 string URL = ""; 164 string configuration = "";
167 // store message over state. 165 // store message over state.
168 string path = ""; 166 string path = "";
169 string data = ""; 167 string data = "";
170 string action = ""; 168 string action = "";
Line 179... Line 177...
179 link_message(integer sender, integer num, string message, key id) { 177 link_message(integer sender, integer num, string message, key id) {
180 if(id != "configuration") return; 178 if(id != "configuration") return;
181 llOwnerSay("[Wiki] Got configuration..."); 179 llOwnerSay("[Wiki] Got configuration...");
182 configuration = message; 180 configuration = message;
183 action = "create"; 181 action = "create";
184 state url; 182 state trampoline;
185 } 183 }
186 timer() { 184 timer() {
187 llOwnerSay("[Wiki] Requesting configuration..."); 185 llOwnerSay("[Wiki] Requesting configuration...");
188 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 186 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
189 } 187 }
Line 200... Line 198...
200 state_exit() { 198 state_exit() {
201 llSetTimerEvent(0); 199 llSetTimerEvent(0);
202 } 200 }
203 } 201 }
Line 204... Line 202...
204   202  
205 state url { 203 state trampoline {
206 state_entry() { -  
207 // DEBUG -  
208 llOwnerSay("[Wiki] Requesting URL..."); -  
209 llRequestURL(); -  
210 } -  
211 http_request(key id, string method, string body) { -  
212 if(method != URL_REQUEST_GRANTED) return; -  
213 URL = body; -  
214 // DEBUG -  
215 llOwnerSay("[Wiki] Got URL."); -  
216 204 state_entry() {
217 if(action == "create") { 205 if(action == "create") {
218 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 206 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
219 wasKeyValueGet("wiki table", configuration) + 207 wasKeyValueGet("wiki table", configuration) +
220 "\" (path text unique collate nocase, data text)"); 208 "\" (path text unique collate nocase, data text)");
Line 358... Line 346...
358 // We only care about notifications now. 346 // We only care about notifications now.
359 if(id != "notification") 347 if(id != "notification")
360 return; 348 return;
Line 361... Line 349...
361 349  
362 // This script only processes group notifications. 350 // This script only processes group notifications.
-   351 if(wasKeyValueGet("type", message) != "group" ||
-   352 (wasKeyValueGet("type", message) == "group" &&
-   353 wasURLUnescape(wasKeyValueGet("group", message)) !=
363 if(wasKeyValueGet("type", message) != "group") 354 wasKeyValueGet("group", configuration)))
Line 364... Line 355...
364 return; 355 return;
365 356  
366 // Get the sent message. 357 // Get the sent message.
Line 431... Line 422...
431 command = llDeleteSubList(command, 0, 0); 422 command = llDeleteSubList(command, 0, 0);
Line 432... Line 423...
432 423  
433 // Dump the rest of the message. 424 // Dump the rest of the message.
Line 434... Line -...
434 data = llDumpList2String(command, " "); -  
435 425 data = llDumpList2String(command, " ");
436 // Get an URL. 426  
437 state url; 427 state trampoline;
438 } 428 }
439 on_rez(integer num) { 429 on_rez(integer num) {
440 llResetScript(); 430 llResetScript();
Line 466... Line 456...
466 configuration 456 configuration
467 ) 457 )
468 ), 458 ),
469 "SQL", statement, 459 "SQL", statement,
470 "data", parameters, 460 "data", parameters,
471 "callback", wasURLEscape(URL) 461 "callback", wasURLEscape(
-   462 wasKeyValueGet(
-   463 "URL",
-   464 configuration
-   465 )
-   466 )
472 ] 467 ]
473 ); 468 );
-   469  
474 // GC - none of these are needed anymore. 470 // GC - none of these are needed anymore.
475 statement = ""; 471 statement = "";
476 parameters = ""; 472 parameters = "";
-   473  
-   474 // Message length check.
477 if(llStringLength(message) > 1023) { 475 if(llStringLength(message) > 1023) {
478 data = "Message length exceeded 1023 characters."; 476 data = "Message length exceeded 1023 characters.";
479 state tell; 477 state tell;
480 } 478 }
-   479  
481 // DEBUG 480 // DEBUG
482 llOwnerSay("[Wiki] Executing action: " + action); 481 llOwnerSay("[Wiki] Executing action: " + action);
483 llInstantMessage( 482 llInstantMessage(
484 wasKeyValueGet( 483 wasKeyValueGet(
485 "corrade", 484 "corrade",
Line 489... Line 488...
489 ); 488 );
490 // GC 489 // GC
491 message = ""; 490 message = "";
492 llSetTimerEvent(60); 491 llSetTimerEvent(60);
493 } 492 }
494 http_request(key id, string method, string body) { 493 link_message(integer sender, integer num, string body, key id) {
495 llHTTPResponse(id, 200, "OK"); 494 // Only process callbacks for the database command.
496 llReleaseURL(URL); -  
497 if(wasKeyValueGet("command", body) != "database" || 495 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   496 return;
-   497  
498 wasKeyValueGet("success", body) != "True") { 498 if(wasKeyValueGet("success", body) != "True") {
499 // DEBUG 499 // DEBUG
500 llOwnerSay("[Wiki] Unable query database: " + 500 llOwnerSay("[Wiki] Unable query database: " +
501 wasURLUnescape( 501 wasURLUnescape(
502 wasKeyValueGet("error", body) 502 wasKeyValueGet("error", body)
503 ) 503 )
504 ); 504 );
505 state listen_group; 505 state listen_group;
506 } 506 }
Line 507... Line 507...
507 507  
508 // Process actions. -  
509 508 // Process actions.
510 if(action == "set") { 509 if(action == "set") {
511 if(data == "") { 510 if(data == "") {
512 data = "Deleted from " + path; 511 data = "Deleted from " + path;
513 state tell; 512 state tell;
Line 634... Line 633...
634 // DEBUG 633 // DEBUG
635 llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); 634 llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
636 state listen_group; 635 state listen_group;
637 } 636 }
638 timer() { 637 timer() {
639 llReleaseURL(URL); -  
640 state listen_group; 638 state listen_group;
641 } 639 }
642 on_rez(integer num) { 640 on_rez(integer num) {
643 llResetScript(); 641 llResetScript();
644 } 642 }