corrade-lsl-templates – Diff between revs 41 and 42

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 41 Rev 42
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // 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 ///////////////////////////////////////////////////////////////////////////
Line 15... Line 15...
15 list a = llParseStringKeepNulls(data, ["&", "="], []); 15 list a = llParseStringKeepNulls(data, ["&", "="], []);
16 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); 16 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
17 if(i != -1) return llList2String(a, 2*i+1); 17 if(i != -1) return llList2String(a, 2*i+1);
18 return ""; 18 return "";
19 } 19 }
20 20  
21 /////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////
22 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 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 = [];
Line 32... Line 32...
32 } while(llGetListLength(k) != 0); 32 } while(llGetListLength(k) != 0);
33 return llDumpList2String(data, "&"); 33 return llDumpList2String(data, "&");
34 } 34 }
Line 35... Line 35...
35   35  
36 /////////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////////
37 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // 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);
Line 44... Line 44...
44 return <x, y, 0>; 44 return <x, y, 0>;
45 return wasCirclePoint(radius); 45 return wasCirclePoint(radius);
46 } 46 }
Line 47... Line 47...
47   47  
48 /////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////
49 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 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 = "";
Line 68... Line 68...
68 } while(i != ""); 68 } while(i != "");
69 return o; 69 return o;
70 } 70 }
Line 71... Line 71...
71   71  
72 /////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////
73 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 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 = [];
Line 107... Line 107...
107 // postcondition: length(s) = 0 107 // postcondition: length(s) = 0
108 return l + m; 108 return l + m;
109 } 109 }
Line 110... Line 110...
110   110  
111 /////////////////////////////////////////////////////////////////////////// 111 ///////////////////////////////////////////////////////////////////////////
112 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 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, ",");
Line 138... Line 138...
138 } 138 }
139   139  
140 /////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////
141 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 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 )
Line 161... Line 161...
161 ); 161 );
162 } 162 }
163   -  
164 // configuration data -  
165 string configuration = ""; 163  
166 // callback URL 164 // configuration data
Line 167... Line 165...
167 string URL = ""; 165 string configuration = "";
168 // store message over state. 166 // store message over state.
Line 185... Line 183...
185 } 183 }
186 on_rez(integer num) { 184 on_rez(integer num) {
187 llResetScript(); 185 llResetScript();
188 } 186 }
189 changed(integer change) { 187 changed(integer change) {
190 if((change & CHANGED_INVENTORY) || 188 if((change & CHANGED_INVENTORY) ||
191 (change & CHANGED_REGION_START) || 189 (change & CHANGED_REGION_START) ||
192 (change & CHANGED_OWNER)) { 190 (change & CHANGED_OWNER)) {
193 llResetScript(); 191 llResetScript();
194 } 192 }
195 } 193 }
196 state_exit() { 194 state_exit() {
Line 205... Line 203...
205 } 203 }
206 link_message(integer sender, integer num, string message, key id) { 204 link_message(integer sender, integer num, string message, key id) {
207 // We only care about notifications now. 205 // We only care about notifications now.
208 if(id != "notification") 206 if(id != "notification")
209 return; 207 return;
210 208  
211 // This script only processes group notifications. 209 // This script only processes group notifications.
212 if(wasKeyValueGet("type", message) != "group") 210 if(wasKeyValueGet("type", message) != "group" ||
-   211 (wasKeyValueGet("type", message) == "group" &&
-   212 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   213 wasKeyValueGet("group", configuration)))
213 return; 214 return;
214 215  
215 // Get the sent message. 216 // Get the sent message.
216 data = wasURLUnescape( 217 data = wasURLUnescape(
217 wasKeyValueGet( 218 wasKeyValueGet(
218 "message", 219 "message",
219 message 220 message
220 ) 221 )
221 ); 222 );
222 223  
223 // Check if this is an eggdrop command. 224 // Check if this is an eggdrop command.
224 if(llGetSubString(data, 0, 0) != 225 if(llGetSubString(data, 0, 0) !=
225 wasKeyValueGet("command", configuration)) 226 wasKeyValueGet("command", configuration))
226 return; 227 return;
227 228  
228 // Check if the command matches the current module. 229 // Check if the command matches the current module.
229 list command = llParseString2List(data, [" "], []); 230 list command = llParseString2List(data, [" "], []);
230 if(llList2String(command, 0) != 231 if(llList2String(command, 0) !=
231 wasKeyValueGet("command", configuration) + "spank") 232 wasKeyValueGet("command", configuration) + "spank")
232 return; 233 return;
233 234  
234 // Remove command. 235 // Remove command.
235 command = llDeleteSubList(command, 0, 0); 236 command = llDeleteSubList(command, 0, 0);
236 237  
237 // Dump the rest of the message. 238 // Dump the rest of the message.
238 data = llDumpList2String(command, " "); 239 data = llDumpList2String(command, " ");
239 -  
240 // Get an URL. -  
241 state url; -  
242 } -  
243 on_rez(integer num) { -  
244 llResetScript(); -  
245 } -  
246 changed(integer change) { -  
247 if((change & CHANGED_INVENTORY) || -  
248 (change & CHANGED_REGION_START) || -  
249 (change & CHANGED_OWNER)) { -  
250 llResetScript(); -  
251 } -  
252 } -  
253 } -  
Line 254... Line -...
254   -  
255 state url { -  
256 state_entry() { -  
257 // DEBUG -  
258 llOwnerSay("[Spank] Requesting URL..."); 240  
259 llRequestURL(); -  
260 } -  
261 http_request(key id, string method, string body) { -  
262 if(method != URL_REQUEST_GRANTED) return; -  
263 URL = body; -  
264 // DEBUG -  
265 llOwnerSay("[Spank] Got URL..."); 241 // Search for member.
266 state search; 242 state search;
267 } 243 }
268 on_rez(integer num) { 244 on_rez(integer num) {
269 llResetScript(); 245 llResetScript();
270 } 246 }
271 changed(integer change) { 247 changed(integer change) {
272 if((change & CHANGED_INVENTORY) || 248 if((change & CHANGED_INVENTORY) ||
273 (change & CHANGED_REGION_START) || 249 (change & CHANGED_REGION_START) ||
274 (change & CHANGED_OWNER)) { 250 (change & CHANGED_OWNER)) {
275 llResetScript(); 251 llResetScript();
276 } 252 }
277 } 253 }
Line 281... Line 257...
281 state_entry() { 257 state_entry() {
282 // DEBUG 258 // DEBUG
283 llOwnerSay("[Spank] Searching for agent."); 259 llOwnerSay("[Spank] Searching for agent.");
284 llInstantMessage( 260 llInstantMessage(
285 wasKeyValueGet( 261 wasKeyValueGet(
286 "corrade", 262 "corrade",
287 configuration 263 configuration
288 ), 264 ),
289 wasKeyValueEncode( 265 wasKeyValueEncode(
290 [ 266 [
291 "command", "getmembers", 267 "command", "getmembers",
292 "group", wasURLEscape( 268 "group", wasURLEscape(
293 wasKeyValueGet( 269 wasKeyValueGet(
294 "group", 270 "group",
295 configuration 271 configuration
296 ) 272 )
297 ), 273 ),
298 "password", wasURLEscape( 274 "password", wasURLEscape(
299 wasKeyValueGet( 275 wasKeyValueGet(
300 "password", 276 "password",
301 configuration 277 configuration
302 ) 278 )
303 ), 279 ),
304 "sift", wasURLEscape( 280 "sift", wasURLEscape(
305 wasListToCSV( 281 wasListToCSV(
Line 307... Line 283...
307 "match", 283 "match",
308 wasURLEscape("(?i),?\"([^\",$]*" + data + "[^\",$]*)\",?") 284 wasURLEscape("(?i),?\"([^\",$]*" + data + "[^\",$]*)\",?")
309 ] 285 ]
310 ) 286 )
311 ), 287 ),
312 "callback", wasURLEscape(URL) 288 "callback", wasURLEscape(
-   289 wasKeyValueGet(
-   290 "URL",
-   291 configuration
-   292 )
-   293 )
313 ] 294 ]
314 ) 295 )
315 ); 296 );
316 llSetTimerEvent(60); 297 llSetTimerEvent(60);
317 } 298 }
318 http_request(key id, string method, string body) { 299 link_message(integer sender, integer num, string body, key id) {
319 llHTTPResponse(id, 200, "OK"); 300 // Only process callbacks for the database command.
320 llReleaseURL(URL); -  
321 if(wasKeyValueGet("command", body) != "getmembers" || 301 if(id != "callback" || wasKeyValueGet("command", body) != "getmembers")
-   302 return;
-   303  
322 wasKeyValueGet("success", body) != "True") { 304 if(wasKeyValueGet("success", body) != "True") {
323 // DEBUG 305 // DEBUG
324 llOwnerSay("[Spank] Unable to get members: " + 306 llOwnerSay("[Spank] Unable to get members: " +
325 wasURLUnescape( 307 wasURLUnescape(
326 wasKeyValueGet("error", body) 308 wasKeyValueGet("error", body)
327 ) 309 )
328 ); 310 );
329 state listen_group; 311 state listen_group;
330 } 312 }
331 313  
332 // Dump the members to a list. 314 // Dump the members to a list.
333 list spankees = wasCSVToList( 315 list spankees = wasCSVToList(
334 wasURLUnescape( 316 wasURLUnescape(
335 wasKeyValueGet("data", body) 317 wasKeyValueGet("data", body)
336 ) 318 )
337 ); 319 );
338 320  
339 // Limit to two people to spank. 321 // Limit to two people to spank.
340 if(llGetListLength(spankees) > 2) { 322 if(llGetListLength(spankees) > 2) {
341 data = "So many people, so few hands!"; 323 data = "So many people, so few hands!";
342 return; 324 state tell;
343 } 325 }
344 326  
345 data = llList2CSV(spankees); 327 data = llList2CSV(spankees);
346 328  
347 if(data == "") { 329 if(data == "") {
348 data = "I could not find anyone to spank (story of my life)."; 330 data = "I could not find anyone to spank (story of my life).";
349 state tell; 331 state tell;
350 } 332 }
351 333  
352 data = "/me spanks " + data; 334 data = "/me spanks " + data;
353 335  
354 state tell; 336 state tell;
355 } 337 }
356 timer() { 338 timer() {
357 llReleaseURL(URL); -  
358 state listen_group; 339 state listen_group;
359 } 340 }
360 on_rez(integer num) { 341 on_rez(integer num) {
361 llResetScript(); 342 llResetScript();
362 } 343 }
363 changed(integer change) { 344 changed(integer change) {
364 if((change & CHANGED_INVENTORY) || 345 if((change & CHANGED_INVENTORY) ||
365 (change & CHANGED_REGION_START) || 346 (change & CHANGED_REGION_START) ||
366 (change & CHANGED_OWNER)) { 347 (change & CHANGED_OWNER)) {
367 llResetScript(); 348 llResetScript();
368 } 349 }
369 } 350 }
370 state_exit() { 351 state_exit() {
Line 376... Line 357...
376 state_entry() { 357 state_entry() {
377 // DEBUG 358 // DEBUG
378 llOwnerSay("[Spank] Sending to group."); 359 llOwnerSay("[Spank] Sending to group.");
379 llInstantMessage( 360 llInstantMessage(
380 wasKeyValueGet( 361 wasKeyValueGet(
381 "corrade", 362 "corrade",
382 configuration 363 configuration
383 ), 364 ),
384 wasKeyValueEncode( 365 wasKeyValueEncode(
385 [ 366 [
386 "command", "tell", 367 "command", "tell",
387 "group", wasURLEscape( 368 "group", wasURLEscape(
388 wasKeyValueGet( 369 wasKeyValueGet(
389 "group", 370 "group",
390 configuration 371 configuration
391 ) 372 )
392 ), 373 ),
393 "password", wasURLEscape( 374 "password", wasURLEscape(
394 wasKeyValueGet( 375 wasKeyValueGet(
395 "password", 376 "password",
396 configuration 377 configuration
397 ) 378 )
398 ), 379 ),
399 "entity", "group", 380 "entity", "group",
400 "message", wasURLEscape(data) 381 "message", wasURLEscape(data)