corrade-lsl-templates – Blame information for rev 42

Subversion Repositories:
Rev:
Rev Author Line No. Line
11 office 1 ///////////////////////////////////////////////////////////////////////////
42 office 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
11 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 //
11 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);
11 office 18 return "";
19 }
42 office 20  
11 office 21 ///////////////////////////////////////////////////////////////////////////
42 office 22 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
11 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 //
11 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 //
11 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 //
11 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 //
11 office 113 ///////////////////////////////////////////////////////////////////////////
114 string wasListToCSV(list l) {
115 list v = [];
116 do {
117 string a = llDumpList2String(
118 llParseStringKeepNulls(
119 llList2String(
42 office 120 l,
11 office 121  
42 office 122 ),
123 ["\""],
11 office 124 []
125 ),
126 "\"\""
127 );
128 if(llParseStringKeepNulls(
42 office 129 a,
11 office 130 [" ", ",", "\n", "\""], []
42 office 131 ) !=
11 office 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 //
11 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(
42 office 150 i,
151 ["+"],
11 office 152 []
42 office 153 ),
11 office 154 " "
42 office 155 ),
156 ["%0D%0A"],
11 office 157 []
42 office 158 ),
11 office 159 "\n"
160 )
161 );
162 }
163  
164 ///////////////////////////////////////////////////////////////////////////
42 office 165 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
11 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 = "";
15 office 183 string soft = "True";
11 office 184  
185 default {
186 state_entry() {
187 llOwnerSay("[Unban] Starting...");
188 llSetTimerEvent(10);
189 }
190 link_message(integer sender, integer num, string message, key id) {
191 if(id != "configuration") return;
192 llOwnerSay("[Unban] Got configuration...");
193 configuration = message;
194 state listen_group;
195 }
196 timer() {
197 llOwnerSay("[Unban] Requesting configuration...");
198 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
199 }
200 on_rez(integer num) {
201 llResetScript();
202 }
203 changed(integer change) {
42 office 204 if((change & CHANGED_INVENTORY) ||
205 (change & CHANGED_REGION_START) ||
11 office 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("[Unban] 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;
42 office 224  
11 office 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)))
11 office 230 return;
42 office 231  
11 office 232 // Get the sent message.
233 data = wasURLUnescape(
234 wasKeyValueGet(
42 office 235 "message",
11 office 236 message
237 )
238 );
42 office 239  
11 office 240 // Check if this is an eggdrop command.
42 office 241 if(llGetSubString(data, 0, 0) !=
11 office 242 wasKeyValueGet("command", configuration))
243 return;
42 office 244  
11 office 245 // Check if the command matches the current module.
15 office 246 list command = llParseString2List(data, [" "], []);
42 office 247 if(llList2String(command, 0) !=
15 office 248 wasKeyValueGet("command", configuration) + "unban")
11 office 249 return;
42 office 250  
15 office 251 // Remove command.
252 command = llDeleteSubList(command, 0, 0);
42 office 253  
11 office 254 firstname = wasKeyValueGet("firstname", message);
255 lastname = wasKeyValueGet("lastname", message);
42 office 256  
11 office 257 if(firstname == "" || lastname == "") {
258 data = "And who would yarr be?";
259 state tell;
260 }
42 office 261  
11 office 262 // Dump the rest of the message.
263 data = llDumpList2String(command, " ");
264  
42 office 265 // Get roles of caller.
11 office 266 state get_caller_roles;
267 }
268 on_rez(integer num) {
269 llResetScript();
270 }
271 changed(integer change) {
42 office 272 if((change & CHANGED_INVENTORY) ||
273 (change & CHANGED_REGION_START) ||
11 office 274 (change & CHANGED_OWNER)) {
275 llResetScript();
276 }
277 }
278 }
279  
280 state get_caller_roles {
281 state_entry() {
282 // DEBUG
283 llOwnerSay("[Unban] Searching for caller...");
284 llInstantMessage(
285 wasKeyValueGet(
42 office 286 "corrade",
11 office 287 configuration
42 office 288 ),
11 office 289 wasKeyValueEncode(
290 [
291 "command", "getmemberroles",
292 "group", wasURLEscape(
293 wasKeyValueGet(
42 office 294 "group",
11 office 295 configuration
296 )
297 ),
298 "password", wasURLEscape(
299 wasKeyValueGet(
42 office 300 "password",
11 office 301 configuration
302 )
303 ),
304 "firstname", firstname,
305 "lastname", lastname,
42 office 306 "callback", wasURLEscape(
307 wasKeyValueGet(
308 "URL",
309 configuration
310 )
311 )
11 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") {
11 office 323 // DEBUG
42 office 324 llOwnerSay("[Unban] Unable to get member roles: " +
11 office 325 wasURLUnescape(
326 wasKeyValueGet("error", body)
327 )
328 );
329 state listen_group;
330 }
42 office 331  
11 office 332 // Dump the roles to a list.
333 list roles = wasCSVToList(
334 wasURLUnescape(
335 wasKeyValueGet("data", body)
336 )
337 );
42 office 338  
11 office 339 if(llGetListLength(
42 office 340 wasSetIntersect(roles,
11 office 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 }
42 office 351  
11 office 352 list banee = llParseString2List(data, [" "], []);
42 office 353  
11 office 354 firstname = llList2String(banee, 0);
15 office 355 banee = llDeleteSubList(banee, 0, 0);
356 lastname = llList2String(banee, 0);
357 banee = llDeleteSubList(banee, 0, 0);
42 office 358  
11 office 359 if(firstname == "" || lastname == "") {
360 data = "Full name required.";
361 state tell;
362 }
42 office 363  
364 if(llGetListLength(banee) != 0 &&
15 office 365 llToLower(llList2String(banee, 0)) == "nosoft") {
366 soft = "False";
367 banee = llDeleteSubList(banee, 0, 0);
368 }
42 office 369  
11 office 370 // GC
371 banee = [];
372 state get_banee_roles;
373 }
374 timer() {
375 state listen_group;
376 }
377 on_rez(integer num) {
378 llResetScript();
379 }
380 changed(integer change) {
42 office 381 if((change & CHANGED_INVENTORY) ||
382 (change & CHANGED_REGION_START) ||
11 office 383 (change & CHANGED_OWNER)) {
384 llResetScript();
385 }
386 }
387 state_exit() {
388 llSetTimerEvent(0);
389 }
390 }
391  
392 state get_banee_roles {
393 state_entry() {
394 // DEBUG
395 llOwnerSay("[Unban] Searching for banee...");
396 llInstantMessage(
397 wasKeyValueGet(
42 office 398 "corrade",
11 office 399 configuration
42 office 400 ),
11 office 401 wasKeyValueEncode(
402 [
403 "command", "getmemberroles",
404 "group", wasURLEscape(
405 wasKeyValueGet(
42 office 406 "group",
11 office 407 configuration
408 )
409 ),
410 "password", wasURLEscape(
411 wasKeyValueGet(
42 office 412 "password",
11 office 413 configuration
414 )
415 ),
416 "firstname", firstname,
417 "lastname", lastname,
42 office 418 "callback", wasURLEscape(
419 wasKeyValueGet(
420 "URL",
421 configuration
422 )
423 )
11 office 424 ]
425 )
426 );
427 llSetTimerEvent(60);
428 }
42 office 429 link_message(integer sender, integer num, string body, key id) {
430 // Only process callbacks for the database command.
431 if(id != "callback" || wasKeyValueGet("command", body) != "getmemberroles")
432 return;
433  
434 if(wasKeyValueGet("success", body) != "True") {
15 office 435 if(wasKeyValueGet("status", body) == "19862") {
436 // DEBUG
437 llOwnerSay("[Unban] User not in group, but proceeding anyway...");
438 jump continue;
439 }
11 office 440 // DEBUG
42 office 441 llOwnerSay("[Unban] Unable to get member roles: " +
11 office 442 wasURLUnescape(
443 wasKeyValueGet("error", body)
444 )
445 );
42 office 446  
11 office 447 state listen_group;
448 }
42 office 449  
11 office 450 string result = wasURLUnescape(
451 wasKeyValueGet("data", body)
452 );
42 office 453  
11 office 454 if(result != "" && llListFindList(wasCSVToList(result), (list)"Owners") != -1) {
455 data = "Ejectee is an owner. I'm not gonna open the pod bay doors.";
456 state tell;
457 }
42 office 458  
15 office 459 @continue;
460  
461 state unban;
11 office 462 }
463 timer() {
464 state listen_group;
465 }
466 on_rez(integer num) {
467 llResetScript();
468 }
469 changed(integer change) {
42 office 470 if((change & CHANGED_INVENTORY) ||
471 (change & CHANGED_REGION_START) ||
11 office 472 (change & CHANGED_OWNER)) {
473 llResetScript();
474 }
475 }
476 state_exit() {
477 llSetTimerEvent(0);
478 }
479 }
480  
15 office 481 state unban {
11 office 482 state_entry() {
483 // DEBUG
484 llOwnerSay("[Unban] Unbanning...");
485 llInstantMessage(
486 wasKeyValueGet(
42 office 487 "corrade",
11 office 488 configuration
42 office 489 ),
11 office 490 wasKeyValueEncode(
491 [
15 office 492 "command", "ban",
11 office 493 "group", wasURLEscape(
494 wasKeyValueGet(
42 office 495 "group",
11 office 496 configuration
497 )
498 ),
499 "password", wasURLEscape(
500 wasKeyValueGet(
42 office 501 "password",
11 office 502 configuration
503 )
504 ),
15 office 505 "soft", soft,
11 office 506 "action", "unban",
507 "avatars", wasURLEscape(
508 wasListToCSV(
509 [
510 firstname + " " + lastname
511 ]
512 )
513 ),
42 office 514 "callback", wasURLEscape(
515 wasKeyValueGet(
516 "URL",
517 configuration
518 )
519 )
11 office 520 ]
521 )
522 );
523 llSetTimerEvent(60);
524 }
42 office 525 link_message(integer sender, integer num, string body, key id) {
526 // Only process callbacks for the database command.
527 if(id != "callback" || wasKeyValueGet("command", body) != "ban")
528 return;
529  
530 if(wasKeyValueGet("success", body) != "True") {
11 office 531 // DEBUG
42 office 532 llOwnerSay("[Unban] Unable to ban member: " +
11 office 533 wasURLUnescape(
534 wasKeyValueGet("error", body)
535 )
536 );
537 state listen_group;
538 }
42 office 539  
15 office 540 data = "They'll be bak!";
42 office 541  
11 office 542 state tell;
543 }
544 timer() {
545 state listen_group;
546 }
547 on_rez(integer num) {
548 llResetScript();
549 }
550 changed(integer change) {
42 office 551 if((change & CHANGED_INVENTORY) ||
552 (change & CHANGED_REGION_START) ||
11 office 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("[Unban] Sending to group.");
566 llInstantMessage(
567 wasKeyValueGet(
42 office 568 "corrade",
11 office 569 configuration
42 office 570 ),
11 office 571 wasKeyValueEncode(
572 [
573 "command", "tell",
574 "group", wasURLEscape(
575 wasKeyValueGet(
42 office 576 "group",
11 office 577 configuration
578 )
579 ),
580 "password", wasURLEscape(
581 wasKeyValueGet(
42 office 582 "password",
11 office 583 configuration
584 )
585 ),
586 "entity", "group",
587 "message", wasURLEscape(data)
588 ]
589 )
590 );
42 office 591  
15 office 592 // reset variables.
593 soft = "True";
42 office 594  
11 office 595 state listen_group;
596 }
597 }