corrade-lsl-templates – Blame information for rev 41
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
15 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
29 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // |
15 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // A module that unbans 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 ""; |
||
41 | office | 15 | list a = llParseStringKeepNulls(data, ["&", "="], []); |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 22 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 37 | // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 49 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 73 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 112 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 141 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 165 | // Copyright (C) 2017 Wizardry and Steamworks - License: CC BY 2.0 // |
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 | // 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("[Softunban] Starting..."); |
||
189 | llSetTimerEvent(10); |
||
190 | } |
||
191 | link_message(integer sender, integer num, string message, key id) { |
||
192 | if(id != "configuration") return; |
||
193 | llOwnerSay("[Softunban] Got configuration..."); |
||
194 | configuration = message; |
||
195 | state listen_group; |
||
196 | } |
||
197 | timer() { |
||
198 | llOwnerSay("[Softunban] 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("[Softunban] 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 | // Check if this is an eggdrop command. |
||
239 | if(llGetSubString(data, 0, 0) != |
||
240 | wasKeyValueGet("command", configuration)) |
||
241 | return; |
||
242 | |||
243 | // Check if the command matches the current module. |
||
244 | list command = llParseString2List(data, [" "], []); |
||
245 | if(llList2String(command, 0) != |
||
246 | wasKeyValueGet("command", configuration) + "softunban") |
||
247 | return; |
||
248 | |||
249 | // Remove command. |
||
250 | command = llDeleteSubList(command, 0, 0); |
||
251 | |||
252 | firstname = wasKeyValueGet("firstname", message); |
||
253 | lastname = wasKeyValueGet("lastname", message); |
||
254 | |||
255 | if(firstname == "" || lastname == "") { |
||
256 | data = "And who would yarr be?"; |
||
257 | state tell; |
||
258 | } |
||
259 | |||
260 | // Dump the rest of the message. |
||
261 | data = llDumpList2String(command, " "); |
||
262 | |||
263 | // Get an URL. |
||
264 | state url; |
||
265 | } |
||
266 | on_rez(integer num) { |
||
267 | llResetScript(); |
||
268 | } |
||
269 | changed(integer change) { |
||
270 | if((change & CHANGED_INVENTORY) || |
||
271 | (change & CHANGED_REGION_START) || |
||
272 | (change & CHANGED_OWNER)) { |
||
273 | llResetScript(); |
||
274 | } |
||
275 | } |
||
276 | } |
||
277 | |||
278 | state url { |
||
279 | state_entry() { |
||
280 | // DEBUG |
||
281 | llOwnerSay("[Softunban] Requesting URL..."); |
||
282 | llRequestURL(); |
||
283 | } |
||
284 | http_request(key id, string method, string body) { |
||
285 | if(method != URL_REQUEST_GRANTED) return; |
||
286 | URL = body; |
||
287 | // DEBUG |
||
288 | llOwnerSay("[Softunban] Got URL..."); |
||
289 | state get_caller_roles; |
||
290 | } |
||
291 | on_rez(integer num) { |
||
292 | llResetScript(); |
||
293 | } |
||
294 | changed(integer change) { |
||
295 | if((change & CHANGED_INVENTORY) || |
||
296 | (change & CHANGED_REGION_START) || |
||
297 | (change & CHANGED_OWNER)) { |
||
298 | llResetScript(); |
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | |||
303 | state get_caller_roles { |
||
304 | state_entry() { |
||
305 | // DEBUG |
||
306 | llOwnerSay("[Softunban] Searching for caller..."); |
||
307 | llInstantMessage( |
||
308 | wasKeyValueGet( |
||
309 | "corrade", |
||
310 | configuration |
||
311 | ), |
||
312 | wasKeyValueEncode( |
||
313 | [ |
||
314 | "command", "getmemberroles", |
||
315 | "group", wasURLEscape( |
||
316 | wasKeyValueGet( |
||
317 | "group", |
||
318 | configuration |
||
319 | ) |
||
320 | ), |
||
321 | "password", wasURLEscape( |
||
322 | wasKeyValueGet( |
||
323 | "password", |
||
324 | configuration |
||
325 | ) |
||
326 | ), |
||
327 | "firstname", firstname, |
||
328 | "lastname", lastname, |
||
329 | "callback", wasURLEscape(URL) |
||
330 | ] |
||
331 | ) |
||
332 | ); |
||
333 | llSetTimerEvent(60); |
||
334 | } |
||
335 | http_request(key id, string method, string body) { |
||
336 | llHTTPResponse(id, 200, "OK"); |
||
337 | if(wasKeyValueGet("command", body) != "getmemberroles" || |
||
338 | wasKeyValueGet("success", body) != "True") { |
||
339 | // DEBUG |
||
340 | llOwnerSay("[Softunban] Unable to get member roles: " + |
||
341 | wasURLUnescape( |
||
342 | wasKeyValueGet("error", body) |
||
343 | ) |
||
344 | ); |
||
345 | llReleaseURL(URL); |
||
346 | state listen_group; |
||
347 | } |
||
348 | |||
349 | // Dump the roles to a list. |
||
350 | list roles = wasCSVToList( |
||
351 | wasURLUnescape( |
||
352 | wasKeyValueGet("data", body) |
||
353 | ) |
||
354 | ); |
||
355 | |||
356 | if(llGetListLength( |
||
357 | wasSetIntersect(roles, |
||
358 | wasCSVToList( |
||
359 | wasKeyValueGet( |
||
360 | "admin roles", configuration |
||
361 | ) |
||
362 | ) |
||
363 | ) |
||
364 | ) == 0) { |
||
365 | data = "You ain't got the cojones!"; |
||
366 | llReleaseURL(URL); |
||
367 | state tell; |
||
368 | } |
||
369 | |||
370 | list banee = llParseString2List(data, [" "], []); |
||
371 | |||
372 | firstname = llList2String(banee, 0); |
||
373 | lastname = llList2String(banee, 1); |
||
374 | |||
375 | if(firstname == "" || lastname == "") { |
||
376 | data = "Full name required."; |
||
377 | state tell; |
||
378 | } |
||
379 | |||
380 | // GC |
||
381 | banee = []; |
||
382 | state get_banee_roles; |
||
383 | } |
||
384 | timer() { |
||
385 | llReleaseURL(URL); |
||
386 | state listen_group; |
||
387 | } |
||
388 | on_rez(integer num) { |
||
389 | llResetScript(); |
||
390 | } |
||
391 | changed(integer change) { |
||
392 | if((change & CHANGED_INVENTORY) || |
||
393 | (change & CHANGED_REGION_START) || |
||
394 | (change & CHANGED_OWNER)) { |
||
395 | llResetScript(); |
||
396 | } |
||
397 | } |
||
398 | state_exit() { |
||
399 | llSetTimerEvent(0); |
||
400 | } |
||
401 | } |
||
402 | |||
403 | state get_banee_roles { |
||
404 | state_entry() { |
||
405 | // DEBUG |
||
406 | llOwnerSay("[Softunban] Searching for banee..."); |
||
407 | llInstantMessage( |
||
408 | wasKeyValueGet( |
||
409 | "corrade", |
||
410 | configuration |
||
411 | ), |
||
412 | wasKeyValueEncode( |
||
413 | [ |
||
414 | "command", "getmemberroles", |
||
415 | "group", wasURLEscape( |
||
416 | wasKeyValueGet( |
||
417 | "group", |
||
418 | configuration |
||
419 | ) |
||
420 | ), |
||
421 | "password", wasURLEscape( |
||
422 | wasKeyValueGet( |
||
423 | "password", |
||
424 | configuration |
||
425 | ) |
||
426 | ), |
||
427 | "firstname", firstname, |
||
428 | "lastname", lastname, |
||
429 | "callback", wasURLEscape(URL) |
||
430 | ] |
||
431 | ) |
||
432 | ); |
||
433 | llSetTimerEvent(60); |
||
434 | } |
||
435 | http_request(key id, string method, string body) { |
||
436 | llHTTPResponse(id, 200, "OK"); |
||
437 | if(wasKeyValueGet("command", body) != "getmemberroles" || |
||
438 | wasKeyValueGet("success", body) != "True") { |
||
439 | if(wasKeyValueGet("status", body) == "19862") { |
||
440 | // DEBUG |
||
441 | llOwnerSay("[Softunban] User not in group, but proceeding anyway..."); |
||
442 | jump continue; |
||
443 | } |
||
444 | // DEBUG |
||
445 | llOwnerSay("[Softunban] Unable to get member roles: " + |
||
446 | wasURLUnescape( |
||
447 | wasKeyValueGet("error", body) |
||
448 | ) |
||
449 | ); |
||
450 | llReleaseURL(URL); |
||
451 | state listen_group; |
||
452 | } |
||
453 | |||
454 | string result = wasURLUnescape( |
||
455 | wasKeyValueGet("data", body) |
||
456 | ); |
||
457 | |||
458 | if(result != "" && llListFindList(wasCSVToList(result), (list)"Owners") != -1) { |
||
459 | data = "Ejectee is an owner. I'm not gonna open the pod bay doors."; |
||
460 | llReleaseURL(URL); |
||
461 | state tell; |
||
462 | } |
||
463 | |||
464 | @continue; |
||
465 | |||
466 | state unban; |
||
467 | } |
||
468 | timer() { |
||
469 | llReleaseURL(URL); |
||
470 | state listen_group; |
||
471 | } |
||
472 | on_rez(integer num) { |
||
473 | llResetScript(); |
||
474 | } |
||
475 | changed(integer change) { |
||
476 | if((change & CHANGED_INVENTORY) || |
||
477 | (change & CHANGED_REGION_START) || |
||
478 | (change & CHANGED_OWNER)) { |
||
479 | llResetScript(); |
||
480 | } |
||
481 | } |
||
482 | state_exit() { |
||
483 | llSetTimerEvent(0); |
||
484 | } |
||
485 | } |
||
486 | |||
487 | state unban { |
||
488 | state_entry() { |
||
489 | // DEBUG |
||
490 | llOwnerSay("[Softunban] Unbanning..."); |
||
491 | llInstantMessage( |
||
492 | wasKeyValueGet( |
||
493 | "corrade", |
||
494 | configuration |
||
495 | ), |
||
496 | wasKeyValueEncode( |
||
497 | [ |
||
498 | "command", "softban", |
||
499 | "group", wasURLEscape( |
||
500 | wasKeyValueGet( |
||
501 | "group", |
||
502 | configuration |
||
503 | ) |
||
504 | ), |
||
505 | "password", wasURLEscape( |
||
506 | wasKeyValueGet( |
||
507 | "password", |
||
508 | configuration |
||
509 | ) |
||
510 | ), |
||
511 | "action", "unban", |
||
512 | "avatars", wasURLEscape( |
||
513 | wasListToCSV( |
||
514 | [ |
||
515 | firstname + " " + lastname |
||
516 | ] |
||
517 | ) |
||
518 | ), |
||
519 | "callback", wasURLEscape(URL) |
||
520 | ] |
||
521 | ) |
||
522 | ); |
||
523 | llSetTimerEvent(60); |
||
524 | } |
||
525 | http_request(key id, string method, string body) { |
||
526 | llHTTPResponse(id, 200, "OK"); |
||
527 | llReleaseURL(URL); |
||
528 | if(wasKeyValueGet("command", body) != "softban" || |
||
529 | wasKeyValueGet("success", body) != "True") { |
||
530 | // DEBUG |
||
531 | llOwnerSay("[Softunban] Unable to ban member: " + |
||
532 | wasURLUnescape( |
||
533 | wasKeyValueGet("error", body) |
||
534 | ) |
||
535 | ); |
||
536 | state listen_group; |
||
537 | } |
||
538 | |||
539 | data = "They'll be bak!"; |
||
540 | |||
541 | state tell; |
||
542 | } |
||
543 | timer() { |
||
544 | llReleaseURL(URL); |
||
545 | state listen_group; |
||
546 | } |
||
547 | on_rez(integer num) { |
||
548 | llResetScript(); |
||
549 | } |
||
550 | changed(integer change) { |
||
551 | if((change & CHANGED_INVENTORY) || |
||
552 | (change & CHANGED_REGION_START) || |
||
553 | (change & CHANGED_OWNER)) { |
||
554 | llResetScript(); |
||
555 | } |
||
556 | } |
||
557 | state_exit() { |
||
558 | llSetTimerEvent(0); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | state tell { |
||
563 | state_entry() { |
||
564 | // DEBUG |
||
565 | llOwnerSay("[Softunban] Sending to group."); |
||
566 | llInstantMessage( |
||
567 | wasKeyValueGet( |
||
568 | "corrade", |
||
569 | configuration |
||
570 | ), |
||
571 | wasKeyValueEncode( |
||
572 | [ |
||
573 | "command", "tell", |
||
574 | "group", wasURLEscape( |
||
575 | wasKeyValueGet( |
||
576 | "group", |
||
577 | configuration |
||
578 | ) |
||
579 | ), |
||
580 | "password", wasURLEscape( |
||
581 | wasKeyValueGet( |
||
582 | "password", |
||
583 | configuration |
||
584 | ) |
||
585 | ), |
||
586 | "entity", "group", |
||
587 | "message", wasURLEscape(data) |
||
588 | ] |
||
589 | ) |
||
590 | ); |
||
591 | |||
592 | state listen_group; |
||
593 | } |
||
594 | } |