corrade-lsl-templates – Blame information for rev 42
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
15 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
42 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
15 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // A module that bans group members using fuzzy name matching. |
||
6 | // |
||
7 | /////////////////////////////////////////////////////////////////////////// |
||
8 | |||
9 | /////////////////////////////////////////////////////////////////////////// |
||
41 | office | 10 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
15 | office | 11 | /////////////////////////////////////////////////////////////////////////// |
12 | string wasKeyValueGet(string k, string data) { |
||
13 | if(llStringLength(data) == 0) return ""; |
||
14 | if(llStringLength(k) == 0) return ""; |
||
42 | office | 15 | list a = llParseString2List(data, ["&", "="], []); |
41 | office | 16 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
17 | if(i != -1) return llList2String(a, 2*i+1); |
||
15 | office | 18 | return ""; |
19 | } |
||
20 | |||
21 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 23 | /////////////////////////////////////////////////////////////////////////// |
24 | string wasKeyValueEncode(list data) { |
||
25 | list k = llList2ListStrided(data, 0, -1, 2); |
||
26 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
||
27 | data = []; |
||
28 | do { |
||
29 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
||
30 | k = llDeleteSubList(k, 0, 0); |
||
31 | v = llDeleteSubList(v, 0, 0); |
||
32 | } while(llGetListLength(k) != 0); |
||
33 | return llDumpList2String(data, "&"); |
||
34 | } |
||
35 | |||
36 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 38 | /////////////////////////////////////////////////////////////////////////// |
39 | // http://was.fm/secondlife/wanderer |
||
40 | vector wasCirclePoint(float radius) { |
||
41 | float x = 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)) |
||
44 | return <x, y, 0>; |
||
45 | return wasCirclePoint(radius); |
||
46 | } |
||
47 | |||
48 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 50 | /////////////////////////////////////////////////////////////////////////// |
51 | // escapes a string in conformance with RFC1738 |
||
52 | string wasURLEscape(string i) { |
||
53 | string o = ""; |
||
54 | do { |
||
55 | string c = llGetSubString(i, 0, 0); |
||
56 | i = llDeleteSubString(i, 0, 0); |
||
57 | if(c == "") jump continue; |
||
58 | if(c == " ") { |
||
59 | o += "+"; |
||
60 | jump continue; |
||
61 | } |
||
62 | if(c == "\n") { |
||
63 | o += "%0D" + llEscapeURL(c); |
||
64 | jump continue; |
||
65 | } |
||
66 | o += llEscapeURL(c); |
||
67 | @continue; |
||
68 | } while(i != ""); |
||
69 | return o; |
||
70 | } |
||
71 | |||
72 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 74 | /////////////////////////////////////////////////////////////////////////// |
75 | list wasCSVToList(string csv) { |
||
76 | list l = []; |
||
77 | list s = []; |
||
78 | string m = ""; |
||
79 | do { |
||
80 | string a = llGetSubString(csv, 0, 0); |
||
81 | csv = llDeleteSubString(csv, 0, 0); |
||
82 | if(a == ",") { |
||
83 | if(llList2String(s, -1) != "\"") { |
||
84 | l += m; |
||
85 | m = ""; |
||
86 | jump continue; |
||
87 | } |
||
88 | m += a; |
||
89 | jump continue; |
||
90 | } |
||
91 | if(a == "\"" && llGetSubString(csv, 0, 0) == a) { |
||
92 | m += a; |
||
93 | csv = llDeleteSubString(csv, 0, 0); |
||
94 | jump continue; |
||
95 | } |
||
96 | if(a == "\"") { |
||
97 | if(llList2String(s, -1) != a) { |
||
98 | s += a; |
||
99 | jump continue; |
||
100 | } |
||
101 | s = llDeleteSubList(s, -1, -1); |
||
102 | jump continue; |
||
103 | } |
||
104 | m += a; |
||
105 | @continue; |
||
106 | } while(csv != ""); |
||
107 | // postcondition: length(s) = 0 |
||
108 | return l + m; |
||
109 | } |
||
110 | |||
111 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 113 | /////////////////////////////////////////////////////////////////////////// |
114 | string wasListToCSV(list l) { |
||
115 | list v = []; |
||
116 | do { |
||
117 | string a = llDumpList2String( |
||
118 | llParseStringKeepNulls( |
||
119 | llList2String( |
||
120 | l, |
||
121 | |||
122 | ), |
||
123 | ["\""], |
||
124 | [] |
||
125 | ), |
||
126 | "\"\"" |
||
127 | ); |
||
128 | if(llParseStringKeepNulls( |
||
129 | a, |
||
130 | [" ", ",", "\n", "\""], [] |
||
131 | ) != |
||
132 | (list) a |
||
133 | ) a = "\"" + a + "\""; |
||
134 | v += a; |
||
135 | l = llDeleteSubList(l, 0, 0); |
||
136 | } while(l != []); |
||
137 | return llDumpList2String(v, ","); |
||
138 | } |
||
139 | |||
140 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 142 | /////////////////////////////////////////////////////////////////////////// |
143 | // unescapes a string in conformance with RFC1738 |
||
144 | string wasURLUnescape(string i) { |
||
145 | return llUnescapeURL( |
||
146 | llDumpList2String( |
||
147 | llParseString2List( |
||
148 | llDumpList2String( |
||
149 | llParseString2List( |
||
150 | i, |
||
151 | ["+"], |
||
152 | [] |
||
153 | ), |
||
154 | " " |
||
155 | ), |
||
156 | ["%0D%0A"], |
||
157 | [] |
||
158 | ), |
||
159 | "\n" |
||
160 | ) |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 165 | // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 166 | /////////////////////////////////////////////////////////////////////////// |
167 | list wasSetIntersect(list a, list b) { |
||
168 | if(llGetListLength(a) == 0) return []; |
||
169 | string i = llList2String(a, 0); |
||
170 | a = llDeleteSubList(a, 0, 0); |
||
171 | if(llListFindList(b, (list)i) == -1) |
||
172 | return wasSetIntersect(a, b); |
||
173 | return i + wasSetIntersect(a, b); |
||
174 | } |
||
175 | |||
176 | // configuration data |
||
177 | string configuration = ""; |
||
178 | // store message over state. |
||
179 | string data = ""; |
||
180 | // banee |
||
181 | string firstname = ""; |
||
182 | string lastname = ""; |
||
183 | integer bantime = 4320; |
||
184 | |||
185 | default { |
||
186 | state_entry() { |
||
187 | llOwnerSay("[Softban] Starting..."); |
||
188 | llSetTimerEvent(10); |
||
189 | } |
||
190 | link_message(integer sender, integer num, string message, key id) { |
||
191 | if(id != "configuration") return; |
||
192 | llOwnerSay("[Softban] Got configuration..."); |
||
193 | configuration = message; |
||
194 | state listen_group; |
||
195 | } |
||
196 | timer() { |
||
197 | llOwnerSay("[Softban] Requesting configuration..."); |
||
198 | llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); |
||
199 | } |
||
200 | on_rez(integer num) { |
||
201 | llResetScript(); |
||
202 | } |
||
203 | changed(integer change) { |
||
204 | if((change & CHANGED_INVENTORY) || |
||
205 | (change & CHANGED_REGION_START) || |
||
206 | (change & CHANGED_OWNER)) { |
||
207 | llResetScript(); |
||
208 | } |
||
209 | } |
||
210 | state_exit() { |
||
211 | llSetTimerEvent(0); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | state listen_group { |
||
216 | state_entry() { |
||
217 | // DEBUG |
||
218 | llOwnerSay("[Softban] Waiting for group messages..."); |
||
219 | } |
||
220 | link_message(integer sender, integer num, string message, key id) { |
||
221 | // We only care about notifications now. |
||
222 | if(id != "notification") |
||
223 | return; |
||
224 | |||
225 | // This script only processes group notifications. |
||
42 | office | 226 | if(wasKeyValueGet("type", message) != "group" || |
227 | (wasKeyValueGet("type", message) == "group" && |
||
228 | wasURLUnescape(wasKeyValueGet("group", message)) != |
||
229 | wasKeyValueGet("group", configuration))) |
||
15 | office | 230 | return; |
231 | |||
232 | // Get the sent message. |
||
233 | data = wasURLUnescape( |
||
234 | wasKeyValueGet( |
||
235 | "message", |
||
236 | message |
||
237 | ) |
||
238 | ); |
||
239 | |||
240 | // Check if this is an eggdrop command. |
||
241 | if(llGetSubString(data, 0, 0) != |
||
242 | wasKeyValueGet("command", configuration)) |
||
243 | return; |
||
244 | |||
245 | // Check if the command matches the current module. |
||
246 | list command = llParseString2List(data, [" "], []); |
||
247 | if(llList2String(command, 0) != |
||
248 | wasKeyValueGet("command", configuration) + "softban") |
||
249 | return; |
||
250 | |||
251 | // Remove command. |
||
252 | command = llDeleteSubList(command, 0, 0); |
||
253 | |||
254 | firstname = wasKeyValueGet("firstname", message); |
||
255 | lastname = wasKeyValueGet("lastname", message); |
||
256 | |||
257 | if(firstname == "" || lastname == "") { |
||
258 | data = "And who would yarr be?"; |
||
259 | state tell; |
||
260 | } |
||
261 | |||
262 | // Dump the rest of the message. |
||
263 | data = llDumpList2String(command, " "); |
||
264 | |||
42 | office | 265 | // Get roles of callers. |
15 | office | 266 | state get_caller_roles; |
267 | } |
||
268 | on_rez(integer num) { |
||
269 | llResetScript(); |
||
270 | } |
||
271 | changed(integer change) { |
||
272 | if((change & CHANGED_INVENTORY) || |
||
273 | (change & CHANGED_REGION_START) || |
||
274 | (change & CHANGED_OWNER)) { |
||
275 | llResetScript(); |
||
276 | } |
||
277 | } |
||
278 | } |
||
279 | |||
280 | state get_caller_roles { |
||
281 | state_entry() { |
||
282 | // DEBUG |
||
283 | llOwnerSay("[Softban] Searching for caller..."); |
||
284 | llInstantMessage( |
||
285 | wasKeyValueGet( |
||
286 | "corrade", |
||
287 | configuration |
||
288 | ), |
||
289 | wasKeyValueEncode( |
||
290 | [ |
||
291 | "command", "getmemberroles", |
||
292 | "group", wasURLEscape( |
||
293 | wasKeyValueGet( |
||
294 | "group", |
||
295 | configuration |
||
296 | ) |
||
297 | ), |
||
298 | "password", wasURLEscape( |
||
299 | wasKeyValueGet( |
||
300 | "password", |
||
301 | configuration |
||
302 | ) |
||
303 | ), |
||
304 | "firstname", firstname, |
||
305 | "lastname", lastname, |
||
42 | office | 306 | "callback", wasURLEscape( |
307 | wasKeyValueGet( |
||
308 | "URL", |
||
309 | configuration |
||
310 | ) |
||
311 | ) |
||
15 | office | 312 | ] |
313 | ) |
||
314 | ); |
||
315 | llSetTimerEvent(60); |
||
316 | } |
||
42 | office | 317 | link_message(integer sender, integer num, string body, key id) { |
318 | // Only process callbacks for the database command. |
||
319 | if(id != "callback" || wasKeyValueGet("command", body) != "getmemberroles") |
||
320 | return; |
||
321 | |||
322 | if(wasKeyValueGet("success", body) != "True") { |
||
15 | office | 323 | // DEBUG |
324 | llOwnerSay("[Softban] Unable to get member roles: " + |
||
325 | wasURLUnescape( |
||
326 | wasKeyValueGet("error", body) |
||
327 | ) |
||
328 | ); |
||
329 | state listen_group; |
||
330 | } |
||
331 | |||
332 | // Dump the roles to a list. |
||
333 | list roles = wasCSVToList( |
||
334 | wasURLUnescape( |
||
335 | wasKeyValueGet("data", body) |
||
336 | ) |
||
337 | ); |
||
338 | |||
339 | if(llGetListLength( |
||
340 | wasSetIntersect(roles, |
||
341 | wasCSVToList( |
||
342 | wasKeyValueGet( |
||
343 | "admin roles", configuration |
||
344 | ) |
||
345 | ) |
||
346 | ) |
||
347 | ) == 0) { |
||
348 | data = "You ain't got the cojones!"; |
||
349 | state tell; |
||
350 | } |
||
351 | |||
352 | list banee = llParseString2List(data, [" "], []); |
||
353 | |||
354 | firstname = llList2String(banee, 0); |
||
355 | banee = llDeleteSubList(banee, 0, 0); |
||
356 | lastname = llList2String(banee, 0); |
||
357 | banee = llDeleteSubList(banee, 0, 0); |
||
358 | |||
359 | if(firstname == "" || lastname == "") { |
||
360 | data = "Full name required."; |
||
361 | state tell; |
||
362 | } |
||
363 | |||
364 | if(llGetListLength(banee) != 0 && llList2Integer(banee, 0) != 0) { |
||
365 | bantime = llList2Integer(banee, 0); |
||
366 | banee = llDeleteSubList(banee, 0, 0); |
||
367 | } |
||
368 | |||
369 | // GC |
||
370 | banee = []; |
||
371 | state get_banee_roles; |
||
372 | } |
||
373 | timer() { |
||
374 | state listen_group; |
||
375 | } |
||
376 | on_rez(integer num) { |
||
377 | llResetScript(); |
||
378 | } |
||
379 | changed(integer change) { |
||
380 | if((change & CHANGED_INVENTORY) || |
||
381 | (change & CHANGED_REGION_START) || |
||
382 | (change & CHANGED_OWNER)) { |
||
383 | llResetScript(); |
||
384 | } |
||
385 | } |
||
386 | state_exit() { |
||
387 | llSetTimerEvent(0); |
||
388 | } |
||
389 | } |
||
390 | |||
391 | state get_banee_roles { |
||
392 | state_entry() { |
||
393 | // DEBUG |
||
394 | llOwnerSay("[Softban] Searching for banee..."); |
||
395 | llInstantMessage( |
||
396 | wasKeyValueGet( |
||
397 | "corrade", |
||
398 | configuration |
||
399 | ), |
||
400 | wasKeyValueEncode( |
||
401 | [ |
||
402 | "command", "getmemberroles", |
||
403 | "group", wasURLEscape( |
||
404 | wasKeyValueGet( |
||
405 | "group", |
||
406 | configuration |
||
407 | ) |
||
408 | ), |
||
409 | "password", wasURLEscape( |
||
410 | wasKeyValueGet( |
||
411 | "password", |
||
412 | configuration |
||
413 | ) |
||
414 | ), |
||
415 | "firstname", firstname, |
||
416 | "lastname", lastname, |
||
42 | office | 417 | "callback", wasURLEscape( |
418 | wasKeyValueGet( |
||
419 | "URL", |
||
420 | configuration |
||
421 | ) |
||
422 | ) |
||
15 | office | 423 | ] |
424 | ) |
||
425 | ); |
||
426 | llSetTimerEvent(60); |
||
427 | } |
||
42 | office | 428 | link_message(integer sender, integer num, string body, key id) { |
429 | // Only process callbacks for the database command. |
||
430 | if(id != "callback" || wasKeyValueGet("command", body) != "getmemberroles") |
||
431 | return; |
||
432 | |||
433 | if(wasKeyValueGet("success", body) != "True") { |
||
15 | office | 434 | if(wasKeyValueGet("status", body) == "19862") { |
435 | // DEBUG |
||
436 | llOwnerSay("[Softban] User not in group, but proceeding anyway..."); |
||
437 | jump continue; |
||
438 | } |
||
439 | // DEBUG |
||
440 | llOwnerSay("[Softban] Unable to get member roles: " + |
||
441 | wasURLUnescape( |
||
442 | wasKeyValueGet("error", body) |
||
443 | ) |
||
444 | ); |
||
445 | state listen_group; |
||
446 | } |
||
447 | |||
448 | @continue; |
||
449 | string result = wasURLUnescape( |
||
450 | wasKeyValueGet("data", body) |
||
451 | ); |
||
452 | |||
453 | if(result != "" && llListFindList(wasCSVToList(result), (list)"Owners") != -1) { |
||
454 | data = "Ejectee is an owner. I'm not gunna open the pod bay doors."; |
||
455 | state tell; |
||
456 | } |
||
457 | |||
458 | state ban; |
||
459 | } |
||
460 | timer() { |
||
461 | state listen_group; |
||
462 | } |
||
463 | on_rez(integer num) { |
||
464 | llResetScript(); |
||
465 | } |
||
466 | changed(integer change) { |
||
467 | if((change & CHANGED_INVENTORY) || |
||
468 | (change & CHANGED_REGION_START) || |
||
469 | (change & CHANGED_OWNER)) { |
||
470 | llResetScript(); |
||
471 | } |
||
472 | } |
||
473 | state_exit() { |
||
474 | llSetTimerEvent(0); |
||
475 | } |
||
476 | } |
||
477 | |||
478 | state ban { |
||
479 | state_entry() { |
||
480 | // DEBUG |
||
481 | llOwnerSay("[Softban] Banning..."); |
||
482 | llInstantMessage( |
||
483 | wasKeyValueGet( |
||
484 | "corrade", |
||
485 | configuration |
||
486 | ), |
||
487 | wasKeyValueEncode( |
||
488 | [ |
||
489 | "command", "softban", |
||
490 | "group", wasURLEscape( |
||
491 | wasKeyValueGet( |
||
492 | "group", |
||
493 | configuration |
||
494 | ) |
||
495 | ), |
||
496 | "password", wasURLEscape( |
||
497 | wasKeyValueGet( |
||
498 | "password", |
||
499 | configuration |
||
500 | ) |
||
501 | ), |
||
502 | "action", "ban", |
||
503 | "avatars", wasURLEscape( |
||
504 | wasListToCSV( |
||
505 | [ |
||
506 | firstname + " " + lastname |
||
507 | ] |
||
508 | ) |
||
509 | ), |
||
510 | "time", wasURLEscape( |
||
511 | wasListToCSV( |
||
512 | [ |
||
513 | bantime |
||
514 | ] |
||
515 | ) |
||
516 | ), |
||
42 | office | 517 | "callback", wasURLEscape( |
518 | wasKeyValueGet( |
||
519 | "URL", |
||
520 | configuration |
||
521 | ) |
||
522 | ) |
||
15 | office | 523 | ] |
524 | ) |
||
525 | ); |
||
526 | llSetTimerEvent(60); |
||
527 | } |
||
42 | office | 528 | link_message(integer sender, integer num, string body, key id) { |
529 | // Only process callbacks for the database command. |
||
530 | if(id != "callback" || wasKeyValueGet("command", body) != "softban") |
||
531 | return; |
||
532 | |||
15 | office | 533 | if(wasKeyValueGet("command", body) != "softban" || |
534 | wasKeyValueGet("success", body) != "True") { |
||
535 | // DEBUG |
||
536 | llOwnerSay("[Softban] Unable to soft ban member: " + |
||
537 | wasURLUnescape( |
||
538 | wasKeyValueGet("error", body) |
||
539 | ) |
||
540 | ); |
||
541 | state listen_group; |
||
542 | } |
||
543 | |||
544 | data = "Hasta la vista, baby!"; |
||
545 | |||
546 | state tell; |
||
547 | } |
||
548 | timer() { |
||
549 | state listen_group; |
||
550 | } |
||
551 | on_rez(integer num) { |
||
552 | llResetScript(); |
||
553 | } |
||
554 | changed(integer change) { |
||
555 | if((change & CHANGED_INVENTORY) || |
||
556 | (change & CHANGED_REGION_START) || |
||
557 | (change & CHANGED_OWNER)) { |
||
558 | llResetScript(); |
||
559 | } |
||
560 | } |
||
561 | state_exit() { |
||
562 | llSetTimerEvent(0); |
||
563 | } |
||
564 | } |
||
565 | |||
566 | state tell { |
||
567 | state_entry() { |
||
568 | // DEBUG |
||
569 | llOwnerSay("[Softban] Sending to group."); |
||
570 | llInstantMessage( |
||
571 | wasKeyValueGet( |
||
572 | "corrade", |
||
573 | configuration |
||
574 | ), |
||
575 | wasKeyValueEncode( |
||
576 | [ |
||
577 | "command", "tell", |
||
578 | "group", wasURLEscape( |
||
579 | wasKeyValueGet( |
||
580 | "group", |
||
581 | configuration |
||
582 | ) |
||
583 | ), |
||
584 | "password", wasURLEscape( |
||
585 | wasKeyValueGet( |
||
586 | "password", |
||
587 | configuration |
||
588 | ) |
||
589 | ), |
||
590 | "entity", "group", |
||
591 | "message", wasURLEscape(data) |
||
592 | ] |
||
593 | ) |
||
594 | ); |
||
595 | |||
596 | // reset variables. |
||
597 | bantime = 4320; |
||
598 | |||
599 | state listen_group; |
||
600 | } |
||
601 | } |