corrade-lsl-templates – Diff between revs 11 and 12

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 11 Rev 12
Line 174... Line 174...
174 // configuration data 174 // configuration data
175 string configuration = ""; 175 string configuration = "";
176 // callback URL 176 // callback URL
177 string URL = ""; 177 string URL = "";
178 // store message over state. 178 // store message over state.
179 string data = ""; -  
180 string path = ""; 179 string path = "";
-   180 string data = "";
-   181 string action = "";
-   182 string statement = "";
181 string jump_state = ""; 183 string parameters = "";
Line 182... Line 184...
182   184  
183 default { 185 default {
184 state_entry() { 186 state_entry() {
185 llOwnerSay("[Wiki] Starting..."); 187 llOwnerSay("[Wiki] Starting...");
186 llSetTimerEvent(10); 188 llSetTimerEvent(10);
187 } 189 }
188 link_message(integer sender, integer num, string message, key id) { 190 link_message(integer sender, integer num, string message, key id) {
189 if(id != "configuration") return; 191 if(id != "configuration") return;
190 llOwnerSay("[Wiki] Got configuration..."); 192 llOwnerSay("[Wiki] Got configuration...");
191 configuration = message; 193 configuration = message;
192 jump_state = "create_database"; 194 action = "create";
193 state url; 195 state url;
194 } 196 }
195 timer() { 197 timer() {
196 llOwnerSay("[Wiki] Requesting configuration..."); 198 llOwnerSay("[Wiki] Requesting configuration...");
Line 219... Line 221...
219 } 221 }
220 http_request(key id, string method, string body) { 222 http_request(key id, string method, string body) {
221 if(method != URL_REQUEST_GRANTED) return; 223 if(method != URL_REQUEST_GRANTED) return;
222 URL = body; 224 URL = body;
223 // DEBUG 225 // DEBUG
224 llOwnerSay("[Wiki] Got URL..."); 226 llOwnerSay("[Wiki] Got URL.");
225 if(jump_state == "create_database") -  
226 state create_database; -  
227 if(jump_state == "get") -  
228 state get; -  
229 if(jump_state == "set") -  
230 state set; -  
231 if(jump_state == "dir") -  
232 state dir; -  
233 if(jump_state == "listen_group") -  
234 state listen_group; -  
Line 235... Line -...
235 -  
236 // DEBUG -  
237 llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); -  
238 llResetScript(); -  
239 } -  
240 on_rez(integer num) { -  
241 llResetScript(); -  
242 } 227
243 changed(integer change) { 228 if(action == "create") {
244 if((change & CHANGED_INVENTORY) || 229 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
245 (change & CHANGED_REGION_START) || 230 wasKeyValueGet("wiki table", configuration) +
246 (change & CHANGED_OWNER)) { 231 "\" (path text unique collate nocase, data text)");
247 llResetScript(); -  
248 } -  
249 } 232 state query;
Line 250... Line -...
250 } -  
251   233 }
252 state create_database { -  
253 state_entry() { 234
254 // DEBUG -  
255 llOwnerSay("[Wiki] Creating database."); 235 if(action == "get") {
256 llInstantMessage( 236 statement = wasURLEscape("SELECT data FROM \"" +
257 wasKeyValueGet( 237 wasKeyValueGet("wiki table", configuration) +
258 "corrade", -  
259 configuration 238 "\" WHERE path=:path");
260 ), 239 parameters = wasURLEscape(
261 wasKeyValueEncode( -  
262 [ -  
263 "command", "database", -  
264 "group", wasURLEscape( 240 wasListToCSV(
265 wasKeyValueGet( 241 [
266 "group", -  
267 configuration 242 "path",
268 ) -  
269 ), -  
270 "password", wasURLEscape( -  
271 wasKeyValueGet( -  
272 "password", 243 wasURLEscape(path)
-   244 ]
273 configuration 245 )
-   246 );
-   247 state query;
-   248 }
-   249
274 ) 250 if(action == "set") {
275 ), 251 if(data == "") {
276 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 252 statement = wasURLEscape("DELETE FROM \"" +
-   253 wasKeyValueGet("wiki table", configuration) +
-   254 "\" WHERE path=:path");
-   255 parameters = wasURLEscape(
-   256 wasListToCSV(
277 wasKeyValueGet("wiki table", configuration) + 257 [
278 "\" (path text unique collate nocase, data text)"), 258 "path",
279 "callback", wasURLEscape(URL) 259 wasURLEscape(path)
280 ] 260 ]
281 ) 261 )
282 ); 262 );
283 llSetTimerEvent(60); 263 state query;
284 } 264 }
285 http_request(key id, string method, string body) { 265 statement = wasURLEscape("REPLACE INTO \"" +
286 llHTTPResponse(id, 200, "OK"); 266 wasKeyValueGet("wiki table", configuration) +
287 llReleaseURL(URL); 267 "\" (path, data) VALUES (:path, :data)");
288 if(wasKeyValueGet("command", body) != "database" || 268 parameters = wasURLEscape(
-   269 wasListToCSV(
289 wasKeyValueGet("success", body) != "True") { 270 [
290 // DEBUG 271 "path",
291 llOwnerSay("[Wiki] Unable modify database: " + 272 wasURLEscape(path),
-   273 "data",
292 wasURLUnescape( 274 wasURLEscape(data)
293 wasKeyValueGet("error", body) 275 ]
294 ) 276 )
295 ); 277 );
-   278 state query;
-   279 }
296 state listen_group; 280
-   281 if(action == "dir") {
-   282 if(path == "/") {
297 } 283 path = "";
298 llOwnerSay("[Wiki] Database created!"); 284 statement = wasURLEscape("SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + wasKeyValueGet("wiki table", configuration) + "\" WHERE path LIKE '/%'");
299 state listen_group; 285 state query;
-   286 }
-   287 statement = wasURLEscape("SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + wasKeyValueGet("wiki table", configuration) + "\" WHERE path LIKE :path");
-   288 parameters = wasURLEscape(
-   289 wasListToCSV(
-   290 [
-   291 "path",
-   292 wasURLEscape(path + "/" + "%"),
-   293 "base",
-   294 wasURLEscape("/" + llDumpList2String(llParseString2List(path, ["/"], []), "/") + "/")
-   295 ]
300 } 296 )
-   297 );
-   298 state query;
-   299 }
-   300
301 timer() { 301 // DEBUG
302 llReleaseURL(URL); 302 llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
303 state listen_group; 303 llResetScript();
304 } 304 }
305 on_rez(integer num) { 305 on_rez(integer num) {
306 llResetScript(); 306 llResetScript();
Line 310... Line 310...
310 (change & CHANGED_REGION_START) || 310 (change & CHANGED_REGION_START) ||
311 (change & CHANGED_OWNER)) { 311 (change & CHANGED_OWNER)) {
312 llResetScript(); 312 llResetScript();
313 } 313 }
314 } 314 }
315 state_exit() { -  
316 llSetTimerEvent(0); -  
317 } -  
318 } 315 }
Line 319... Line 316...
319   316  
320 state listen_group { 317 state listen_group {
321 state_entry() { 318 state_entry() {
Line 343... Line 340...
343 if(llGetSubString(data, 0, 0) != 340 if(llGetSubString(data, 0, 0) !=
344 wasKeyValueGet("command", configuration)) 341 wasKeyValueGet("command", configuration))
345 return; 342 return;
Line 346... Line 343...
346 343
347 // Check if the command matches the current module. 344 // Check if the command matches the current module.
348 list command = llParseString2List(data, 345 list command = llParseString2List(data, [" "], []);
349 [wasKeyValueGet("command", configuration), " "], ["@"]); 346 if(llList2String(command, 0) !=
350 if(llList2String(command, 0) != "wiki") 347 wasKeyValueGet("command", configuration) + "wiki")
Line 351... Line 348...
351 return; 348 return;
352 349
Line 360... Line 357...
360 data = "Subcommands are: get, set, dir"; 357 data = "Subcommands are: get, set, dir";
361 state tell; 358 state tell;
362 } 359 }
Line 363... Line 360...
363 360
364 // Get the sub-command and store it as a jump state. 361 // Get the sub-command and store it as a jump state.
Line 365... Line 362...
365 jump_state = llList2String(command, 0); 362 action = llList2String(command, 0);
366 363
Line 367... Line 364...
367 // Remove sub-command. 364 // Remove sub-command.
Line 413... Line 410...
413 llResetScript(); 410 llResetScript();
414 } 411 }
415 } 412 }
416 } 413 }
Line 417... Line 414...
417   414  
418 state set { 415 state query {
419 state_entry() { -  
420 if(data == "") { -  
421 // DEBUG -  
422 llOwnerSay("[Wiki] Removing from database."); -  
423 llInstantMessage( -  
424 wasKeyValueGet( -  
425 "corrade", -  
426 configuration -  
427 ), -  
428 wasKeyValueEncode( -  
429 [ -  
430 "command", "database", -  
431 "group", wasURLEscape( -  
432 wasKeyValueGet( -  
433 "group", -  
434 configuration -  
435 ) -  
436 ), -  
437 "password", wasURLEscape( -  
438 wasKeyValueGet( -  
439 "password", -  
440 configuration -  
441 ) -  
442 ), -  
443 "SQL", wasURLEscape("DELETE FROM \"" + -  
444 wasKeyValueGet("wiki table", configuration) + -  
445 "\" WHERE path=:path"), -  
446 "data", wasURLEscape( -  
447 wasListToCSV( -  
448 [ -  
449 "path", -  
450 wasURLEscape("path") -  
451 ] -  
452 ) -  
453 ), -  
454 "callback", wasURLEscape(URL) -  
455 ] -  
456 ) -  
457 ); -  
458 llSetTimerEvent(60); -  
459 return; -  
460 } 416 state_entry() {
461 // DEBUG 417 // DEBUG
462 llOwnerSay("[Wiki] Adding to database."); 418 llOwnerSay("[Wiki] Executing action: " + action);
463 llInstantMessage( 419 llInstantMessage(
464 wasKeyValueGet( 420 wasKeyValueGet(
465 "corrade", 421 "corrade",
466 configuration 422 configuration
Line 478... Line 434...
478 wasKeyValueGet( 434 wasKeyValueGet(
479 "password", 435 "password",
480 configuration 436 configuration
481 ) 437 )
482 ), 438 ),
483 "SQL", wasURLEscape("REPLACE INTO \"" + -  
484 wasKeyValueGet("wiki table", configuration) + -  
485 "\" (path, data) VALUES (:path, :data)"), -  
486 "data", wasURLEscape( 439 "SQL", statement,
487 wasListToCSV( -  
488 [ -  
489 "path", -  
490 wasURLEscape(path), -  
491 "data", 440 "data", parameters,
492 wasURLEscape(data) -  
493 ] -  
494 ) -  
495 ), -  
496 "callback", wasURLEscape(URL) 441 "callback", wasURLEscape(URL)
497 ] 442 ]
498 ) 443 )
499 ); 444 );
500 llSetTimerEvent(60); 445 llSetTimerEvent(60);
Line 503... Line 448...
503 llHTTPResponse(id, 200, "OK"); 448 llHTTPResponse(id, 200, "OK");
504 llReleaseURL(URL); 449 llReleaseURL(URL);
505 if(wasKeyValueGet("command", body) != "database" || 450 if(wasKeyValueGet("command", body) != "database" ||
506 wasKeyValueGet("success", body) != "True") { 451 wasKeyValueGet("success", body) != "True") {
507 // DEBUG 452 // DEBUG
508 llOwnerSay("[Wiki] Unable modify database: " + 453 llOwnerSay("[Wiki] Unable query database: " +
509 wasURLUnescape( 454 wasURLUnescape(
510 wasKeyValueGet("error", body) 455 wasKeyValueGet("error", body)
511 ) 456 )
512 ); 457 );
513 state listen_group; 458 state listen_group;
514 } 459 }
-   460
-   461 // Process actions.
-   462
-   463 if(action == "set") {
515 if(data == "") { 464 if(data == "") {
516 data = "Deleted from " + path; 465 data = "Deleted from " + path;
517 state tell; 466 state tell;
518 } 467 }
519 data = "Stored into " + path; 468 data = "Stored into " + path;
520 state tell; 469 state tell;
521 } 470 }
522 timer() { -  
523 llReleaseURL(URL); -  
524 state listen_group; -  
525 } -  
526 on_rez(integer num) { -  
527 llResetScript(); -  
528 } -  
529 changed(integer change) { -  
530 if((change & CHANGED_INVENTORY) || -  
531 (change & CHANGED_REGION_START) || -  
532 (change & CHANGED_OWNER)) { -  
533 llResetScript(); -  
534 } -  
535 } -  
536 state_exit() { -  
537 llSetTimerEvent(0); -  
538 } -  
539 } -  
540   -  
541 state get { -  
542 state_entry() { -  
543 // DEBUG -  
544 llOwnerSay("[Wiki] Retrieving from database."); -  
545 llInstantMessage( -  
546 wasKeyValueGet( -  
547 "corrade", -  
548 configuration -  
549 ), -  
550 wasKeyValueEncode( -  
551 [ -  
552 "command", "database", -  
553 "group", wasURLEscape( -  
554 wasKeyValueGet( -  
555 "group", -  
556 configuration -  
557 ) -  
558 ), -  
559 "password", wasURLEscape( -  
560 wasKeyValueGet( -  
561 "password", -  
562 configuration -  
563 ) -  
564 ), -  
565 "SQL", wasURLEscape("SELECT data FROM \"" + -  
566 wasKeyValueGet("wiki table", configuration) + -  
567 "\" WHERE path=:path"), -  
568 "data", wasURLEscape( -  
569 wasListToCSV( -  
570 [ -  
571 "path", -  
572 wasURLEscape(path) -  
573 ] -  
574 ) -  
575 ), -  
576 "callback", wasURLEscape(URL) -  
577 ] -  
578 ) -  
579 ); -  
580 llSetTimerEvent(60); -  
581 } -  
582 http_request(key id, string method, string body) { -  
583 llHTTPResponse(id, 200, "OK"); -  
584 llReleaseURL(URL); -  
585 if(wasKeyValueGet("command", body) != "database" || -  
586 wasKeyValueGet("success", body) != "True") { -  
587 // DEBUG -  
588 llOwnerSay("[Wiki] Unable retrieve from database: " + -  
589 wasURLUnescape( -  
590 wasKeyValueGet("error", body) -  
591 ) -  
592 ); -  
593 state listen_group; -  
594 } -  
Line -... Line 471...
-   471
595 472 if(action == "get") {
596 data = llDumpList2String( 473 data = llDumpList2String(
597 llDeleteSubList( 474 llDeleteSubList(
598 wasCSVToList( 475 wasCSVToList(
599 wasURLUnescape( 476 wasURLUnescape(
Line 612... Line 489...
612 } 489 }
Line 613... Line 490...
613 490
614 data = path + ": " + data; 491 data = path + ": " + data;
615 state tell; 492 state tell;
616 } -  
617 timer() { -  
618 llReleaseURL(URL); -  
619 state listen_group; -  
620 } -  
621 on_rez(integer num) { -  
622 llResetScript(); -  
623 } -  
624 changed(integer change) { -  
625 if((change & CHANGED_INVENTORY) || -  
626 (change & CHANGED_REGION_START) || -  
627 (change & CHANGED_OWNER)) { -  
628 llResetScript(); -  
629 } -  
630 } -  
631 state_exit() { -  
632 llSetTimerEvent(0); -  
633 } -  
634 } -  
635   -  
636 state dir { -  
637 state_entry() { -  
638 // DEBUG -  
639 llOwnerSay("[Wiki] Listing paths from database."); -  
640 llInstantMessage( -  
641 wasKeyValueGet( -  
642 "corrade", -  
643 configuration -  
644 ), -  
645 wasKeyValueEncode( -  
646 [ -  
647 "command", "database", -  
648 "group", wasURLEscape( -  
649 wasKeyValueGet( -  
650 "group", -  
651 configuration -  
652 ) -  
653 ), -  
654 "password", wasURLEscape( -  
655 wasKeyValueGet( -  
656 "password", -  
657 configuration -  
658 ) -  
659 ), -  
660 "SQL", wasURLEscape("SELECT path FROM \"" + -  
661 wasKeyValueGet("wiki table", configuration) + -  
662 "\" WHERE path like :path"), -  
663 "data", wasURLEscape( -  
664 wasListToCSV( -  
665 [ -  
666 "path", -  
667 wasURLEscape(path + "%") -  
668 ] -  
669 ) -  
670 ), -  
671 "callback", wasURLEscape(URL) -  
672 ] -  
673 ) -  
674 ); -  
675 llSetTimerEvent(60); -  
676 } -  
677 http_request(key id, string method, string body) { -  
678 llHTTPResponse(id, 200, "OK"); -  
679 llReleaseURL(URL); -  
680 if(wasKeyValueGet("command", body) != "database" || -  
681 wasKeyValueGet("success", body) != "True") { -  
682 // DEBUG -  
683 llOwnerSay("[Wiki] Unable retrieve from database: " + -  
684 wasURLUnescape( -  
685 wasKeyValueGet("error", body) -  
686 ) -  
687 ); -  
688 state listen_group; -  
Line -... Line 493...
-   493 }
-   494
-   495 if(action == "dir") {
-   496 llOwnerSay(wasURLUnescape(
689 } 497 wasKeyValueGet("data", body)
690 498 ));
691 list paths = llList2ListStrided( 499 list paths = llList2ListStrided(
692 llDeleteSubList( 500 llDeleteSubList(
693 wasCSVToList( 501 wasCSVToList(
Line 732... Line 540...
732 ); 540 );
Line 733... Line 541...
733 541
734 integer i = llSubStringIndex(child, "/"); 542 integer i = llSubStringIndex(child, "/");
735 if(i == -1) { 543 if(i == -1) {
736 sibling += path + "/" + child; 544 sibling += path + "/" + child;
737 jump continue; 545 jump continue_dir;
738 } 546 }
739 child = path + "/" + llDeleteSubString(child, i, -1) + "/"; 547 child = path + "/" + llDeleteSubString(child, i, -1) + "/";
740 if(llListFindList(sibling, (list)child) == -1) 548 if(llListFindList(sibling, (list)child) == -1)
741 sibling += child; 549 sibling += child;
742 @continue; 550 @continue_dir;
743 paths = llDeleteSubList(paths, 0, 0); 551 paths = llDeleteSubList(paths, 0, 0);
Line 744... Line 552...
744 } while(llGetListLength(paths) != 0); 552 } while(llGetListLength(paths) != 0);
745 553
746 data = llList2CSV(sibling); 554 data = llList2CSV(sibling);
Line 747... Line 555...
747 // GC 555 // GC
748 sibling = []; 556 sibling = [];
-   557
-   558 state tell;
-   559 }
-   560
-   561 // Don't announce creating table.
-   562 if(action == "create")
-   563 state listen_group;
-   564
-   565 // DEBUG
749 566 llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
750 state tell; 567 state listen_group;
751 } 568 }
752 timer() { 569 timer() {
753 llReleaseURL(URL); 570 llReleaseURL(URL);