corrade-lsl-templates – Blame information for rev 42
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
8 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
42 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
8 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // A module that invites people to the group members. |
||
6 | // |
||
7 | /////////////////////////////////////////////////////////////////////////// |
||
8 | |||
9 | /////////////////////////////////////////////////////////////////////////// |
||
41 | office | 10 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
8 | 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); |
||
8 | office | 18 | return ""; |
19 | } |
||
42 | office | 20 | |
8 | office | 21 | /////////////////////////////////////////////////////////////////////////// |
42 | office | 22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
8 | 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 // |
8 | 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 // |
8 | 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 // |
8 | 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 // |
8 | office | 113 | /////////////////////////////////////////////////////////////////////////// |
114 | string wasListToCSV(list l) { |
||
115 | list v = []; |
||
116 | do { |
||
117 | string a = llDumpList2String( |
||
118 | llParseStringKeepNulls( |
||
119 | llList2String( |
||
42 | office | 120 | l, |
8 | office | 121 | |
42 | office | 122 | ), |
123 | ["\""], |
||
8 | office | 124 | [] |
125 | ), |
||
126 | "\"\"" |
||
127 | ); |
||
128 | if(llParseStringKeepNulls( |
||
42 | office | 129 | a, |
8 | office | 130 | [" ", ",", "\n", "\""], [] |
42 | office | 131 | ) != |
8 | 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 // |
8 | 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 | ["+"], |
||
8 | office | 152 | [] |
42 | office | 153 | ), |
8 | office | 154 | " " |
42 | office | 155 | ), |
156 | ["%0D%0A"], |
||
8 | office | 157 | [] |
42 | office | 158 | ), |
8 | office | 159 | "\n" |
160 | ) |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | // configuration data |
||
165 | string configuration = ""; |
||
166 | // store message over state. |
||
167 | string data = ""; |
||
168 | string firstname = ""; |
||
169 | string lastname = ""; |
||
170 | |||
171 | default { |
||
172 | state_entry() { |
||
173 | llOwnerSay("[Invite] Starting..."); |
||
174 | llSetTimerEvent(10); |
||
175 | } |
||
176 | link_message(integer sender, integer num, string message, key id) { |
||
177 | if(id != "configuration") return; |
||
178 | llOwnerSay("[Invite] Got configuration..."); |
||
179 | configuration = message; |
||
180 | state listen_group; |
||
181 | } |
||
182 | timer() { |
||
183 | llOwnerSay("[Invite] Requesting configuration..."); |
||
184 | llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); |
||
185 | } |
||
186 | on_rez(integer num) { |
||
187 | llResetScript(); |
||
188 | } |
||
189 | changed(integer change) { |
||
42 | office | 190 | if((change & CHANGED_INVENTORY) || |
191 | (change & CHANGED_REGION_START) || |
||
8 | office | 192 | (change & CHANGED_OWNER)) { |
193 | llResetScript(); |
||
194 | } |
||
195 | } |
||
196 | state_exit() { |
||
197 | llSetTimerEvent(0); |
||
198 | } |
||
199 | } |
||
200 | |||
201 | state listen_group { |
||
202 | state_entry() { |
||
203 | // DEBUG |
||
204 | llOwnerSay("[Invite] Waiting for group messages..."); |
||
205 | } |
||
206 | link_message(integer sender, integer num, string message, key id) { |
||
207 | // We only care about notifications now. |
||
208 | if(id != "notification") |
||
209 | return; |
||
42 | office | 210 | |
8 | office | 211 | // This script only processes group notifications. |
42 | office | 212 | if(wasKeyValueGet("type", message) != "group" || |
213 | (wasKeyValueGet("type", message) == "group" && |
||
214 | wasURLUnescape(wasKeyValueGet("group", message)) != |
||
215 | wasKeyValueGet("group", configuration))) |
||
8 | office | 216 | return; |
42 | office | 217 | |
8 | office | 218 | // Get the sent message. |
219 | data = wasURLUnescape( |
||
220 | wasKeyValueGet( |
||
42 | office | 221 | "message", |
8 | office | 222 | message |
223 | ) |
||
224 | ); |
||
42 | office | 225 | |
11 | office | 226 | // Check if this is an eggdrop command. |
42 | office | 227 | if(llGetSubString(data, 0, 0) != |
8 | office | 228 | wasKeyValueGet("command", configuration)) |
229 | return; |
||
42 | office | 230 | |
11 | office | 231 | // Check if the command matches the current module. |
15 | office | 232 | list command = llParseString2List(data, [" "], []); |
42 | office | 233 | if(llList2String(command, 0) != |
15 | office | 234 | wasKeyValueGet("command", configuration) + "invite") |
8 | office | 235 | return; |
42 | office | 236 | |
8 | office | 237 | // Remove command. |
238 | command = llDeleteSubList(command, 0, 0); |
||
42 | office | 239 | |
8 | office | 240 | // Dump the rest of the message. |
241 | data = llDumpList2String(command, " "); |
||
242 | |||
42 | office | 243 | // Search for agent. |
8 | office | 244 | state search; |
245 | } |
||
246 | on_rez(integer num) { |
||
247 | llResetScript(); |
||
248 | } |
||
249 | changed(integer change) { |
||
42 | office | 250 | if((change & CHANGED_INVENTORY) || |
251 | (change & CHANGED_REGION_START) || |
||
8 | office | 252 | (change & CHANGED_OWNER)) { |
253 | llResetScript(); |
||
254 | } |
||
255 | } |
||
256 | } |
||
257 | |||
258 | state search { |
||
259 | state_entry() { |
||
260 | // DEBUG |
||
261 | llOwnerSay("[Invite] Searching for agent."); |
||
262 | llInstantMessage( |
||
263 | wasKeyValueGet( |
||
42 | office | 264 | "corrade", |
8 | office | 265 | configuration |
42 | office | 266 | ), |
8 | office | 267 | wasKeyValueEncode( |
268 | [ |
||
269 | "command", "directorysearch", |
||
270 | "group", wasURLEscape( |
||
271 | wasKeyValueGet( |
||
42 | office | 272 | "group", |
8 | office | 273 | configuration |
274 | ) |
||
275 | ), |
||
276 | "password", wasURLEscape( |
||
277 | wasKeyValueGet( |
||
42 | office | 278 | "password", |
8 | office | 279 | configuration |
280 | ) |
||
281 | ), |
||
282 | "type", "people", |
||
283 | "name", wasURLEscape(data), |
||
284 | /*"sift", wasURLEscape( |
||
285 | wasListToCSV( |
||
286 | [ |
||
287 | "match", |
||
288 | wasURLEscape("(?i),?([^,$]*" + data +"[^,$]*),?") |
||
289 | ] |
||
290 | ) |
||
291 | ),*/ |
||
42 | office | 292 | "callback", wasURLEscape( |
293 | wasKeyValueGet( |
||
294 | "URL", |
||
295 | configuration |
||
296 | ) |
||
297 | ) |
||
8 | office | 298 | ] |
299 | ) |
||
300 | ); |
||
301 | llSetTimerEvent(60); |
||
302 | } |
||
42 | office | 303 | link_message(integer sender, integer num, string body, key id) { |
304 | // Only process callbacks for the database command. |
||
305 | if(id != "callback" || wasKeyValueGet("command", body) != "directorysearch") |
||
306 | return; |
||
307 | |||
308 | if(wasKeyValueGet("success", body) != "True") { |
||
8 | office | 309 | // DEBUG |
42 | office | 310 | llOwnerSay("[Invite] Unable to search for agent: " + |
8 | office | 311 | wasURLUnescape( |
312 | wasKeyValueGet("error", body) |
||
313 | ) |
||
314 | ); |
||
315 | state listen_group; |
||
316 | } |
||
42 | office | 317 | |
8 | office | 318 | list first_last = llParseString2List(data, [" "], []); |
319 | firstname = llList2String(first_last, 0); |
||
320 | lastname = llList2String(first_last, 1); |
||
42 | office | 321 | |
8 | office | 322 | list found_agent = wasCSVToList( |
323 | wasURLUnescape( |
||
324 | wasKeyValueGet("data", body) |
||
325 | ) |
||
326 | ); |
||
42 | office | 327 | |
8 | office | 328 | if(llToUpper( |
329 | llList2String( |
||
330 | found_agent, |
||
331 | llListFindList( |
||
42 | office | 332 | found_agent, |
8 | office | 333 | (list)"FirstName" |
334 | ) + 1 |
||
335 | ) |
||
336 | ) != llToUpper(firstname) || |
||
337 | llToUpper( |
||
338 | llList2String( |
||
339 | found_agent, |
||
340 | llListFindList( |
||
341 | found_agent, |
||
342 | (list)"LastName" |
||
343 | ) + 1 |
||
344 | ) |
||
345 | ) != llToUpper(lastname)) { |
||
346 | data = "Agent not found."; |
||
347 | state tell; |
||
348 | } |
||
42 | office | 349 | |
8 | office | 350 | state invite; |
351 | } |
||
352 | timer() { |
||
353 | state listen_group; |
||
354 | } |
||
355 | on_rez(integer num) { |
||
356 | llResetScript(); |
||
357 | } |
||
358 | changed(integer change) { |
||
42 | office | 359 | if((change & CHANGED_INVENTORY) || |
360 | (change & CHANGED_REGION_START) || |
||
8 | office | 361 | (change & CHANGED_OWNER)) { |
362 | llResetScript(); |
||
363 | } |
||
364 | } |
||
365 | state_exit() { |
||
366 | llSetTimerEvent(0); |
||
367 | } |
||
368 | } |
||
369 | |||
370 | state invite { |
||
371 | state_entry() { |
||
372 | // DEBUG |
||
373 | llOwnerSay("[Invite] inviting..."); |
||
374 | llInstantMessage( |
||
375 | wasKeyValueGet( |
||
42 | office | 376 | "corrade", |
8 | office | 377 | configuration |
42 | office | 378 | ), |
8 | office | 379 | wasKeyValueEncode( |
380 | [ |
||
381 | "command", "invite", |
||
382 | "group", wasURLEscape( |
||
383 | wasKeyValueGet( |
||
42 | office | 384 | "group", |
8 | office | 385 | configuration |
386 | ) |
||
387 | ), |
||
388 | "password", wasURLEscape( |
||
389 | wasKeyValueGet( |
||
42 | office | 390 | "password", |
8 | office | 391 | configuration |
392 | ) |
||
393 | ), |
||
394 | "firstname", firstname, |
||
395 | "lastname", lastname, |
||
396 | "soft", "True", |
||
397 | "verify", "False", |
||
42 | office | 398 | "callback", wasURLEscape( |
399 | wasKeyValueGet( |
||
400 | "URL", |
||
401 | configuration |
||
402 | ) |
||
403 | ) |
||
8 | office | 404 | ] |
405 | ) |
||
406 | ); |
||
407 | llSetTimerEvent(60); |
||
408 | } |
||
42 | office | 409 | link_message(integer sender, integer num, string body, key id) { |
410 | // Only process callbacks for the database command. |
||
411 | if(id != "callback" || wasKeyValueGet("command", body) != "invite") |
||
412 | return; |
||
413 | |||
414 | if(wasKeyValueGet("success", body) != "True") { |
||
8 | office | 415 | // DEBUG |
42 | office | 416 | llOwnerSay("[Eject] Unable to invite agent: " + |
8 | office | 417 | wasURLUnescape( |
418 | wasKeyValueGet("error", body) |
||
419 | ) |
||
420 | ); |
||
421 | state listen_group; |
||
422 | } |
||
42 | office | 423 | |
8 | office | 424 | data = "Butters (Jym) was sent to pick them up!"; |
42 | office | 425 | |
8 | office | 426 | state tell; |
427 | } |
||
428 | timer() { |
||
429 | state listen_group; |
||
430 | } |
||
431 | on_rez(integer num) { |
||
432 | llResetScript(); |
||
433 | } |
||
434 | changed(integer change) { |
||
42 | office | 435 | if((change & CHANGED_INVENTORY) || |
436 | (change & CHANGED_REGION_START) || |
||
8 | office | 437 | (change & CHANGED_OWNER)) { |
438 | llResetScript(); |
||
439 | } |
||
440 | } |
||
441 | state_exit() { |
||
442 | llSetTimerEvent(0); |
||
443 | } |
||
444 | } |
||
445 | |||
446 | state tell { |
||
447 | state_entry() { |
||
448 | // DEBUG |
||
449 | llOwnerSay("[Invite] Sending to group."); |
||
450 | llInstantMessage( |
||
451 | wasKeyValueGet( |
||
42 | office | 452 | "corrade", |
8 | office | 453 | configuration |
42 | office | 454 | ), |
8 | office | 455 | wasKeyValueEncode( |
456 | [ |
||
457 | "command", "tell", |
||
458 | "group", wasURLEscape( |
||
459 | wasKeyValueGet( |
||
42 | office | 460 | "group", |
8 | office | 461 | configuration |
462 | ) |
||
463 | ), |
||
464 | "password", wasURLEscape( |
||
465 | wasKeyValueGet( |
||
42 | office | 466 | "password", |
8 | office | 467 | configuration |
468 | ) |
||
469 | ), |
||
470 | "entity", "group", |
||
471 | "message", wasURLEscape(data) |
||
472 | ] |
||
473 | ) |
||
474 | ); |
||
475 | state listen_group; |
||
476 | } |
||
477 | } |