corrade-lsl-templates – Diff between revs 15 and 24
?pathlinks?
Rev 15 | Rev 24 | |||
---|---|---|---|---|
Line 3... | Line 3... | |||
3 | /////////////////////////////////////////////////////////////////////////// |
3 | /////////////////////////////////////////////////////////////////////////// |
|
4 | // |
4 | // |
|
5 | // A MOTD module for Corrade Eggdrop. |
5 | // A MOTD module for Corrade Eggdrop. |
|
6 | // |
6 | // |
|
7 | /////////////////////////////////////////////////////////////////////////// |
7 | /////////////////////////////////////////////////////////////////////////// |
|
8 | |
8 | |
|
9 | /////////////////////////////////////////////////////////////////////////// |
9 | /////////////////////////////////////////////////////////////////////////// |
|
10 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
10 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
|
11 | /////////////////////////////////////////////////////////////////////////// |
11 | /////////////////////////////////////////////////////////////////////////// |
|
12 | string wasKeyValueGet(string k, string data) { |
12 | string wasKeyValueGet(string k, string data) { |
|
13 | if(llStringLength(data) == 0) return ""; |
13 | if(llStringLength(data) == 0) return ""; |
|
Line 30... | Line 30... | |||
30 | k = llDeleteSubList(k, 0, 0); |
30 | k = llDeleteSubList(k, 0, 0); |
|
31 | v = llDeleteSubList(v, 0, 0); |
31 | v = llDeleteSubList(v, 0, 0); |
|
32 | } while(llGetListLength(k) != 0); |
32 | } while(llGetListLength(k) != 0); |
|
33 | return llDumpList2String(data, "&"); |
33 | return llDumpList2String(data, "&"); |
|
34 | } |
34 | } |
|
35 | |
35 | |
|
36 | /////////////////////////////////////////////////////////////////////////// |
36 | /////////////////////////////////////////////////////////////////////////// |
|
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
|
38 | /////////////////////////////////////////////////////////////////////////// |
38 | /////////////////////////////////////////////////////////////////////////// |
|
39 | // http://was.fm/secondlife/wanderer |
39 | // http://was.fm/secondlife/wanderer |
|
40 | vector wasCirclePoint(float radius) { |
40 | vector wasCirclePoint(float radius) { |
|
Line 42... | Line 42... | |||
42 | float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
42 | float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
|
43 | if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) |
43 | if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) |
|
44 | return <x, y, 0>; |
44 | return <x, y, 0>; |
|
45 | return wasCirclePoint(radius); |
45 | return wasCirclePoint(radius); |
|
46 | } |
46 | } |
|
47 | |
47 | |
|
48 | /////////////////////////////////////////////////////////////////////////// |
48 | /////////////////////////////////////////////////////////////////////////// |
|
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
50 | /////////////////////////////////////////////////////////////////////////// |
50 | /////////////////////////////////////////////////////////////////////////// |
|
51 | // escapes a string in conformance with RFC1738 |
51 | // escapes a string in conformance with RFC1738 |
|
52 | string wasURLEscape(string i) { |
52 | string wasURLEscape(string i) { |
|
Line 66... | Line 66... | |||
66 | o += llEscapeURL(c); |
66 | o += llEscapeURL(c); |
|
67 | @continue; |
67 | @continue; |
|
68 | } while(i != ""); |
68 | } while(i != ""); |
|
69 | return o; |
69 | return o; |
|
70 | } |
70 | } |
|
71 | |
71 | |
|
72 | /////////////////////////////////////////////////////////////////////////// |
72 | /////////////////////////////////////////////////////////////////////////// |
|
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
74 | /////////////////////////////////////////////////////////////////////////// |
74 | /////////////////////////////////////////////////////////////////////////// |
|
75 | list wasCSVToList(string csv) { |
75 | list wasCSVToList(string csv) { |
|
76 | list l = []; |
76 | list l = []; |
|
Line 105... | Line 105... | |||
105 | @continue; |
105 | @continue; |
|
106 | } while(csv != ""); |
106 | } while(csv != ""); |
|
107 | // postcondition: length(s) = 0 |
107 | // postcondition: length(s) = 0 |
|
108 | return l + m; |
108 | return l + m; |
|
109 | } |
109 | } |
|
110 | |
110 | |
|
111 | /////////////////////////////////////////////////////////////////////////// |
111 | /////////////////////////////////////////////////////////////////////////// |
|
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
113 | /////////////////////////////////////////////////////////////////////////// |
113 | /////////////////////////////////////////////////////////////////////////// |
|
114 | string wasListToCSV(list l) { |
114 | string wasListToCSV(list l) { |
|
115 | list v = []; |
115 | list v = []; |
|
Line 134... | Line 134... | |||
134 | v += a; |
134 | v += a; |
|
135 | l = llDeleteSubList(l, 0, 0); |
135 | l = llDeleteSubList(l, 0, 0); |
|
136 | } while(l != []); |
136 | } while(l != []); |
|
137 | return llDumpList2String(v, ","); |
137 | return llDumpList2String(v, ","); |
|
138 | } |
138 | } |
|
139 | |
139 | |
|
140 | /////////////////////////////////////////////////////////////////////////// |
140 | /////////////////////////////////////////////////////////////////////////// |
|
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
142 | /////////////////////////////////////////////////////////////////////////// |
142 | /////////////////////////////////////////////////////////////////////////// |
|
143 | // unescapes a string in conformance with RFC1738 |
143 | // unescapes a string in conformance with RFC1738 |
|
144 | string wasURLUnescape(string i) { |
144 | string wasURLUnescape(string i) { |
|
Line 158... | Line 158... | |||
158 | ), |
158 | ), |
|
159 | "\n" |
159 | "\n" |
|
160 | ) |
160 | ) |
|
161 | ); |
161 | ); |
|
162 | } |
162 | } |
|
163 | |
163 | |
|
164 | // configuration data |
164 | // configuration data |
|
165 | string configuration = ""; |
165 | string configuration = ""; |
|
166 | // callback URL |
166 | // callback URL |
|
167 | string URL = ""; |
167 | string URL = ""; |
|
168 | // store message over state. |
168 | // store message over state. |
|
169 | string firstname = ""; |
169 | string firstname = ""; |
|
170 | string lastname = ""; |
170 | string lastname = ""; |
|
171 | string group = ""; |
171 | string group = ""; |
|
172 | string data = ""; |
172 | string data = ""; |
|
173 | string jump_state = ""; |
173 | string jump_state = ""; |
|
174 | |
174 | |
|
175 | default { |
175 | default { |
|
176 | state_entry() { |
176 | state_entry() { |
|
177 | llOwnerSay("[MOTD] Starting module..."); |
177 | llOwnerSay("[MOTD] Starting module..."); |
|
178 | llSetTimerEvent(10); |
178 | llSetTimerEvent(10); |
|
179 | } |
179 | } |
|
Line 200... | Line 200... | |||
200 | } |
200 | } |
|
201 | state_exit() { |
201 | state_exit() { |
|
202 | llSetTimerEvent(0); |
202 | llSetTimerEvent(0); |
|
203 | } |
203 | } |
|
204 | } |
204 | } |
|
205 | |
205 | |
|
206 | state url { |
206 | state url { |
|
207 | state_entry() { |
207 | state_entry() { |
|
208 | // DEBUG |
208 | // DEBUG |
|
209 | llOwnerSay("[MOTD] Requesting URL..."); |
209 | llOwnerSay("[MOTD] Requesting URL..."); |
|
210 | llRequestURL(); |
210 | llRequestURL(); |
|
Line 222... | Line 222... | |||
222 | state get; |
222 | state get; |
|
223 | if(jump_state == "set") |
223 | if(jump_state == "set") |
|
224 | state set; |
224 | state set; |
|
225 | if(jump_state == "listen_group") |
225 | if(jump_state == "listen_group") |
|
226 | state listen_group; |
226 | state listen_group; |
|
227 | |
227 | |
|
228 | // DEBUG |
228 | // DEBUG |
|
229 | llOwnerSay("[MOTD] Jump table corrupted, please contact creator..."); |
229 | llOwnerSay("[MOTD] Jump table corrupted, please contact creator..."); |
|
230 | llResetScript(); |
230 | llResetScript(); |
|
231 | } |
231 | } |
|
232 | on_rez(integer num) { |
232 | on_rez(integer num) { |
|
Line 238... | Line 238... | |||
238 | (change & CHANGED_OWNER)) { |
238 | (change & CHANGED_OWNER)) { |
|
239 | llResetScript(); |
239 | llResetScript(); |
|
240 | } |
240 | } |
|
241 | } |
241 | } |
|
242 | } |
242 | } |
|
243 | |
243 | |
|
244 | state create_database { |
244 | state create_database { |
|
245 | state_entry() { |
245 | state_entry() { |
|
246 | // DEBUG |
246 | // DEBUG |
|
247 | llOwnerSay("[MOTD] Creating database."); |
247 | llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration)); |
|
248 | llInstantMessage( |
248 | llInstantMessage( |
|
249 | wasKeyValueGet( |
249 | wasKeyValueGet( |
|
250 | "corrade", |
250 | "corrade", |
|
251 | configuration |
251 | configuration |
|
252 | ), |
252 | ), |
|
Line 281... | Line 281... | |||
281 | wasKeyValueGet("success", body) != "True") { |
281 | wasKeyValueGet("success", body) != "True") { |
|
282 | // DEBUG |
282 | // DEBUG |
|
283 | llOwnerSay("[MOTD] Unable modify database: " + |
283 | llOwnerSay("[MOTD] Unable modify database: " + |
|
284 | wasURLUnescape( |
284 | wasURLUnescape( |
|
285 | wasKeyValueGet("error", body) |
285 | wasKeyValueGet("error", body) |
|
- | 286 | ) + |
||
- | 287 | " " + |
||
- | 288 | wasURLUnescape( |
||
- | 289 | wasKeyValueGet("data", body) |
||
286 | ) |
290 | ) |
|
- | 291 | |
||
287 | ); |
292 | ); |
|
288 | llResetScript(); |
293 | llResetScript(); |
|
289 | } |
294 | } |
|
290 | llOwnerSay("[MOTD] Database created!"); |
295 | llOwnerSay("[MOTD] Database created!"); |
|
291 | state listen_group; |
296 | state listen_group; |
|
Line 306... | Line 311... | |||
306 | } |
311 | } |
|
307 | state_exit() { |
312 | state_exit() { |
|
308 | llSetTimerEvent(0); |
313 | llSetTimerEvent(0); |
|
309 | } |
314 | } |
|
310 | } |
315 | } |
|
311 | |
316 | |
|
312 | |
317 | |
|
313 | state listen_group { |
318 | state listen_group { |
|
314 | state_entry() { |
319 | state_entry() { |
|
315 | // DEBUG |
320 | // DEBUG |
|
316 | llOwnerSay("[MOTD] Waiting for group messages and new group members."); |
321 | llOwnerSay("[MOTD] Waiting for group messages and new group members."); |
|
317 | } |
322 | } |
|
318 | link_message(integer sender, integer num, string message, key id) { |
323 | link_message(integer sender, integer num, string message, key id) { |
|
319 | // We only care about notifications now. |
324 | // We only care about notifications now. |
|
320 | if(id != "notification") |
325 | if(id != "notification") |
|
321 | return; |
326 | return; |
|
322 | |
327 | |
|
323 | // Get the group. |
328 | // Get the group. |
|
324 | group = wasURLUnescape( |
329 | group = wasURLUnescape( |
|
325 | wasKeyValueGet( |
330 | wasKeyValueGet( |
|
326 | "group", |
331 | "group", |
|
327 | message |
332 | message |
|
328 | ) |
333 | ) |
|
329 | ); |
334 | ); |
|
330 | |
335 | |
|
331 | // Retrieve the membership notification. |
336 | // Retrieve the membership notification. |
|
332 | if(wasKeyValueGet("type", message) == "membership" && |
337 | if(wasKeyValueGet("type", message) == "membership" && |
|
333 | wasKeyValueGet("action", message) == "joined") { |
338 | wasKeyValueGet("action", message) == "joined") { |
|
334 | firstname = wasURLUnescape( |
339 | firstname = wasURLUnescape( |
|
335 | wasKeyValueGet( |
340 | wasKeyValueGet( |
|
Line 344... | Line 349... | |||
344 | ) |
349 | ) |
|
345 | ); |
350 | ); |
|
346 | jump_state = "greet"; |
351 | jump_state = "greet"; |
|
347 | state url; |
352 | state url; |
|
348 | } |
353 | } |
|
349 | |
354 | |
|
350 | // This script only processes group notifications. |
355 | // This script only processes group notifications. |
|
351 | if(wasKeyValueGet("type", message) != "group") |
356 | if(wasKeyValueGet("type", message) != "group") |
|
352 | return; |
357 | return; |
|
353 | |
358 | |
|
354 | // Get the sent message. |
359 | // Get the sent message. |
|
355 | data = wasURLUnescape( |
360 | data = wasURLUnescape( |
|
356 | wasKeyValueGet( |
361 | wasKeyValueGet( |
|
357 | "message", |
362 | "message", |
|
358 | message |
363 | message |
|
359 | ) |
364 | ) |
|
360 | ); |
365 | ); |
|
361 | |
366 | |
|
362 | // Check if this is an eggdrop command. |
367 | // Check if this is an eggdrop command. |
|
363 | if(llGetSubString(data, 0, 0) != |
368 | if(llGetSubString(data, 0, 0) != |
|
364 | wasKeyValueGet("command", configuration)) |
369 | wasKeyValueGet("command", configuration)) |
|
365 | return; |
370 | return; |
|
366 | |
371 | |
|
367 | // Check if the command matches the current module. |
372 | // Check if the command matches the current module. |
|
368 | list command = llParseString2List(data, [" "], []); |
373 | list command = llParseString2List(data, [" "], []); |
|
369 | if(llList2String(command, 0) != |
374 | if(llList2String(command, 0) != |
|
370 | wasKeyValueGet("command", configuration) + "motd") |
375 | wasKeyValueGet("command", configuration) + "motd") |
|
371 | return; |
376 | return; |
|
372 | |
377 | |
|
373 | // Remove command. |
378 | // Remove command. |
|
374 | command = llDeleteSubList(command, 0, 0); |
379 | command = llDeleteSubList(command, 0, 0); |
|
375 | |
380 | |
|
376 | // Dump the rest of the message. |
381 | // Dump the rest of the message. |
|
377 | data = llDumpList2String(command, " "); |
382 | data = llDumpList2String(command, " "); |
|
378 | |
383 | |
|
379 | // Get the sent message. |
384 | // Get the sent message. |
|
380 | if(data == "") { |
385 | if(data == "") { |
|
381 | jump_state = "get"; |
386 | jump_state = "get"; |
|
382 | state url; |
387 | state url; |
|
383 | } |
388 | } |
|
384 | |
389 | |
|
385 | jump_state = "set"; |
390 | jump_state = "set"; |
|
386 | state url; |
391 | state url; |
|
387 | } |
392 | } |
|
388 | on_rez(integer num) { |
393 | on_rez(integer num) { |
|
389 | llResetScript(); |
394 | llResetScript(); |
|
Line 394... | Line 399... | |||
394 | (change & CHANGED_OWNER)) { |
399 | (change & CHANGED_OWNER)) { |
|
395 | llResetScript(); |
400 | llResetScript(); |
|
396 | } |
401 | } |
|
397 | } |
402 | } |
|
398 | } |
403 | } |
|
399 | |
404 | |
|
400 | state greet { |
405 | state greet { |
|
401 | state_entry() { |
406 | state_entry() { |
|
402 | // DEBUG |
407 | // DEBUG |
|
403 | llOwnerSay("[MOTD] Member joined, retrieving MOTD..."); |
408 | llOwnerSay("[MOTD] Member joined, retrieving MOTD..."); |
|
404 | llInstantMessage( |
409 | llInstantMessage( |
|
Line 449... | Line 454... | |||
449 | wasKeyValueGet("error", body) |
454 | wasKeyValueGet("error", body) |
|
450 | ) |
455 | ) |
|
451 | ); |
456 | ); |
|
452 | state listen_group; |
457 | state listen_group; |
|
453 | } |
458 | } |
|
454 | |
459 | |
|
455 | data = llDumpList2String( |
460 | data = llDumpList2String( |
|
456 | llDeleteSubList( |
461 | llDeleteSubList( |
|
457 | wasCSVToList( |
462 | wasCSVToList( |
|
458 | wasURLUnescape( |
463 | wasURLUnescape( |
|
459 | wasKeyValueGet("data", body) |
464 | wasKeyValueGet("data", body) |
|
Line 462... | Line 467... | |||
462 | 0, |
467 | 0, |
|
463 | 0 |
468 | 0 |
|
464 | ), |
469 | ), |
|
465 | "" |
470 | "" |
|
466 | ); |
471 | ); |
|
467 | |
472 | |
|
468 | if(data == "") |
473 | if(data == "") |
|
469 | state listen_group; |
474 | state listen_group; |
|
470 | |
475 | |
|
471 | data = "Hello " + firstname + " " + lastname + "!" + " " + data; |
476 | data = "Hello " + firstname + " " + lastname + "!" + " " + data; |
|
472 | state tell; |
477 | state tell; |
|
473 | } |
478 | } |
|
474 | timer() { |
479 | timer() { |
|
475 | llReleaseURL(URL); |
480 | llReleaseURL(URL); |
|
Line 487... | Line 492... | |||
487 | } |
492 | } |
|
488 | state_exit() { |
493 | state_exit() { |
|
489 | llSetTimerEvent(0); |
494 | llSetTimerEvent(0); |
|
490 | } |
495 | } |
|
491 | } |
496 | } |
|
492 | |
497 | |
|
493 | state get { |
498 | state get { |
|
494 | state_entry() { |
499 | state_entry() { |
|
495 | // DEBUG |
500 | // DEBUG |
|
496 | llOwnerSay("[MOTD] Retrieving from database."); |
501 | llOwnerSay("[MOTD] Retrieving from database."); |
|
497 | llInstantMessage( |
502 | llInstantMessage( |
|
Line 519... | Line 524... | |||
519 | "\" WHERE name=:group"), |
524 | "\" WHERE name=:group"), |
|
520 | "data", wasURLEscape( |
525 | "data", wasURLEscape( |
|
521 | wasListToCSV( |
526 | wasListToCSV( |
|
522 | [ |
527 | [ |
|
523 | "group", |
528 | "group", |
|
524 | wasURLEscape(group) |
529 | wasURLEscape( |
|
- | 530 | wasKeyValueGet( |
||
- | 531 | "group", |
||
- | 532 | configuration |
||
- | 533 | ) |
||
- | 534 | ) |
||
525 | ] |
535 | ] |
|
526 | ) |
536 | ) |
|
527 | ), |
537 | ), |
|
528 | "callback", wasURLEscape(URL) |
538 | "callback", wasURLEscape(URL) |
|
529 | ] |
539 | ] |
|
Line 542... | Line 552... | |||
542 | wasKeyValueGet("error", body) |
552 | wasKeyValueGet("error", body) |
|
543 | ) |
553 | ) |
|
544 | ); |
554 | ); |
|
545 | state listen_group; |
555 | state listen_group; |
|
546 | } |
556 | } |
|
547 | |
557 | |
|
548 | data = llDumpList2String( |
558 | data = llDumpList2String( |
|
549 | llDeleteSubList( |
559 | llDeleteSubList( |
|
550 | wasCSVToList( |
560 | wasCSVToList( |
|
551 | wasURLUnescape( |
561 | wasURLUnescape( |
|
552 | wasKeyValueGet("data", body) |
562 | wasKeyValueGet("data", body) |
|
Line 555... | Line 565... | |||
555 | 0, |
565 | 0, |
|
556 | 0 |
566 | 0 |
|
557 | ), |
567 | ), |
|
558 | "" |
568 | "" |
|
559 | ); |
569 | ); |
|
560 | |
570 | |
|
561 | if(data == "") { |
571 | if(data == "") { |
|
562 | data = "Sorry, no MOTD is currently set."; |
572 | data = "Sorry, no MOTD is currently set."; |
|
563 | state tell; |
573 | state tell; |
|
564 | } |
574 | } |
|
565 | |
575 | |
|
566 | state tell; |
576 | state tell; |
|
567 | } |
577 | } |
|
568 | timer() { |
578 | timer() { |
|
569 | llReleaseURL(URL); |
579 | llReleaseURL(URL); |
|
570 | state listen_group; |
580 | state listen_group; |
|
Line 581... | Line 591... | |||
581 | } |
591 | } |
|
582 | state_exit() { |
592 | state_exit() { |
|
583 | llSetTimerEvent(0); |
593 | llSetTimerEvent(0); |
|
584 | } |
594 | } |
|
585 | } |
595 | } |
|
586 | |
596 | |
|
587 | state set { |
597 | state set { |
|
588 | state_entry() { |
598 | state_entry() { |
|
589 | // DEBUG |
599 | // DEBUG |
|
590 | llOwnerSay("[MOTD] Adding to database."); |
600 | llOwnerSay("[MOTD] Adding to database."); |
|
591 | llInstantMessage( |
601 | llInstantMessage( |
|
Line 613... | Line 623... | |||
613 | "\" (name, data) VALUES (:name, :data)"), |
623 | "\" (name, data) VALUES (:name, :data)"), |
|
614 | "data", wasURLEscape( |
624 | "data", wasURLEscape( |
|
615 | wasListToCSV( |
625 | wasListToCSV( |
|
616 | [ |
626 | [ |
|
617 | "name", |
627 | "name", |
|
618 | wasURLEscape(group), |
628 | wasURLEscape( |
|
- | 629 | wasKeyValueGet( |
||
- | 630 | "group", |
||
- | 631 | configuration |
||
- | 632 | ) |
||
- | 633 | ), |
||
619 | "data", |
634 | "data", |
|
620 | wasURLEscape(data) |
635 | wasURLEscape(data) |
|
621 | ] |
636 | ] |
|
622 | ) |
637 | ) |
|
623 | ), |
638 | ), |
|
Line 659... | Line 674... | |||
659 | } |
674 | } |
|
660 | state_exit() { |
675 | state_exit() { |
|
661 | llSetTimerEvent(0); |
676 | llSetTimerEvent(0); |
|
662 | } |
677 | } |
|
663 | } |
678 | } |
|
664 | |
679 | |
|
665 | state tell { |
680 | state tell { |
|
666 | state_entry() { |
681 | state_entry() { |
|
667 | // DEBUG |
682 | // DEBUG |
|
668 | llOwnerSay("[MOTD] Sending to group."); |
683 | llOwnerSay("[MOTD] Sending to group."); |
|
669 | llInstantMessage( |
684 | llInstantMessage( |