corrade-lsl-templates – Blame information for rev 42

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