corrade-lsl-templates – Blame information for rev 11

Subversion Repositories:
Rev:
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  
11 office 238 // Check if this is an eggdrop command.
8 office 239 if(llGetSubString(data, 0, 0) !=
240 wasKeyValueGet("command", configuration))
241 return;
11 office 242  
243 // Check if the command matches the current module.
10 office 244 list command = llParseString2List(data,
11 office 245 [wasKeyValueGet("command", configuration), " "], ["@"]);
8 office 246 if(llList2String(command, 0) != "ban")
247 return;
248  
249 firstname = wasKeyValueGet("firstname", message);
250 lastname = wasKeyValueGet("lastname", message);
251  
252 if(firstname == "" || lastname == "") {
253 data = "And who would yarr be?";
254 state tell;
255 }
256  
257 // Remove command.
258 command = llDeleteSubList(command, 0, 0);
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("[Ban] 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("[Ban] 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("[Ban] 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("[Ban] 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("[Ban] 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 // DEBUG
440 llOwnerSay("[Ban] Unable to get member roles: " +
441 wasURLUnescape(
442 wasKeyValueGet("error", body)
443 )
444 );
445 llReleaseURL(URL);
446 state listen_group;
447 }
448  
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 gonna open the pod bay doors.";
455 llReleaseURL(URL);
456 state tell;
457 }
458  
459 state ban;
460 }
461 timer() {
462 llReleaseURL(URL);
463 state listen_group;
464 }
465 on_rez(integer num) {
466 llResetScript();
467 }
468 changed(integer change) {
469 if((change & CHANGED_INVENTORY) ||
470 (change & CHANGED_REGION_START) ||
471 (change & CHANGED_OWNER)) {
472 llResetScript();
473 }
474 }
475 state_exit() {
476 llSetTimerEvent(0);
477 }
478 }
479  
480 state ban {
481 state_entry() {
482 // DEBUG
483 llOwnerSay("[Ban] Banning...");
484 llInstantMessage(
485 wasKeyValueGet(
486 "corrade",
487 configuration
488 ),
489 wasKeyValueEncode(
490 [
491 "command", "ban",
492 "group", wasURLEscape(
493 wasKeyValueGet(
494 "group",
495 configuration
496 )
497 ),
498 "password", wasURLEscape(
499 wasKeyValueGet(
500 "password",
501 configuration
502 )
503 ),
504 "action", "ban",
505 "avatars", wasURLEscape(
506 wasListToCSV(
507 [
508 firstname + " " + lastname
509 ]
510 )
511 ),
512 "eject", "True",
513 "callback", wasURLEscape(URL)
514 ]
515 )
516 );
517 llSetTimerEvent(60);
518 }
519 http_request(key id, string method, string body) {
520 llHTTPResponse(id, 200, "OK");
521 llReleaseURL(URL);
522 if(wasKeyValueGet("command", body) != "ban" ||
523 wasKeyValueGet("success", body) != "True") {
524 // DEBUG
525 llOwnerSay("[Ban] Unable to ban member: " +
526 wasURLUnescape(
527 wasKeyValueGet("error", body)
528 )
529 );
530 state listen_group;
531 }
532  
533 data = "Hasta la vista, baby!";
534  
535 state tell;
536 }
537 timer() {
538 llReleaseURL(URL);
539 state listen_group;
540 }
541 on_rez(integer num) {
542 llResetScript();
543 }
544 changed(integer change) {
545 if((change & CHANGED_INVENTORY) ||
546 (change & CHANGED_REGION_START) ||
547 (change & CHANGED_OWNER)) {
548 llResetScript();
549 }
550 }
551 state_exit() {
552 llSetTimerEvent(0);
553 }
554 }
555  
556 state tell {
557 state_entry() {
558 // DEBUG
559 llOwnerSay("[Ban] Sending to group.");
560 llInstantMessage(
561 wasKeyValueGet(
562 "corrade",
563 configuration
564 ),
565 wasKeyValueEncode(
566 [
567 "command", "tell",
568 "group", wasURLEscape(
569 wasKeyValueGet(
570 "group",
571 configuration
572 )
573 ),
574 "password", wasURLEscape(
575 wasKeyValueGet(
576 "password",
577 configuration
578 )
579 ),
580 "entity", "group",
581 "message", wasURLEscape(data)
582 ]
583 )
584 );
585 state listen_group;
586 }
587 }