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

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 41 Rev 42
Line 161... Line 161...
161 ); 161 );
162 } 162 }
Line 163... Line 163...
163 163  
164 // configuration data 164 // configuration data
165 string configuration = ""; -  
166 // callback URL -  
167 string URL = ""; 165 string configuration = "";
168 // store message over state. 166 // store message over state.
169 string firstname = ""; 167 string firstname = "";
170 string lastname = ""; 168 string lastname = "";
171 string group = ""; 169 string group = "";
-   170 string data = "";
-   171 string action = "";
172 string data = ""; 172  
173 string jump_state = ""; 173 string statement = "";
Line 174... Line 174...
174 integer joke_counter = 0; 174 string parameters = "";
175 175  
176 default { 176 default {
177 state_entry() { 177 state_entry() {
178 llOwnerSay("[Joke] Starting module..."); 178 llOwnerSay("[Joke] Starting module...");
179 llSetTimerEvent(10); 179 llSetTimerEvent(10);
180 } 180 }
181 link_message(integer sender, integer num, string message, key id) { 181 link_message(integer sender, integer num, string message, key id) {
182 if(id != "configuration") return; 182 if(id != "configuration") return;
183 llOwnerSay("[Joke] Got configuration..."); 183 llOwnerSay("[Joke] Got configuration...");
184 configuration = message; 184 configuration = message;
185 jump_state = "create_database"; 185 action = "create_database";
186 state url; 186 state trampoline;
187 } 187 }
188 timer() { 188 timer() {
189 llOwnerSay("[Joke] Requesting configuration..."); 189 llOwnerSay("[Joke] Requesting configuration...");
Line 202... Line 202...
202 state_exit() { 202 state_exit() {
203 llSetTimerEvent(0); 203 llSetTimerEvent(0);
204 } 204 }
205 } 205 }
Line 206... Line 206...
206 206  
207 state url { 207 state trampoline {
208 state_entry() { 208 state_entry() {
-   209 if(action == "create_database") {
209 // DEBUG 210 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
-   211 wasKeyValueGet("joke table", configuration) +
210 llOwnerSay("[Joke] Requesting URL..."); 212 "\" (data text(1023), name text(35), firstname text(31), lastname text(31), id integer NOT NULL PRIMARY KEY)");
211 llRequestURL(); 213 state query;
212 } -  
213 http_request(key id, string method, string body) { -  
214 if(method != URL_REQUEST_GRANTED) return; -  
215 URL = body; -  
216 // DEBUG -  
217 llOwnerSay("[Joke] Got URL..."); -  
218 if(jump_state == "create_database") -  
219 state create_database; -  
220 if(jump_state == "get") -  
221 state get; -  
222 if(jump_state == "add") -  
223 state add; -  
224 if(jump_state == "remove") -  
225 state remove; -  
226 if(jump_state == "count_jokes") -  
227 state count_jokes; -  
228 if(jump_state == "listen_group") -  
Line 229... Line 214...
229 state listen_group; 214 }
-   215  
230 216 if(action == "random") {
-   217 statement = wasURLEscape("SELECT * FROM \"" +
-   218 wasKeyValueGet("joke table", configuration) +
231 // DEBUG 219 "\" WHERE name=:group ORDER BY RANDOM() LIMIT 1");
232 llOwnerSay("[Joke] Jump table corrupted, please contact creator..."); 220 parameters = wasURLEscape(
233 llResetScript(); 221 wasListToCSV(
234 } 222 [
235 on_rez(integer num) { -  
236 llResetScript(); 223 "group",
237 } 224 wasURLEscape(
238 changed(integer change) { 225 wasKeyValueGet(
239 if((change & CHANGED_INVENTORY) || 226 "group",
240 (change & CHANGED_REGION_START) || 227 configuration
-   228 )
241 (change & CHANGED_OWNER)) { 229 )
242 llResetScript(); 230 ]
-   231 )
-   232 );
243 } 233  
Line 244... Line 234...
244 } 234 state query;
-   235 }
-   236  
-   237 if(action == "id") {
-   238 statement = wasURLEscape("SELECT * FROM \"" +
245 } 239 wasKeyValueGet("joke table", configuration) +
246 240 "\" WHERE name=:group AND id=:id");
247 state create_database { 241 parameters = wasURLEscape(
248 state_entry() { 242 wasListToCSV(
249 // DEBUG 243 [
250 llOwnerSay("[Joke] Creating database: " + wasKeyValueGet("joke table", configuration)); 244 "group",
251 llInstantMessage( 245 wasURLEscape(
-   246 wasKeyValueGet(
252 wasKeyValueGet( 247 "group",
-   248 configuration
-   249 )
-   250 ),
-   251 "id",
-   252 data
-   253 ]
-   254 )
-   255 );
-   256 state query;
-   257 }
-   258  
-   259 if(action == "search") {
-   260 statement = wasURLEscape("SELECT * FROM \"" +
253 "corrade", 261 wasKeyValueGet("joke table", configuration) +
254 configuration 262 "\" WHERE name=:group AND data LIKE :data COLLATE NOCASE ORDER BY RANDOM() LIMIT 1");
255 ), 263 parameters = wasURLEscape(
256 wasKeyValueEncode( 264 wasListToCSV(
257 [ 265 [
258 "command", "database", 266 "group",
259 "group", wasURLEscape( 267 wasURLEscape(
260 wasKeyValueGet( 268 wasKeyValueGet(
261 "group", 269 "group",
-   270 configuration
-   271 )
-   272 ),
-   273 "data",
-   274 wasURLEscape("%" + llDumpList2String(llParseString2List(data, [" "], []), "%") + "%")
-   275 ]
-   276 )
-   277 );
-   278 state query;
-   279 }
-   280  
-   281 if(action == "remove") {
-   282 statement = wasURLEscape("DELETE FROM \"" +
-   283 wasKeyValueGet("joke table", configuration) +
-   284 "\" WHERE name=:name AND id=:id");
-   285 parameters = wasURLEscape(
262 configuration 286 wasListToCSV(
263 ) 287 [
264 ), 288 "name",
265 "password", wasURLEscape( 289 wasURLEscape(
266 wasKeyValueGet( 290 wasKeyValueGet(
267 "password", 291 "group",
268 configuration -  
269 ) 292 configuration
270 ), -  
271 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 293 )
272 wasKeyValueGet("joke table", configuration) + 294 ),
273 "\" (data text(1023), name text(35), firstname text(31), lastname text(31), id integer NOT NULL PRIMARY KEY)"), 295 "id",
274 "callback", wasURLEscape(URL) 296 data
275 ] 297 ]
276 ) 298 )
277 ); -  
278 llSetTimerEvent(60); -  
279 } -  
280 http_request(key id, string method, string body) { -  
281 llHTTPResponse(id, 200, "OK"); -  
282 llReleaseURL(URL); -  
283 if(wasKeyValueGet("command", body) != "database" || -  
284 wasKeyValueGet("success", body) != "True") { -  
285 // DEBUG -  
286 llOwnerSay("[Joke] Unable modify database: " + -  
287 wasURLUnescape( -  
288 wasKeyValueGet("error", body) -  
289 ) + -  
290 " " + -  
Line -... Line 299...
-   299 );
-   300 state query;
-   301 }
-   302  
-   303 if(action == "add") {
-   304 statement = wasURLEscape("INSERT INTO \"" +
-   305 wasKeyValueGet("joke table", configuration) +
-   306 "\" (name, data, firstname, lastname) VALUES (:name, :data, :firstname, :lastname)");
-   307 parameters = wasURLEscape(
-   308 wasListToCSV(
-   309 [
-   310 "name",
-   311 wasURLEscape(
-   312 wasKeyValueGet(
-   313 "group",
-   314 configuration
-   315 )
-   316 ),
-   317 "data",
-   318 wasURLEscape(data),
-   319 "firstname",
-   320 wasURLEscape(firstname),
291 wasURLUnescape( 321 "lastname",
292 wasKeyValueGet("data", body) 322 wasURLEscape(lastname)
293 ) 323 ]
-   324 )
294 325 );
-   326 state query;
295 ); 327 }
296 llResetScript(); 328  
297 } 329 if(action == "get_joke_id") {
-   330 statement = wasURLEscape("SELECT MAX(id) AS LAST FROM \"" +
-   331 wasKeyValueGet("joke table", configuration) + "\"");
-   332 state query;
-   333 }
-   334  
-   335 if(action == "by") {
-   336 statement = wasURLEscape("SELECT * FROM \"" +
-   337 wasKeyValueGet("joke table", configuration) +
-   338 "\" WHERE name=:group AND firstname=:firstname AND lastname=:lastname ORDER BY RANDOM() LIMIT 1");
-   339 parameters = wasURLEscape(
-   340 wasListToCSV(
-   341 [
-   342 "group",
-   343 wasURLEscape(
-   344 wasKeyValueGet(
-   345 "group",
-   346 configuration
-   347 )
-   348 ),
-   349 "firstname",
-   350 wasURLEscape(firstname),
298 llOwnerSay("[Joke] Database created!"); 351 "lastname",
-   352 wasURLEscape(lastname)
-   353 ]
-   354 )
-   355 );
-   356  
-   357 state query;
299 jump_state = "count_jokes"; 358 }
300 state url; 359  
301 } 360 // DEBUG
302 timer() { 361 llOwnerSay("[Joke] Jump table corrupted, please contact creator...");
303 llResetScript(); 362 llResetScript();
Line 310... Line 369...
310 (change & CHANGED_REGION_START) || 369 (change & CHANGED_REGION_START) ||
311 (change & CHANGED_OWNER)) { 370 (change & CHANGED_OWNER)) {
312 llResetScript(); 371 llResetScript();
313 } 372 }
314 } 373 }
315 state_exit() { -  
316 llSetTimerEvent(0); -  
317 } -  
318 } 374 }
Line 319... Line 375...
319   375  
320 state count_jokes { 376 state query {
321 state_entry() { -  
322 // DEBUG -  
323 llOwnerSay("[Joke] Counting jokes in database: " + wasKeyValueGet("joke table", configuration)); -  
324 llInstantMessage( 377 state_entry() {
325 wasKeyValueGet( -  
326 "corrade", -  
327 configuration -  
328 ), 378 // Check messge length.
329 wasKeyValueEncode( 379 string message = wasKeyValueEncode(
330 [ 380 [
331 "command", "database", 381 "command", "database",
332 "group", wasURLEscape( 382 "group", wasURLEscape(
333 wasKeyValueGet( 383 wasKeyValueGet(
Line 339... Line 389...
339 wasKeyValueGet( 389 wasKeyValueGet(
340 "password", 390 "password",
341 configuration 391 configuration
342 ) 392 )
343 ), 393 ),
344 "SQL", wasURLEscape("SELECT COUNT(*) AS count FROM \"" + 394 "SQL", statement,
345 wasKeyValueGet("joke table", configuration) + "\""), 395 "data", parameters,
346 "callback", wasURLEscape(URL) 396 "callback", wasURLEscape(
-   397 wasKeyValueGet(
347 ] 398 "URL",
-   399 configuration
348 ) 400 )
-   401 )
-   402 ]
349 ); 403 );
-   404  
-   405 // GC - none of these are needed anymore.
-   406 statement = "";
-   407 parameters = "";
-   408  
-   409 // Message length check.
-   410 if(llStringLength(message) > 1023) {
-   411 data = "Message length exceeded 1023 characters.";
-   412 state tell;
-   413 }
-   414  
-   415 // DEBUG
-   416 llOwnerSay("[Joke] Executing action: " + action);
-   417 llInstantMessage(
-   418 wasKeyValueGet(
-   419 "corrade",
-   420 configuration
-   421 ),
-   422 message
-   423 );
-   424 // GC
-   425 message = "";
350 llSetTimerEvent(60); 426 llSetTimerEvent(60);
351 } 427 }
352 http_request(key id, string method, string body) { 428 link_message(integer sender, integer num, string body, key id) {
353 llHTTPResponse(id, 200, "OK"); 429 // Only process callbacks for the database command.
354 llReleaseURL(URL); -  
355 if(wasKeyValueGet("command", body) != "database" || 430 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   431 return;
-   432  
356 wasKeyValueGet("success", body) != "True") { 433 if(wasKeyValueGet("success", body) != "True") {
357 // DEBUG 434 // DEBUG
358 llOwnerSay("[Joke] Unable modify database: " + 435 llOwnerSay("[Joke] Unable query database: " +
359 wasURLUnescape( 436 wasURLUnescape(
360 wasKeyValueGet("error", body) 437 wasKeyValueGet("error", body)
361 ) + 438 )
362 " " + 439 );
-   440 state listen_group;
-   441 }
-   442  
-   443 if(action == "create_database") {
-   444 llOwnerSay("[Joke] Database created!");
-   445 state listen_group;
-   446 }
-   447  
-   448 if(action == "random" || action == "id" || action == "search" || action == "by") {
-   449 list result = wasCSVToList(
363 wasURLUnescape( 450 wasURLUnescape(
364 wasKeyValueGet("data", body) 451 wasKeyValueGet("data", body)
365 ) 452 )
-   453 );
Line -... Line 454...
-   454  
-   455 if(llGetListLength(result) != 10) {
-   456 data = "No joke found. . .";
-   457 state tell;
-   458 }
-   459  
-   460 data = llList2String(
-   461 result,
366 462 llListFindList(result, ["data"]) + 1
-   463 );
-   464  
-   465 firstname = llList2String(
-   466 result,
-   467 llListFindList(result, ["firstname"]) + 1
-   468 );
-   469  
-   470 lastname = llList2String(
-   471 result,
-   472 llListFindList(result, ["lastname"]) + 1
-   473 );
-   474  
-   475 string id = llList2String(
-   476 result,
-   477 llListFindList(result, ["id"]) + 1
-   478 );
-   479  
-   480 // Build data to be sent.
-   481 data += " " + "[" + firstname + " " + lastname + "/" + id + "]";
367 ); 482  
-   483 state tell;
-   484 }
-   485  
-   486 if(action == "remove") {
-   487 data = "Joke " + data + " has been removed.";
-   488 state tell;
-   489 }
-   490  
-   491 if(action == "add") {
-   492 action = "get_joke_id";
-   493 data = body;
368 llResetScript(); 494 state trampoline;
Line -... Line 495...
-   495 }
369 } 496  
370 497 if(action == "get_joke_id") {
371 list result = wasCSVToList( 498 list result = wasCSVToList(
372 wasURLUnescape( 499 wasURLUnescape(
373 wasKeyValueGet("data", body) 500 wasKeyValueGet("data", body)
Line 374... Line 501...
374 ) 501 )
375 ); 502 );
376 503  
377 joke_counter = llList2Integer( 504 data = llList2String(
-   505 result,
-   506 llListFindList(result, ["LAST"]) + 1
-   507 );
-   508  
Line -... Line 509...
-   509 data = "Joke " + data + " has been stored.";
378 result, 510 state tell;
379 llListFindList(result, ["count"]) + 1 511 }
380 ) + 1; 512  
381 513 // DEBUG
382 llOwnerSay("[Joke] There are " + (string)joke_counter + " jokes in the database."); 514 llOwnerSay("[Joke] Jump table corrupted, please contact creator...");
383 state listen_group; 515 state listen_group;
384 } 516 }
385 timer() { 517 timer() {
386 llResetScript(); 518 state listen_group;
387 } 519 }
Line 453... Line 585...
453 585  
454 // Remove command. 586 // Remove command.
Line 455... Line 587...
455 command = llDeleteSubList(command, 0, 0); 587 command = llDeleteSubList(command, 0, 0);
456 588  
457 // Remove action. 589 // Remove action.
458 string action = llList2String(command, 0); 590 action = llList2String(command, 0);
459 // Jump to the "add" state for adding 591 // Jump to the "add" state for adding
460 if(action == "add") { 592 if(action == "add") {
461 command = llDeleteSubList(command, 0, 0); 593 command = llDeleteSubList(command, 0, 0);
462 data = llDumpList2String(command, " "); 594 data = llDumpList2String(command, " ");
463 if(data == "") { 595 if(data == "") {
464 data = "The joke's too short to be funny."; 596 data = "The joke's too short to be funny.";
465 state tell; 597 state tell;
466 } 598 }
467 jump_state = "add"; 599 action = "add";
Line 468... Line 600...
468 state url; 600 state trampoline;
469 } 601 }
470 602  
471 // Jump to the "remove" state for removing 603 // Jump to the "remove" state for removing
472 if(action == "remove") { 604 if(action == "remove") {
473 command = llDeleteSubList(command, 0, 0); 605 command = llDeleteSubList(command, 0, 0);
474 data = llDumpList2String(command, " "); 606 data = llDumpList2String(command, " ");
475 if((integer)data == 0) { 607 if((integer)data == 0) {
476 data = "Which one though? Please provide a joke id."; 608 data = "Which one though? Please provide a joke id.";
477 state tell; 609 state tell;
478 } 610 }
Line -... Line 611...
-   611 action = "remove";
-   612 state trampoline;
-   613 }
-   614  
-   615 if(action == "by") {
-   616 command = llDeleteSubList(command, 0, 0);
479 jump_state = "remove"; 617 firstname = llList2String(command, 0);
480 state url; -  
481 } -  
482 -  
483 data = llDumpList2String(command, " "); -  
484 if((integer)data <= 0) -  
485 data = ""; -  
486 jump_state = "get"; -  
487 state url; -  
488 } -  
489 on_rez(integer num) { -  
490 llResetScript(); -  
491 } -  
492 changed(integer change) { -  
493 if((change & CHANGED_INVENTORY) || -  
494 (change & CHANGED_REGION_START) || -  
495 (change & CHANGED_OWNER)) { -  
Line 496... Line -...
496 llResetScript(); -  
497 } -  
498 } -  
499 } -  
500 -  
501 state get { -  
502 state_entry() { -  
503 // DEBUG -  
504 llOwnerSay("[Joke] Retrieving from database."); -  
505 if(data == "") { -  
506 llInstantMessage( -  
507 wasKeyValueGet( -  
508 "corrade", -  
509 configuration -  
510 ), -  
511 wasKeyValueEncode( -  
512 [ -  
513 "command", "database", -  
514 "group", wasURLEscape( -  
515 wasKeyValueGet( -  
516 "group", -  
517 configuration -  
518 ) -  
519 ), -  
520 "password", wasURLEscape( -  
521 wasKeyValueGet( -  
522 "password", -  
523 configuration -  
524 ) -  
525 ), -  
526 "SQL", wasURLEscape("SELECT * FROM \"" + -  
527 wasKeyValueGet("joke table", configuration) + -  
528 "\" WHERE name=:group LIMIT 1 OFFSET :id"), -  
529 "data", wasURLEscape( -  
530 wasListToCSV( -  
531 [ -  
532 "group", -  
533 wasURLEscape( -  
534 wasKeyValueGet( -  
535 "group", -  
536 configuration -  
537 ) -  
538 ), -  
539 "id", -  
540 (string)( -  
541 (integer)llFrand( -  
542 joke_counter -  
543 ) + 1 -  
544 ) -  
545 ] -  
546 ) -  
547 ), -  
548 "callback", wasURLEscape(URL) -  
549 ] -  
550 ) -  
551 ); -  
552 llSetTimerEvent(60); -  
553 return; -  
554 } -  
555 llInstantMessage( -  
556 wasKeyValueGet( -  
557 "corrade", -  
558 configuration -  
559 ), -  
560 wasKeyValueEncode( -  
561 [ -  
562 "command", "database", -  
563 "group", wasURLEscape( -  
564 wasKeyValueGet( -  
565 "group", -  
566 configuration -  
567 ) -  
568 ), -  
569 "password", wasURLEscape( -  
570 wasKeyValueGet( -  
571 "password", -  
572 configuration -  
573 ) -  
574 ), -  
575 "SQL", wasURLEscape("SELECT * FROM \"" + -  
576 wasKeyValueGet("joke table", configuration) + -  
577 "\" WHERE name=:group AND id=:id"), -  
578 "data", wasURLEscape( -  
579 wasListToCSV( -  
580 [ -  
581 "group", -  
582 wasURLEscape( -  
583 wasKeyValueGet( -  
584 "group", -  
585 configuration -  
586 ) -  
587 ), -  
588 "id", -  
589 data -  
590 ] -  
591 ) -  
592 ), -  
593 "callback", wasURLEscape(URL) -  
594 ] -  
595 ) -  
596 ); -  
597 llSetTimerEvent(60); -  
598 } -  
599 http_request(key id, string method, string body) { -  
600 llHTTPResponse(id, 200, "OK"); -  
601 llReleaseURL(URL); -  
602 if(wasKeyValueGet("command", body) != "database" || -  
603 wasKeyValueGet("success", body) != "True") { -  
604 // DEBUG -  
605 llOwnerSay("[Joke] Unable retrieve from database: " + -  
606 wasURLUnescape( -  
607 wasKeyValueGet("error", body) -  
608 ) -  
609 ); -  
610 state listen_group; 618 command = llDeleteSubList(command, 0, 0);
611 } -  
612 -  
613 list result = wasCSVToList( -  
614 wasURLUnescape( 619 lastname = llList2String(command, 0);
615 wasKeyValueGet("data", body) 620 command = llDeleteSubList(command, 0, 0);
616 ) 621 data = llDumpList2String(command, " ");
617 ); 622  
Line 618... Line -...
618 -  
619 if(llGetListLength(result) != 10) { -  
620 data = "No joke found. . ."; -  
621 state tell; -  
622 } -  
623 -  
624 data = llList2String( 623 if(llStringLength(firstname) == 0 ||
625 result, -  
626 llListFindList(result, ["data"]) + 1 -  
627 ); -  
628 -  
629 string firstname = llList2String( 624 llStringLength(lastname) == 0) {
630 result, -  
631 llListFindList(result, ["firstname"]) + 1 625 data = "First and Last name is required.";
Line 632... Line 626...
632 ); 626 state tell;
633 -  
634 string lastname = llList2String( 627 }
635 result, -  
Line 636... Line -...
636 llListFindList(result, ["lastname"]) + 1 -  
637 ); 628  
Line 638... Line -...
638 -  
639 string id = llList2String( -  
640 result, -  
641 llListFindList(result, ["id"]) + 1 -  
642 ); -  
643 -  
644 // Build data to be sent. -  
645 data += " " + "[" + firstname + " " + lastname + "/" + id + "]"; -  
646 -  
647 state tell; 629 action = "by";
648 } -  
649 timer() { -  
650 llReleaseURL(URL); -  
651 state listen_group; 630 state trampoline;
652 } -  
653 on_rez(integer num) { -  
654 llResetScript(); -  
655 } 631 }
656 changed(integer change) { -  
657 if((change & CHANGED_INVENTORY) || 632  
Line 658... Line -...
658 (change & CHANGED_REGION_START) || -  
659 (change & CHANGED_OWNER)) { -  
660 llResetScript(); -  
661 } -  
662 } -  
663 state_exit() { -  
664 llSetTimerEvent(0); -  
665 } -  
666 } -  
667 -  
668 state add { -  
669 state_entry() { -  
670 // DEBUG -  
671 llOwnerSay("[Joke] Adding to database: " + (string)(joke_counter + 1)); -  
672 llInstantMessage( -  
673 wasKeyValueGet( -  
674 "corrade", -  
675 configuration -  
676 ), -  
677 wasKeyValueEncode( -  
678 [ -  
679 "command", "database", -  
680 "group", wasURLEscape( -  
681 wasKeyValueGet( -  
682 "group", -  
683 configuration -  
684 ) -  
685 ), -  
686 "password", wasURLEscape( -  
687 wasKeyValueGet( -  
688 "password", -  
689 configuration -  
690 ) -  
691 ), -  
692 "SQL", wasURLEscape("INSERT INTO \"" + -  
693 wasKeyValueGet("joke table", configuration) + -  
694 "\" (name, data, firstname, lastname, id) VALUES (:name, :data, :firstname, :lastname, :id)"), 633 string index = llList2String(command, 0);
695 "data", wasURLEscape( -  
696 wasListToCSV( -  
697 [ -  
698 "name", -  
699 wasURLEscape( -  
700 wasKeyValueGet( -  
701 "group", -  
702 configuration -  
703 ) 634 command = llDeleteSubList(command, 0, 0);
704 ), -  
705 "data", -  
706 wasURLEscape(data), -  
707 "firstname", -  
708 wasURLEscape(firstname), -  
709 "lastname", -  
710 wasURLEscape(lastname), -  
711 "id", -  
712 (string)(joke_counter + 1) -  
713 ] -  
714 ) -  
715 ), -  
716 "callback", wasURLEscape(URL) -  
717 ] -  
718 ) -  
719 ); -  
720 llSetTimerEvent(60); -  
721 } -  
722 http_request(key id, string method, string body) { -  
723 llHTTPResponse(id, 200, "OK"); 635  
724 llReleaseURL(URL); -  
725 if(wasKeyValueGet("command", body) != "database" || -  
726 wasKeyValueGet("success", body) != "True") { -  
727 // DEBUG -  
728 llOwnerSay("[Joke] Unable modify database: " + -  
729 wasURLUnescape( -  
730 wasKeyValueGet("data", body) -  
731 ) -  
732 ); -  
733 state listen_group; -  
734 } -  
735 ++joke_counter; -  
736 data = "Joke " + (string)joke_counter + " has been stored."; -  
737 state tell; -  
738 } -  
739 timer() { -  
740 llReleaseURL(URL); -  
741 state listen_group; -  
742 } -  
743 on_rez(integer num) { -  
744 llResetScript(); -  
745 } -  
746 changed(integer change) { 636 data = llDumpList2String(command, " ");
Line 747... Line -...
747 if((change & CHANGED_INVENTORY) || -  
748 (change & CHANGED_REGION_START) || -  
749 (change & CHANGED_OWNER)) { -  
750 llResetScript(); -  
751 } -  
752 } -  
753 state_exit() { -  
754 llSetTimerEvent(0); -  
755 } -  
756 } -  
757   -  
758 state remove { -  
759 state_entry() { -  
760 // DEBUG -  
761 llOwnerSay("[Joke] Removing from database."); -  
762 llInstantMessage( -  
763 wasKeyValueGet( -  
764 "corrade", 637  
765 configuration -  
766 ), -  
767 wasKeyValueEncode( -  
768 [ -  
769 "command", "database", -  
770 "group", wasURLEscape( -  
771 wasKeyValueGet( -  
772 "group", -  
773 configuration -  
774 ) -  
775 ), -  
776 "password", wasURLEscape( -  
777 wasKeyValueGet( -  
778 "password", -  
779 configuration -  
780 ) -  
781 ), -  
782 "SQL", wasURLEscape("DELETE FROM \"" + -  
783 wasKeyValueGet("joke table", configuration) + -  
784 "\" WHERE name=:name AND id=:id"), -  
785 "data", wasURLEscape( -  
786 wasListToCSV( -  
787 [ -  
788 "name", 638 if(index == "search") {
789 wasURLEscape( -  
790 wasKeyValueGet( -  
791 "group", -  
792 configuration -  
793 ) -  
794 ), -  
795 "id", -  
796 data -  
797 ] -  
798 ) -  
799 ), -  
800 "callback", wasURLEscape(URL) -  
801 ] -  
802 ) -  
803 ); -  
804 llSetTimerEvent(60); -  
805 } -  
806 http_request(key id, string method, string body) { -  
807 llHTTPResponse(id, 200, "OK"); -  
808 llReleaseURL(URL); -  
809 if(wasKeyValueGet("command", body) != "database" || -  
810 wasKeyValueGet("success", body) != "True") { 639 action = "search";
811 // DEBUG -  
812 llOwnerSay("[Joke] Unable modify database: " + -  
813 wasURLUnescape( -  
814 wasKeyValueGet("error", body) -  
815 ) 640 state trampoline;
816 ); 641 }
817 state listen_group; 642  
818 } 643 if((integer)index <= 0) {
819 --joke_counter; 644 action = "random";
Line 832... Line 657...
832 (change & CHANGED_REGION_START) || 657 (change & CHANGED_REGION_START) ||
833 (change & CHANGED_OWNER)) { 658 (change & CHANGED_OWNER)) {
834 llResetScript(); 659 llResetScript();
835 } 660 }
836 } 661 }
837 state_exit() { -  
838 llSetTimerEvent(0); -  
839 } -  
840 } 662 }
Line 841... Line 663...
841 663  
842 state tell { 664 state tell {
843 state_entry() { 665 state_entry() {