corrade-lsl-templates – Diff between revs 10 and 11

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 10 Rev 11
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // A module that spanks group members using fuzzy name matching. . . 5 // A module that spanks group members using fuzzy name matching. . .
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
8   8  
9 /////////////////////////////////////////////////////////////////////////// 9 ///////////////////////////////////////////////////////////////////////////
10 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 10 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
11 /////////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////////
12 string wasKeyValueGet(string k, string data) { 12 string wasKeyValueGet(string k, string data) {
13 if(llStringLength(data) == 0) return ""; 13 if(llStringLength(data) == 0) return "";
14 if(llStringLength(k) == 0) return ""; 14 if(llStringLength(k) == 0) return "";
15 list a = llParseString2List(data, ["&", "="], []); 15 list a = llParseString2List(data, ["&", "="], []);
16 integer i = llListFindList(a, [ k ]); 16 integer i = llListFindList(a, [ k ]);
17 if(i != -1) return llList2String(a, i+1); 17 if(i != -1) return llList2String(a, i+1);
18 return ""; 18 return "";
19 } 19 }
20 20
21 /////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////
22 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // 22 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
23 /////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////
24 string wasKeyValueEncode(list data) { 24 string wasKeyValueEncode(list data) {
25 list k = llList2ListStrided(data, 0, -1, 2); 25 list k = llList2ListStrided(data, 0, -1, 2);
26 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 26 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
27 data = []; 27 data = [];
28 do { 28 do {
29 data += llList2String(k, 0) + "=" + llList2String(v, 0); 29 data += llList2String(k, 0) + "=" + llList2String(v, 0);
30 k = llDeleteSubList(k, 0, 0); 30 k = llDeleteSubList(k, 0, 0);
31 v = llDeleteSubList(v, 0, 0); 31 v = llDeleteSubList(v, 0, 0);
32 } while(llGetListLength(k) != 0); 32 } while(llGetListLength(k) != 0);
33 return llDumpList2String(data, "&"); 33 return llDumpList2String(data, "&");
34 } 34 }
35   35  
36 /////////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////////
37 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // 37 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 //
38 /////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////
39 // http://was.fm/secondlife/wanderer 39 // http://was.fm/secondlife/wanderer
40 vector wasCirclePoint(float radius) { 40 vector wasCirclePoint(float radius) {
41 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); 41 float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
42 float y = 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)) 43 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2))
44 return <x, y, 0>; 44 return <x, y, 0>;
45 return wasCirclePoint(radius); 45 return wasCirclePoint(radius);
46 } 46 }
47   47  
48 /////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////
49 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 49 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
50 /////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////
51 // escapes a string in conformance with RFC1738 51 // escapes a string in conformance with RFC1738
52 string wasURLEscape(string i) { 52 string wasURLEscape(string i) {
53 string o = ""; 53 string o = "";
54 do { 54 do {
55 string c = llGetSubString(i, 0, 0); 55 string c = llGetSubString(i, 0, 0);
56 i = llDeleteSubString(i, 0, 0); 56 i = llDeleteSubString(i, 0, 0);
57 if(c == "") jump continue; 57 if(c == "") jump continue;
58 if(c == " ") { 58 if(c == " ") {
59 o += "+"; 59 o += "+";
60 jump continue; 60 jump continue;
61 } 61 }
62 if(c == "\n") { 62 if(c == "\n") {
63 o += "%0D" + llEscapeURL(c); 63 o += "%0D" + llEscapeURL(c);
64 jump continue; 64 jump continue;
65 } 65 }
66 o += llEscapeURL(c); 66 o += llEscapeURL(c);
67 @continue; 67 @continue;
68 } while(i != ""); 68 } while(i != "");
69 return o; 69 return o;
70 } 70 }
71   71  
72 /////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////
73 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 73 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
74 /////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////
75 list wasCSVToList(string csv) { 75 list wasCSVToList(string csv) {
76 list l = []; 76 list l = [];
77 list s = []; 77 list s = [];
78 string m = ""; 78 string m = "";
79 do { 79 do {
80 string a = llGetSubString(csv, 0, 0); 80 string a = llGetSubString(csv, 0, 0);
81 csv = llDeleteSubString(csv, 0, 0); 81 csv = llDeleteSubString(csv, 0, 0);
82 if(a == ",") { 82 if(a == ",") {
83 if(llList2String(s, -1) != "\"") { 83 if(llList2String(s, -1) != "\"") {
84 l += m; 84 l += m;
85 m = ""; 85 m = "";
86 jump continue; 86 jump continue;
87 } 87 }
88 m += a; 88 m += a;
89 jump continue; 89 jump continue;
90 } 90 }
91 if(a == "\"" && llGetSubString(csv, 0, 0) == a) { 91 if(a == "\"" && llGetSubString(csv, 0, 0) == a) {
92 m += a; 92 m += a;
93 csv = llDeleteSubString(csv, 0, 0); 93 csv = llDeleteSubString(csv, 0, 0);
94 jump continue; 94 jump continue;
95 } 95 }
96 if(a == "\"") { 96 if(a == "\"") {
97 if(llList2String(s, -1) != a) { 97 if(llList2String(s, -1) != a) {
98 s += a; 98 s += a;
99 jump continue; 99 jump continue;
100 } 100 }
101 s = llDeleteSubList(s, -1, -1); 101 s = llDeleteSubList(s, -1, -1);
102 jump continue; 102 jump continue;
103 } 103 }
104 m += a; 104 m += a;
105 @continue; 105 @continue;
106 } while(csv != ""); 106 } while(csv != "");
107 // postcondition: length(s) = 0 107 // postcondition: length(s) = 0
108 return l + m; 108 return l + m;
109 } 109 }
110   110  
111 /////////////////////////////////////////////////////////////////////////// 111 ///////////////////////////////////////////////////////////////////////////
112 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 112 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
113 /////////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////////
114 string wasListToCSV(list l) { 114 string wasListToCSV(list l) {
115 list v = []; 115 list v = [];
116 do { 116 do {
117 string a = llDumpList2String( 117 string a = llDumpList2String(
118 llParseStringKeepNulls( 118 llParseStringKeepNulls(
119 llList2String( 119 llList2String(
120 l, 120 l,
121 0 121 0
122 ), 122 ),
123 ["\""], 123 ["\""],
124 [] 124 []
125 ), 125 ),
126 "\"\"" 126 "\"\""
127 ); 127 );
128 if(llParseStringKeepNulls( 128 if(llParseStringKeepNulls(
129 a, 129 a,
130 [" ", ",", "\n", "\""], [] 130 [" ", ",", "\n", "\""], []
131 ) != 131 ) !=
132 (list) a 132 (list) a
133 ) a = "\"" + a + "\""; 133 ) a = "\"" + a + "\"";
134 v += a; 134 v += a;
135 l = llDeleteSubList(l, 0, 0); 135 l = llDeleteSubList(l, 0, 0);
136 } while(l != []); 136 } while(l != []);
137 return llDumpList2String(v, ","); 137 return llDumpList2String(v, ",");
138 } 138 }
139   139  
140 /////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////
141 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 141 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
142 /////////////////////////////////////////////////////////////////////////// 142 ///////////////////////////////////////////////////////////////////////////
143 // unescapes a string in conformance with RFC1738 143 // unescapes a string in conformance with RFC1738
144 string wasURLUnescape(string i) { 144 string wasURLUnescape(string i) {
145 return llUnescapeURL( 145 return llUnescapeURL(
146 llDumpList2String( 146 llDumpList2String(
147 llParseString2List( 147 llParseString2List(
148 llDumpList2String( 148 llDumpList2String(
149 llParseString2List( 149 llParseString2List(
150 i, 150 i,
151 ["+"], 151 ["+"],
152 [] 152 []
153 ), 153 ),
154 " " 154 " "
155 ), 155 ),
156 ["%0D%0A"], 156 ["%0D%0A"],
157 [] 157 []
158 ), 158 ),
159 "\n" 159 "\n"
160 ) 160 )
161 ); 161 );
162 } 162 }
163   163  
164 // configuration data 164 // configuration data
165 string configuration = ""; 165 string configuration = "";
166 // callback URL 166 // callback URL
167 string URL = ""; 167 string URL = "";
168 // store message over state. 168 // store message over state.
169 string data = ""; 169 string data = "";
170   170  
171 default { 171 default {
172 state_entry() { 172 state_entry() {
173 llOwnerSay("[Spank] Starting..."); 173 llOwnerSay("[Spank] Starting...");
174 llSetTimerEvent(10); 174 llSetTimerEvent(10);
175 } 175 }
176 link_message(integer sender, integer num, string message, key id) { 176 link_message(integer sender, integer num, string message, key id) {
177 if(id != "configuration") return; 177 if(id != "configuration") return;
178 llOwnerSay("[Spank] Got configuration..."); 178 llOwnerSay("[Spank] Got configuration...");
179 configuration = message; 179 configuration = message;
180 state listen_group; 180 state listen_group;
181 } 181 }
182 timer() { 182 timer() {
183 llOwnerSay("[Spank] Requesting configuration..."); 183 llOwnerSay("[Spank] Requesting configuration...");
184 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 184 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
185 } 185 }
186 on_rez(integer num) { 186 on_rez(integer num) {
187 llResetScript(); 187 llResetScript();
188 } 188 }
189 changed(integer change) { 189 changed(integer change) {
190 if((change & CHANGED_INVENTORY) || 190 if((change & CHANGED_INVENTORY) ||
191 (change & CHANGED_REGION_START) || 191 (change & CHANGED_REGION_START) ||
192 (change & CHANGED_OWNER)) { 192 (change & CHANGED_OWNER)) {
193 llResetScript(); 193 llResetScript();
194 } 194 }
195 } 195 }
196 state_exit() { 196 state_exit() {
197 llSetTimerEvent(0); 197 llSetTimerEvent(0);
198 } 198 }
199 } 199 }
200   200  
201 state listen_group { 201 state listen_group {
202 state_entry() { 202 state_entry() {
203 // DEBUG 203 // DEBUG
204 llOwnerSay("[Spank] Waiting for group messages..."); 204 llOwnerSay("[Spank] Waiting for group messages...");
205 } 205 }
206 link_message(integer sender, integer num, string message, key id) { 206 link_message(integer sender, integer num, string message, key id) {
207 // We only care about notifications now. 207 // We only care about notifications now.
208 if(id != "notification") 208 if(id != "notification")
209 return; 209 return;
210 210
211 // This script only processes group notifications. 211 // This script only processes group notifications.
212 if(wasKeyValueGet("type", message) != "group") 212 if(wasKeyValueGet("type", message) != "group")
213 return; 213 return;
214 214
215 // Get the sent message. 215 // Get the sent message.
216 data = wasURLUnescape( 216 data = wasURLUnescape(
217 wasKeyValueGet( 217 wasKeyValueGet(
218 "message", 218 "message",
219 message 219 message
220 ) 220 )
221 ); 221 );
-   222
222 223 // Check if this is an eggdrop command.
223 if(llGetSubString(data, 0, 0) != 224 if(llGetSubString(data, 0, 0) !=
224 wasKeyValueGet("command", configuration)) 225 wasKeyValueGet("command", configuration))
225 return; 226 return;
226 227
-   228 // Check if the command matches the current module.
227 list command = llParseString2List(data, 229 list command = llParseString2List(data,
228 [wasKeyValueGet("command", configuration), " "], []); 230 [wasKeyValueGet("command", configuration), " "], ["@"]);
229 if(llList2String(command, 0) != "spank") 231 if(llList2String(command, 0) != "spank")
230 return; 232 return;
231 233
232 // Remove command. 234 // Remove command.
233 command = llDeleteSubList(command, 0, 0); 235 command = llDeleteSubList(command, 0, 0);
234 236
235 // Dump the rest of the message. 237 // Dump the rest of the message.
236 data = llDumpList2String(command, " "); 238 data = llDumpList2String(command, " ");
237 239
238 // Get an URL. 240 // Get an URL.
239 state url; 241 state url;
240 } 242 }
241 on_rez(integer num) { 243 on_rez(integer num) {
242 llResetScript(); 244 llResetScript();
243 } 245 }
244 changed(integer change) { 246 changed(integer change) {
245 if((change & CHANGED_INVENTORY) || 247 if((change & CHANGED_INVENTORY) ||
246 (change & CHANGED_REGION_START) || 248 (change & CHANGED_REGION_START) ||
247 (change & CHANGED_OWNER)) { 249 (change & CHANGED_OWNER)) {
248 llResetScript(); 250 llResetScript();
249 } 251 }
250 } 252 }
251 } 253 }
252   254  
253 state url { 255 state url {
254 state_entry() { 256 state_entry() {
255 // DEBUG 257 // DEBUG
256 llOwnerSay("[Spank] Requesting URL..."); 258 llOwnerSay("[Spank] Requesting URL...");
257 llRequestURL(); 259 llRequestURL();
258 } 260 }
259 http_request(key id, string method, string body) { 261 http_request(key id, string method, string body) {
260 if(method != URL_REQUEST_GRANTED) return; 262 if(method != URL_REQUEST_GRANTED) return;
261 URL = body; 263 URL = body;
262 // DEBUG 264 // DEBUG
263 llOwnerSay("[Spank] Got URL..."); 265 llOwnerSay("[Spank] Got URL...");
264 state search; 266 state search;
265 } 267 }
266 on_rez(integer num) { 268 on_rez(integer num) {
267 llResetScript(); 269 llResetScript();
268 } 270 }
269 changed(integer change) { 271 changed(integer change) {
270 if((change & CHANGED_INVENTORY) || 272 if((change & CHANGED_INVENTORY) ||
271 (change & CHANGED_REGION_START) || 273 (change & CHANGED_REGION_START) ||
272 (change & CHANGED_OWNER)) { 274 (change & CHANGED_OWNER)) {
273 llResetScript(); 275 llResetScript();
274 } 276 }
275 } 277 }
276 } 278 }
277   279  
278 state search { 280 state search {
279 state_entry() { 281 state_entry() {
280 // DEBUG 282 // DEBUG
281 llOwnerSay("[Spank] Searching for agent."); 283 llOwnerSay("[Spank] Searching for agent.");
282 llInstantMessage( 284 llInstantMessage(
283 wasKeyValueGet( 285 wasKeyValueGet(
284 "corrade", 286 "corrade",
285 configuration 287 configuration
286 ), 288 ),
287 wasKeyValueEncode( 289 wasKeyValueEncode(
288 [ 290 [
289 "command", "getmembers", 291 "command", "getmembers",
290 "group", wasURLEscape( 292 "group", wasURLEscape(
291 wasKeyValueGet( 293 wasKeyValueGet(
292 "group", 294 "group",
293 configuration 295 configuration
294 ) 296 )
295 ), 297 ),
296 "password", wasURLEscape( 298 "password", wasURLEscape(
297 wasKeyValueGet( 299 wasKeyValueGet(
298 "password", 300 "password",
299 configuration 301 configuration
300 ) 302 )
301 ), 303 ),
302 "sift", wasURLEscape( 304 "sift", wasURLEscape(
303 wasListToCSV( 305 wasListToCSV(
304 [ 306 [
305 "match", 307 "match",
306 wasURLEscape("(?i),?([^,$]*" + data +"[^,$]*),?") 308 wasURLEscape("(?i),?\"([^\",$]*" + data + "[^\",$]*)\",?")
307 ] 309 ]
308 ) 310 )
309 ), 311 ),
310 "callback", wasURLEscape(URL) 312 "callback", wasURLEscape(URL)
311 ] 313 ]
312 ) 314 )
313 ); 315 );
314 llSetTimerEvent(60); 316 llSetTimerEvent(60);
315 } 317 }
316 http_request(key id, string method, string body) { 318 http_request(key id, string method, string body) {
317 llHTTPResponse(id, 200, "OK"); 319 llHTTPResponse(id, 200, "OK");
318 llReleaseURL(URL); 320 llReleaseURL(URL);
319 if(wasKeyValueGet("command", body) != "getmembers" || 321 if(wasKeyValueGet("command", body) != "getmembers" ||
320 wasKeyValueGet("success", body) != "True") { 322 wasKeyValueGet("success", body) != "True") {
321 // DEBUG 323 // DEBUG
322 llOwnerSay("[Spank] Unable to get members: " + 324 llOwnerSay("[Spank] Unable to get members: " +
323 wasURLUnescape( 325 wasURLUnescape(
324 wasKeyValueGet("error", body) 326 wasKeyValueGet("error", body)
325 ) 327 )
326 ); 328 );
327 state listen_group; 329 state listen_group;
328 } 330 }
329 331
330 // Dump the members to a list. 332 // Dump the members to a list.
331 data = llList2CSV( -  
332 wasCSVToList( 333 list spankees = wasCSVToList(
333 wasURLUnescape( 334 wasURLUnescape(
334 wasKeyValueGet("data", body) 335 wasKeyValueGet("data", body)
335 ) -  
336 ) 336 )
337 ); 337 );
-   338
-   339 // Limit to two people to spank.
-   340 if(llGetListLength(spankees) > 2) {
-   341 data = "So many people, so few hands!";
-   342 return;
-   343 }
-   344
-   345 data = llList2CSV(spankees);
338 346
339 if(data == "") { 347 if(data == "") {
340 data = "I could not find anyone to spank (story of my life)."; 348 data = "I could not find anyone to spank (story of my life).";
341 state tell; 349 state tell;
342 } 350 }
343 -  
344 llOwnerSay("Spanking: " + data); -  
345 351
346 data = "/me spanks " + data; 352 data = "/me spanks " + data;
347 353
348 state tell; 354 state tell;
349 } 355 }
350 timer() { 356 timer() {
351 llReleaseURL(URL); 357 llReleaseURL(URL);
352 state listen_group; 358 state listen_group;
353 } 359 }
354 on_rez(integer num) { 360 on_rez(integer num) {
355 llResetScript(); 361 llResetScript();
356 } 362 }
357 changed(integer change) { 363 changed(integer change) {
358 if((change & CHANGED_INVENTORY) || 364 if((change & CHANGED_INVENTORY) ||
359 (change & CHANGED_REGION_START) || 365 (change & CHANGED_REGION_START) ||
360 (change & CHANGED_OWNER)) { 366 (change & CHANGED_OWNER)) {
361 llResetScript(); 367 llResetScript();
362 } 368 }
363 } 369 }
364 state_exit() { 370 state_exit() {
365 llSetTimerEvent(0); 371 llSetTimerEvent(0);
366 } 372 }
367 } 373 }
368   374  
369 state tell { 375 state tell {
370 state_entry() { 376 state_entry() {
371 // DEBUG 377 // DEBUG
372 llOwnerSay("[Spank] Sending to group."); 378 llOwnerSay("[Spank] Sending to group.");
373 llInstantMessage( 379 llInstantMessage(
374 wasKeyValueGet( 380 wasKeyValueGet(
375 "corrade", 381 "corrade",
376 configuration 382 configuration
377 ), 383 ),
378 wasKeyValueEncode( 384 wasKeyValueEncode(
379 [ 385 [
380 "command", "tell", 386 "command", "tell",
381 "group", wasURLEscape( 387 "group", wasURLEscape(
382 wasKeyValueGet( 388 wasKeyValueGet(
383 "group", 389 "group",
384 configuration 390 configuration
385 ) 391 )
386 ), 392 ),
387 "password", wasURLEscape( 393 "password", wasURLEscape(
388 wasKeyValueGet( 394 wasKeyValueGet(
389 "password", 395 "password",
390 configuration 396 configuration
391 ) 397 )
392 ), 398 ),
393 "entity", "group", 399 "entity", "group",
394 "message", wasURLEscape(data) 400 "message", wasURLEscape(data)
395 ] 401 ]
396 ) 402 )
397 ); 403 );
398 state listen_group; 404 state listen_group;
399 } 405 }
400 } 406 }
401   407