corrade-lsl-templates – Diff between revs 13 and 14

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 13 Rev 14
Line 42... Line 42...
42 } while(llGetListLength(k) != 0); 42 } while(llGetListLength(k) != 0);
43 return llDumpList2String(data, "&"); 43 return llDumpList2String(data, "&");
44 } 44 }
Line 45... Line 45...
45   45  
46 /////////////////////////////////////////////////////////////////////////// -  
47 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // -  
48 /////////////////////////////////////////////////////////////////////////// -  
49 // http://was.fm/secondlife/wanderer -  
50 vector wasCirclePoint(float radius) { -  
51 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); -  
52 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); -  
53 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) -  
54 return <x, y, 0>; -  
55 return wasCirclePoint(radius); -  
56 } -  
57   -  
58 /////////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////////
59 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 47 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
60 /////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////
61 // escapes a string in conformance with RFC1738 49 // escapes a string in conformance with RFC1738
62 string wasURLEscape(string i) { 50 string wasURLEscape(string i) {
Line 279... Line 267...
279 } 267 }
Line 280... Line 268...
280 268
281 if(action == "dir") { 269 if(action == "dir") {
282 if(path == "/") { 270 if(path == "/") {
-   271 path = "";
283 path = ""; 272 statement = wasURLEscape(
-   273 "SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" +
-   274 wasKeyValueGet("wiki table", configuration) +
-   275 "\" WHERE path LIKE '/%' LIMIT " +
-   276 wasKeyValueGet("wiki results limit", configuration)
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 '/%'"); 277 );
285 state query; 278 state query;
-   279 }
286 } 280 statement = wasURLEscape(
-   281 "SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" +
-   282 wasKeyValueGet("wiki table", configuration) +
-   283 "\" WHERE path LIKE :path LIMIT " +
-   284 wasKeyValueGet("wiki results limit", configuration)
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"); 285 );
288 parameters = wasURLEscape( 286 parameters = wasURLEscape(
289 wasListToCSV( 287 wasListToCSV(
290 [ 288 [
291 "path", 289 "path",
292 wasURLEscape(path + "/" + "%"), 290 wasURLEscape(path + "/" + "%"),
-   291 "base",
-   292 wasURLEscape("/" +
-   293 llDumpList2String(
-   294 llParseString2List(
-   295 path,
-   296 ["/"],
-   297 []
-   298 ),
-   299 "/"
-   300 ) +
-   301 "/"
-   302 )
-   303 ]
-   304 )
-   305 );
-   306 state query;
-   307 }
-   308
-   309 if(action == "find") {
-   310 if(data == "") {
-   311 data = "Command requires two parameters: a path followed by a search term.";
-   312 state tell;
-   313 }
-   314 if(path == "/")
-   315 path = "";
-   316 statement = wasURLEscape(
-   317 "SELECT DISTINCT path FROM \"" +
-   318 wasKeyValueGet("wiki table", configuration) +
-   319 "\" WHERE path LIKE :path AND ( data LIKE :data OR path LIKE :data ) COLLATE NOCASE LIMIT " +
-   320 wasKeyValueGet("wiki search limit", configuration)
-   321 );
-   322 parameters = wasURLEscape(
-   323 wasListToCSV(
-   324 [
293 "base", 325 "path",
-   326 wasURLEscape(path + "/" + "%"),
-   327 "data",
294 wasURLEscape("/" + llDumpList2String(llParseString2List(path, ["/"], []), "/") + "/") 328 wasURLEscape("%" + data + "%")
295 ] 329 ]
296 ) 330 )
297 ); 331 );
298 state query; 332 state query;
Line 351... Line 385...
351 command = llDeleteSubList(command, 0, 0); 385 command = llDeleteSubList(command, 0, 0);
Line 352... Line 386...
352 386
353 // Check for supported sub-commands. 387 // Check for supported sub-commands.
354 if(llList2String(command, 0) != "set" && 388 if(llList2String(command, 0) != "set" &&
-   389 llList2String(command, 0) != "get" &&
355 llList2String(command, 0) != "get" && 390 llList2String(command, 0) != "dir" &&
356 llList2String(command, 0) != "dir") { 391 llList2String(command, 0) != "find") {
357 data = "Subcommands are: get, set, dir"; 392 data = "Subcommands are: get, set, dir or find";
358 state tell; 393 state tell;
Line 359... Line 394...
359 } 394 }
360 395
Line 412... Line 447...
412 } 447 }
413 } 448 }
Line 414... Line 449...
414   449  
415 state query { 450 state query {
-   451 state_entry() {
-   452 // Check messge length.
-   453 string message = wasKeyValueEncode(
-   454 [
-   455 "command", "database",
-   456 "group", wasURLEscape(
-   457 wasKeyValueGet(
-   458 "group",
-   459 configuration
-   460 )
-   461 ),
-   462 "password", wasURLEscape(
-   463 wasKeyValueGet(
-   464 "password",
-   465 configuration
-   466 )
-   467 ),
-   468 "SQL", statement,
-   469 "data", parameters,
-   470 "callback", wasURLEscape(URL)
-   471 ]
-   472 );
-   473 // GC - none of these are needed anymore.
-   474 statement = "";
-   475 parameters = "";
-   476 if(llStringLength(message) > 1023) {
-   477 data = "Message length exceeded 1023 characters.";
-   478 state tell;
416 state_entry() { 479 }
417 // DEBUG 480 // DEBUG
418 llOwnerSay("[Wiki] Executing action: " + action); 481 llOwnerSay("[Wiki] Executing action: " + action);
419 llInstantMessage( 482 llInstantMessage(
420 wasKeyValueGet( 483 wasKeyValueGet(
421 "corrade", 484 "corrade",
422 configuration 485 configuration
423 ), -  
424 wasKeyValueEncode( 486 ),
425 [ -  
426 "command", "database", -  
427 "group", wasURLEscape( -  
428 wasKeyValueGet( -  
429 "group", -  
430 configuration -  
431 ) -  
432 ), -  
433 "password", wasURLEscape( -  
434 wasKeyValueGet( -  
435 "password", -  
436 configuration -  
437 ) -  
438 ), -  
439 "SQL", statement, -  
440 "data", parameters, -  
441 "callback", wasURLEscape(URL) -  
442 ] -  
443 ) 487 message
-   488 );
-   489 // GC
444 ); 490 message = "";
445 llSetTimerEvent(60); 491 llSetTimerEvent(60);
446 } 492 }
447 http_request(key id, string method, string body) { 493 http_request(key id, string method, string body) {
448 llHTTPResponse(id, 200, "OK"); 494 llHTTPResponse(id, 200, "OK");
Line 466... Line 512...
466 state tell; 512 state tell;
467 } 513 }
468 data = "Stored into " + path; 514 data = "Stored into " + path;
469 state tell; 515 state tell;
470 } 516 }
471 517  
-   518 if(action == "find") {
-   519 data = llDumpList2String(
-   520 llList2ListStrided(
-   521 llDeleteSubList(
-   522 wasCSVToList(
-   523 wasURLUnescape(
-   524 wasKeyValueGet("data", body)
-   525 )
-   526 ),
-   527 0,
-   528 0
-   529 ),
-   530 0,
-   531 -1,
-   532 2
-   533 ),
-   534 ","
-   535 );
-   536 if(data == "") {
-   537 data = "Sorry, the term was not found.";
-   538 state tell;
-   539 }
-   540 state tell;
-   541 }
-   542  
472 if(action == "get") { 543 if(action == "get") {
473 data = llDumpList2String( 544 data = llDumpList2String(
474 llDeleteSubList( 545 llDeleteSubList(
475 wasCSVToList( 546 wasCSVToList(
476 wasURLUnescape( 547 wasURLUnescape(
Line 609... Line 680...
609 "entity", "group", 680 "entity", "group",
610 "message", wasURLEscape(data) 681 "message", wasURLEscape(data)
611 ] 682 ]
612 ) 683 )
613 ); 684 );
-   685 // GC
-   686 path = "";
-   687 data = "";
614 state listen_group; 688 state listen_group;
615 } 689 }
616 } 690 }