corrade-lsl-templates – Blame information for rev 8
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
8 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
||
3 | /////////////////////////////////////////////////////////////////////////// |
||
4 | // |
||
5 | // A module that bans group members using fuzzy name matching. |
||
6 | // |
||
7 | /////////////////////////////////////////////////////////////////////////// |
||
8 | |||
9 | /////////////////////////////////////////////////////////////////////////// |
||
10 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
||
11 | /////////////////////////////////////////////////////////////////////////// |
||
12 | string wasKeyValueGet(string k, string data) { |
||
13 | if(llStringLength(data) == 0) return ""; |
||
14 | if(llStringLength(k) == 0) return ""; |
||
15 | list a = llParseString2List(data, ["&", "="], []); |
||
16 | integer i = llListFindList(a, [ k ]); |
||
17 | if(i != -1) return llList2String(a, i+1); |
||
18 | return ""; |
||
19 | } |
||
20 | |||
21 | /////////////////////////////////////////////////////////////////////////// |
||
22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | /////////////////////////////////////////////////////////////////////////// |
||
165 | // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 // |
||
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 | // callback URL |
||
179 | string URL = ""; |
||
180 | // store message over state. |
||
181 | string data = ""; |
||
182 | // banee |
||
183 | string firstname = ""; |
||
184 | string lastname = ""; |
||
185 | |||
186 | default { |
||
187 | state_entry() { |
||
188 | llOwnerSay("[Ban] Starting..."); |
||
189 | llSetTimerEvent(10); |
||
190 | } |
||
191 | link_message(integer sender, integer num, string message, key id) { |
||
192 | if(id != "configuration") return; |
||
193 | llOwnerSay("[Ban] Got configuration..."); |
||
194 | configuration = message; |
||
195 | state listen_group; |
||
196 | } |
||
197 | timer() { |
||
198 | llOwnerSay("[Ban] Requesting configuration..."); |
||
199 | llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); |
||
200 | } |
||
201 | on_rez(integer num) { |
||
202 | llResetScript(); |
||
203 | } |
||
204 | changed(integer change) { |
||
205 | if((change & CHANGED_INVENTORY) || |
||
206 | (change & CHANGED_REGION_START) || |
||
207 | (change & CHANGED_OWNER)) { |
||
208 | llResetScript(); |
||
209 | } |
||
210 | } |
||
211 | state_exit() { |
||
212 | llSetTimerEvent(0); |
||
213 | } |
||
214 | } |
||
215 | |||
216 | state listen_group { |
||
217 | state_entry() { |
||
218 | // DEBUG |
||
219 | llOwnerSay("[Ban] Waiting for group messages..."); |
||
220 | } |
||
221 | link_message(integer sender, integer num, string message, key id) { |
||
222 | // We only care about notifications now. |
||
223 | if(id != "notification") |
||
224 | return; |
||
225 | |||
226 | // This script only processes group notifications. |
||
227 | if(wasKeyValueGet("type", message) != "group") |
||
228 | return; |
||
229 | |||
230 | // Get the sent message. |
||
231 | data = wasURLUnescape( |
||
232 | wasKeyValueGet( |
||
233 | "message", |
||
234 | message |
||
235 | ) |
||
236 | ); |
||
237 | |||
238 | if(llGetSubString(data, 0, 0) != |
||
239 | wasKeyValueGet("command", configuration)) |
||
240 | return; |
||
241 | |||
242 | list command = llParseString2List(data, ["@", " "], []); |
||
243 | if(llList2String(command, 0) != "ban") |
||
244 | return; |
||
245 | |||
246 | firstname = wasKeyValueGet("firstname", message); |
||
247 | lastname = wasKeyValueGet("lastname", message); |
||
248 | |||
249 | if(firstname == "" || lastname == "") { |
||
250 | data = "And who would yarr be?"; |
||
251 | state tell; |
||
252 | } |
||
253 | |||
254 | // Remove command. |
||
255 | command = llDeleteSubList(command, 0, 0); |
||
256 | |||
257 | // Dump the rest of the message. |
||
258 | data = llDumpList2String(command, " "); |
||
259 | |||
260 | // Get an URL. |
||
261 | state url; |
||
262 | } |
||
263 | on_rez(integer num) { |
||
264 | llResetScript(); |
||
265 | } |
||
266 | changed(integer change) { |
||
267 | if((change & CHANGED_INVENTORY) || |
||
268 | (change & CHANGED_REGION_START) || |
||
269 | (change & CHANGED_OWNER)) { |
||
270 | llResetScript(); |
||
271 | } |
||
272 | } |
||
273 | } |
||
274 | |||
275 | state url { |
||
276 | state_entry() { |
||
277 | // DEBUG |
||
278 | llOwnerSay("[Ban] Requesting URL..."); |
||
279 | llRequestURL(); |
||
280 | } |
||
281 | http_request(key id, string method, string body) { |
||
282 | if(method != URL_REQUEST_GRANTED) return; |
||
283 | URL = body; |
||
284 | // DEBUG |
||
285 | llOwnerSay("[Ban] Got URL..."); |
||
286 | state get_caller_roles; |
||
287 | } |
||
288 | on_rez(integer num) { |
||
289 | llResetScript(); |
||
290 | } |
||
291 | changed(integer change) { |
||
292 | if((change & CHANGED_INVENTORY) || |
||
293 | (change & CHANGED_REGION_START) || |
||
294 | (change & CHANGED_OWNER)) { |
||
295 | llResetScript(); |
||
296 | } |
||
297 | } |
||
298 | } |
||
299 | |||
300 | state get_caller_roles { |
||
301 | state_entry() { |
||
302 | // DEBUG |
||
303 | llOwnerSay("[Ban] Searching for caller..."); |
||
304 | llInstantMessage( |
||
305 | wasKeyValueGet( |
||
306 | "corrade", |
||
307 | configuration |
||
308 | ), |
||
309 | wasKeyValueEncode( |
||
310 | [ |
||
311 | "command", "getmemberroles", |
||
312 | "group", wasURLEscape( |
||
313 | wasKeyValueGet( |
||
314 | "group", |
||
315 | configuration |
||
316 | ) |
||
317 | ), |
||
318 | "password", wasURLEscape( |
||
319 | wasKeyValueGet( |
||
320 | "password", |
||
321 | configuration |
||
322 | ) |
||
323 | ), |
||
324 | "firstname", firstname, |
||
325 | "lastname", lastname, |
||
326 | "callback", wasURLEscape(URL) |
||
327 | ] |
||
328 | ) |
||
329 | ); |
||
330 | llSetTimerEvent(60); |
||
331 | } |
||
332 | http_request(key id, string method, string body) { |
||
333 | llHTTPResponse(id, 200, "OK"); |
||
334 | if(wasKeyValueGet("command", body) != "getmemberroles" || |
||
335 | wasKeyValueGet("success", body) != "True") { |
||
336 | // DEBUG |
||
337 | llOwnerSay("[Ban] Unable to get member roles: " + |
||
338 | wasURLUnescape( |
||
339 | wasKeyValueGet("error", body) |
||
340 | ) |
||
341 | ); |
||
342 | llReleaseURL(URL); |
||
343 | state listen_group; |
||
344 | } |
||
345 | |||
346 | // Dump the roles to a list. |
||
347 | list roles = wasCSVToList( |
||
348 | wasURLUnescape( |
||
349 | wasKeyValueGet("data", body) |
||
350 | ) |
||
351 | ); |
||
352 | |||
353 | if(llGetListLength( |
||
354 | wasSetIntersect(roles, |
||
355 | wasCSVToList( |
||
356 | wasKeyValueGet( |
||
357 | "admin roles", configuration |
||
358 | ) |
||
359 | ) |
||
360 | ) |
||
361 | ) == 0) { |
||
362 | data = "You ain't got the cojones!"; |
||
363 | llReleaseURL(URL); |
||
364 | state tell; |
||
365 | } |
||
366 | |||
367 | list banee = llParseString2List(data, [" "], []); |
||
368 | |||
369 | firstname = llList2String(banee, 0); |
||
370 | lastname = llList2String(banee, 1); |
||
371 | |||
372 | if(firstname == "" || lastname == "") { |
||
373 | data = "Full name required."; |
||
374 | state tell; |
||
375 | } |
||
376 | |||
377 | // GC |
||
378 | banee = []; |
||
379 | state get_banee_roles; |
||
380 | } |
||
381 | timer() { |
||
382 | llReleaseURL(URL); |
||
383 | state listen_group; |
||
384 | } |
||
385 | on_rez(integer num) { |
||
386 | llResetScript(); |
||
387 | } |
||
388 | changed(integer change) { |
||
389 | if((change & CHANGED_INVENTORY) || |
||
390 | (change & CHANGED_REGION_START) || |
||
391 | (change & CHANGED_OWNER)) { |
||
392 | llResetScript(); |
||
393 | } |
||
394 | } |
||
395 | state_exit() { |
||
396 | llSetTimerEvent(0); |
||
397 | } |
||
398 | } |
||
399 | |||
400 | state get_banee_roles { |
||
401 | state_entry() { |
||
402 | // DEBUG |
||
403 | llOwnerSay("[Ban] Searching for banee..."); |
||
404 | llInstantMessage( |
||
405 | wasKeyValueGet( |
||
406 | "corrade", |
||
407 | configuration |
||
408 | ), |
||
409 | wasKeyValueEncode( |
||
410 | [ |
||
411 | "command", "getmemberroles", |
||
412 | "group", wasURLEscape( |
||
413 | wasKeyValueGet( |
||
414 | "group", |
||
415 | configuration |
||
416 | ) |
||
417 | ), |
||
418 | "password", wasURLEscape( |
||
419 | wasKeyValueGet( |
||
420 | "password", |
||
421 | configuration |
||
422 | ) |
||
423 | ), |
||
424 | "firstname", firstname, |
||
425 | "lastname", lastname, |
||
426 | "callback", wasURLEscape(URL) |
||
427 | ] |
||
428 | ) |
||
429 | ); |
||
430 | llSetTimerEvent(60); |
||
431 | } |
||
432 | http_request(key id, string method, string body) { |
||
433 | llHTTPResponse(id, 200, "OK"); |
||
434 | if(wasKeyValueGet("command", body) != "getmemberroles" || |
||
435 | wasKeyValueGet("success", body) != "True") { |
||
436 | // DEBUG |
||
437 | llOwnerSay("[Ban] Unable to get member roles: " + |
||
438 | wasURLUnescape( |
||
439 | wasKeyValueGet("error", body) |
||
440 | ) |
||
441 | ); |
||
442 | llReleaseURL(URL); |
||
443 | state listen_group; |
||
444 | } |
||
445 | |||
446 | string result = wasURLUnescape( |
||
447 | wasKeyValueGet("data", body) |
||
448 | ); |
||
449 | |||
450 | if(result != "" && llListFindList(wasCSVToList(result), (list)"Owners") != -1) { |
||
451 | data = "Ejectee is an owner. I'm not gonna open the pod bay doors."; |
||
452 | llReleaseURL(URL); |
||
453 | state tell; |
||
454 | } |
||
455 | |||
456 | state ban; |
||
457 | } |
||
458 | timer() { |
||
459 | llReleaseURL(URL); |
||
460 | state listen_group; |
||
461 | } |
||
462 | on_rez(integer num) { |
||
463 | llResetScript(); |
||
464 | } |
||
465 | changed(integer change) { |
||
466 | if((change & CHANGED_INVENTORY) || |
||
467 | (change & CHANGED_REGION_START) || |
||
468 | (change & CHANGED_OWNER)) { |
||
469 | llResetScript(); |
||
470 | } |
||
471 | } |
||
472 | state_exit() { |
||
473 | llSetTimerEvent(0); |
||
474 | } |
||
475 | } |
||
476 | |||
477 | state ban { |
||
478 | state_entry() { |
||
479 | // DEBUG |
||
480 | llOwnerSay("[Ban] Banning..."); |
||
481 | llInstantMessage( |
||
482 | wasKeyValueGet( |
||
483 | "corrade", |
||
484 | configuration |
||
485 | ), |
||
486 | wasKeyValueEncode( |
||
487 | [ |
||
488 | "command", "ban", |
||
489 | "group", wasURLEscape( |
||
490 | wasKeyValueGet( |
||
491 | "group", |
||
492 | configuration |
||
493 | ) |
||
494 | ), |
||
495 | "password", wasURLEscape( |
||
496 | wasKeyValueGet( |
||
497 | "password", |
||
498 | configuration |
||
499 | ) |
||
500 | ), |
||
501 | "action", "ban", |
||
502 | "avatars", wasURLEscape( |
||
503 | wasListToCSV( |
||
504 | [ |
||
505 | firstname + " " + lastname |
||
506 | ] |
||
507 | ) |
||
508 | ), |
||
509 | "eject", "True", |
||
510 | "callback", wasURLEscape(URL) |
||
511 | ] |
||
512 | ) |
||
513 | ); |
||
514 | llSetTimerEvent(60); |
||
515 | } |
||
516 | http_request(key id, string method, string body) { |
||
517 | llHTTPResponse(id, 200, "OK"); |
||
518 | llReleaseURL(URL); |
||
519 | if(wasKeyValueGet("command", body) != "ban" || |
||
520 | wasKeyValueGet("success", body) != "True") { |
||
521 | // DEBUG |
||
522 | llOwnerSay("[Ban] Unable to ban member: " + |
||
523 | wasURLUnescape( |
||
524 | wasKeyValueGet("error", body) |
||
525 | ) |
||
526 | ); |
||
527 | state listen_group; |
||
528 | } |
||
529 | |||
530 | data = "Hasta la vista, baby!"; |
||
531 | |||
532 | state tell; |
||
533 | } |
||
534 | timer() { |
||
535 | llReleaseURL(URL); |
||
536 | state listen_group; |
||
537 | } |
||
538 | on_rez(integer num) { |
||
539 | llResetScript(); |
||
540 | } |
||
541 | changed(integer change) { |
||
542 | if((change & CHANGED_INVENTORY) || |
||
543 | (change & CHANGED_REGION_START) || |
||
544 | (change & CHANGED_OWNER)) { |
||
545 | llResetScript(); |
||
546 | } |
||
547 | } |
||
548 | state_exit() { |
||
549 | llSetTimerEvent(0); |
||
550 | } |
||
551 | } |
||
552 | |||
553 | state tell { |
||
554 | state_entry() { |
||
555 | // DEBUG |
||
556 | llOwnerSay("[Ban] Sending to group."); |
||
557 | llInstantMessage( |
||
558 | wasKeyValueGet( |
||
559 | "corrade", |
||
560 | configuration |
||
561 | ), |
||
562 | wasKeyValueEncode( |
||
563 | [ |
||
564 | "command", "tell", |
||
565 | "group", wasURLEscape( |
||
566 | wasKeyValueGet( |
||
567 | "group", |
||
568 | configuration |
||
569 | ) |
||
570 | ), |
||
571 | "password", wasURLEscape( |
||
572 | wasKeyValueGet( |
||
573 | "password", |
||
574 | configuration |
||
575 | ) |
||
576 | ), |
||
577 | "entity", "group", |
||
578 | "message", wasURLEscape(data) |
||
579 | ] |
||
580 | ) |
||
581 | ); |
||
582 | state listen_group; |
||
583 | } |
||
584 | } |