corrade-lsl-templates – Blame information for rev 31
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
29 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // |
2 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // This script is a passthrough or proxy script for script permissions that |
||
6 | // are received by Corrade. The script binds to Corrade's permission |
||
7 | // notification and then any permission request received by Corrade gets |
||
8 | // sent to you. When you either accept or decline, Corrade will either |
||
9 | // grant or decline the permission request. |
||
10 | // |
||
11 | // For more information on Corrade, please see: |
||
12 | // http://grimore.org/secondlife/scripted_agents/corrade |
||
13 | // |
||
14 | /////////////////////////////////////////////////////////////////////////// |
||
15 | |||
16 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 17 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 18 | /////////////////////////////////////////////////////////////////////////// |
19 | string wasKeyValueGet(string k, string data) { |
||
20 | if(llStringLength(data) == 0) return ""; |
||
21 | if(llStringLength(k) == 0) return ""; |
||
22 | list a = llParseString2List(data, ["&", "="], []); |
||
23 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
||
24 | if(i != -1) return llList2String(a, 2*i+1); |
||
25 | return ""; |
||
26 | } |
||
27 | |||
28 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 29 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 30 | /////////////////////////////////////////////////////////////////////////// |
31 | string wasKeyValueEncode(list data) { |
||
32 | list k = llList2ListStrided(data, 0, -1, 2); |
||
33 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
||
34 | data = []; |
||
35 | do { |
||
36 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
||
37 | k = llDeleteSubList(k, 0, 0); |
||
38 | v = llDeleteSubList(v, 0, 0); |
||
39 | } while(llGetListLength(k) != 0); |
||
40 | return llDumpList2String(data, "&"); |
||
41 | } |
||
42 | |||
43 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 44 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 45 | /////////////////////////////////////////////////////////////////////////// |
46 | // escapes a string in conformance with RFC1738 |
||
47 | string wasURLEscape(string i) { |
||
48 | string o = ""; |
||
49 | do { |
||
50 | string c = llGetSubString(i, 0, 0); |
||
51 | i = llDeleteSubString(i, 0, 0); |
||
52 | if(c == "") jump continue; |
||
53 | if(c == " ") { |
||
54 | o += "+"; |
||
55 | jump continue; |
||
56 | } |
||
57 | if(c == "\n") { |
||
58 | o += "%0D" + llEscapeURL(c); |
||
59 | jump continue; |
||
60 | } |
||
61 | o += llEscapeURL(c); |
||
62 | @continue; |
||
63 | } while(i != ""); |
||
64 | return o; |
||
65 | } |
||
66 | |||
67 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 68 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 69 | /////////////////////////////////////////////////////////////////////////// |
70 | list wasCSVToList(string csv) { |
||
71 | list l = []; |
||
72 | list s = []; |
||
73 | string m = ""; |
||
74 | do { |
||
75 | string a = llGetSubString(csv, 0, 0); |
||
76 | csv = llDeleteSubString(csv, 0, 0); |
||
77 | if(a == ",") { |
||
78 | if(llList2String(s, -1) != "\"") { |
||
79 | l += m; |
||
80 | m = ""; |
||
81 | jump continue; |
||
82 | } |
||
83 | m += a; |
||
84 | jump continue; |
||
85 | } |
||
86 | if(a == "\"" && llGetSubString(csv, 0, 0) == a) { |
||
87 | m += a; |
||
88 | csv = llDeleteSubString(csv, 0, 0); |
||
89 | jump continue; |
||
90 | } |
||
91 | if(a == "\"") { |
||
92 | if(llList2String(s, -1) != a) { |
||
93 | s += a; |
||
94 | jump continue; |
||
95 | } |
||
96 | s = llDeleteSubList(s, -1, -1); |
||
97 | jump continue; |
||
98 | } |
||
99 | m += a; |
||
100 | @continue; |
||
101 | } while(csv != ""); |
||
102 | // postcondition: length(s) = 0 |
||
103 | return l + m; |
||
104 | } |
||
105 | |||
106 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 107 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 108 | /////////////////////////////////////////////////////////////////////////// |
109 | string wasListToCSV(list l) { |
||
110 | list v = []; |
||
111 | do { |
||
112 | string a = llDumpList2String( |
||
113 | llParseStringKeepNulls( |
||
114 | llList2String( |
||
115 | l, |
||
116 | |||
117 | ), |
||
118 | ["\""], |
||
119 | [] |
||
120 | ), |
||
121 | "\"\"" |
||
122 | ); |
||
123 | if(llParseStringKeepNulls( |
||
124 | a, |
||
125 | [" ", ",", "\n", "\""], [] |
||
126 | ) != |
||
127 | (list) a |
||
128 | ) a = "\"" + a + "\""; |
||
129 | v += a; |
||
130 | l = llDeleteSubList(l, 0, 0); |
||
131 | } while(l != []); |
||
132 | return llDumpList2String(v, ","); |
||
133 | } |
||
134 | |||
135 | /////////////////////////////////////////////////////////////////////////// |
||
29 | office | 136 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
2 | office | 137 | /////////////////////////////////////////////////////////////////////////// |
138 | // unescapes a string in conformance with RFC1738 |
||
139 | string wasURLUnescape(string i) { |
||
140 | return llUnescapeURL( |
||
141 | llDumpList2String( |
||
142 | llParseString2List( |
||
143 | llDumpList2String( |
||
144 | llParseString2List( |
||
145 | i, |
||
146 | ["+"], |
||
147 | [] |
||
148 | ), |
||
149 | " " |
||
150 | ), |
||
151 | ["%0D%0A"], |
||
152 | [] |
||
153 | ), |
||
154 | "\n" |
||
155 | ) |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | // callback URL |
||
160 | string callback = ""; |
||
161 | // configuration data |
||
162 | string configuration = ""; |
||
163 | // listen handle |
||
164 | integer listenHandle = 0; |
||
165 | |||
166 | // store dialog details |
||
167 | string permission_region = ""; |
||
168 | list permission_requested = []; |
||
169 | key permission_item = NULL_KEY; |
||
170 | key permission_task = NULL_KEY; |
||
171 | |||
172 | default { |
||
173 | state_entry() { |
||
174 | llSetTimerEvent(1); |
||
175 | } |
||
176 | link_message(integer sender, integer num, string message, key id) { |
||
177 | if(sender != 1 || id != "configuration") return; |
||
178 | configuration = message; |
||
179 | state off; |
||
180 | } |
||
181 | timer() { |
||
182 | llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY); |
||
183 | } |
||
184 | attach(key id) { |
||
185 | llResetScript(); |
||
186 | } |
||
187 | on_rez(integer num) { |
||
188 | llResetScript(); |
||
189 | } |
||
190 | changed(integer change) { |
||
191 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
192 | llResetScript(); |
||
193 | } |
||
194 | } |
||
195 | state_exit() { |
||
196 | llSetTimerEvent(0); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | state off { |
||
201 | state_entry() { |
||
202 | llReleaseControls(); |
||
203 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
204 | } |
||
205 | touch_end(integer num) { |
||
206 | state on; |
||
207 | } |
||
208 | attach(key id) { |
||
209 | llResetScript(); |
||
210 | } |
||
211 | on_rez(integer num) { |
||
212 | llResetScript(); |
||
213 | } |
||
214 | changed(integer change) { |
||
215 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
216 | llResetScript(); |
||
217 | } |
||
218 | } |
||
219 | } |
||
220 | |||
221 | state on { |
||
222 | state_entry() { |
||
223 | llSetColor(<0,.5,0>, ALL_SIDES); |
||
224 | state url; |
||
225 | } |
||
226 | attach(key id) { |
||
227 | llResetScript(); |
||
228 | } |
||
229 | on_rez(integer num) { |
||
230 | llResetScript(); |
||
231 | } |
||
232 | changed(integer change) { |
||
233 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
234 | llResetScript(); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | |||
239 | state url { |
||
240 | state_entry() { |
||
241 | // DEBUG |
||
242 | llOwnerSay("Requesting URL..."); |
||
243 | llRequestURL(); |
||
244 | } |
||
245 | touch_end(integer num) { |
||
246 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
247 | llResetScript(); |
||
248 | } |
||
249 | http_request(key id, string method, string body) { |
||
250 | if(method != URL_REQUEST_GRANTED) return; |
||
251 | callback = body; |
||
252 | // DEBUG |
||
253 | llOwnerSay("Got URL..."); |
||
254 | state permission; |
||
255 | } |
||
256 | attach(key id) { |
||
257 | llResetScript(); |
||
258 | } |
||
259 | on_rez(integer num) { |
||
260 | llResetScript(); |
||
261 | } |
||
262 | changed(integer change) { |
||
263 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
264 | llResetScript(); |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | |||
269 | state permission { |
||
270 | state_entry() { |
||
271 | // DEBUG |
||
272 | llOwnerSay("Binding to the script permission notification..."); |
||
273 | llInstantMessage( |
||
274 | (key)wasKeyValueGet( |
||
275 | "corrade", |
||
276 | configuration |
||
277 | ), |
||
278 | wasKeyValueEncode( |
||
279 | [ |
||
280 | "command", "notify", |
||
281 | "group", wasURLEscape( |
||
282 | wasKeyValueGet( |
||
283 | "group", |
||
284 | configuration |
||
285 | ) |
||
286 | ), |
||
287 | "password", wasURLEscape( |
||
288 | wasKeyValueGet( |
||
289 | "password", |
||
290 | configuration |
||
291 | ) |
||
292 | ), |
||
293 | "action", "add", |
||
294 | "type", "permission", |
||
295 | "URL", wasURLEscape(callback), |
||
296 | "callback", wasURLEscape(callback) |
||
297 | ] |
||
298 | ) |
||
299 | ); |
||
300 | llSetTimerEvent(60); |
||
301 | } |
||
302 | touch_end(integer num) { |
||
303 | llSetColor(<.5,0,0>, ALL_SIDES); |
||
304 | llResetScript(); |
||
305 | } |
||
306 | timer() { |
||
307 | // DEBUG |
||
308 | llOwnerSay("Timeout binding to the script permission notification..."); |
||
309 | llResetScript(); |
||
310 | } |
||
311 | http_request(key id, string method, string body) { |
||
312 | llHTTPResponse(id, 200, "OK"); |
||
313 | if(wasKeyValueGet("command", body) != "notify" || |
||
314 | wasKeyValueGet("success", body) != "True") { |
||
315 | // DEBUG |
||
316 | llOwnerSay("Failed to bind to the script permission notification..." + wasKeyValueGet("error", body)); |
||
317 | llResetScript(); |
||
318 | } |
||
319 | // DEBUG |
||
320 | llOwnerSay("Script permission notification installed..."); |
||
321 | state main; |
||
322 | } |
||
323 | attach(key id) { |
||
324 | llResetScript(); |
||
325 | } |
||
326 | on_rez(integer num) { |
||
327 | llResetScript(); |
||
328 | } |
||
329 | changed(integer change) { |
||
330 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
331 | llResetScript(); |
||
332 | } |
||
333 | } |
||
334 | state_exit() { |
||
335 | llSetTimerEvent(0); |
||
336 | } |
||
337 | } |
||
338 | |||
339 | state main { |
||
340 | state_entry() { |
||
341 | // DEBUG |
||
342 | llOwnerSay("Waiting for script permission..."); |
||
343 | llSetTimerEvent(1); |
||
344 | } |
||
345 | touch_end(integer num) { |
||
346 | state uninstall; |
||
347 | } |
||
348 | timer() { |
||
349 | llRequestAgentData( |
||
350 | (key)wasKeyValueGet( |
||
351 | "corrade", |
||
352 | configuration |
||
353 | ), DATA_ONLINE); |
||
354 | } |
||
355 | dataserver(key id, string data) { |
||
356 | if(data != "1") llResetScript(); |
||
357 | } |
||
358 | http_request(key id, string method, string body) { |
||
359 | llHTTPResponse(id, 200, "OK"); |
||
360 | |||
361 | // get the script permission region |
||
362 | permission_region = wasURLUnescape( |
||
363 | wasKeyValueGet( |
||
364 | "region", |
||
365 | body |
||
366 | ) |
||
367 | ); |
||
368 | |||
369 | // get the script permission item |
||
370 | permission_item = (key)wasURLUnescape( |
||
371 | wasKeyValueGet( |
||
372 | "item", |
||
373 | body |
||
374 | ) |
||
375 | ); |
||
376 | |||
377 | // get the script permission task |
||
378 | permission_task = (key)wasURLUnescape( |
||
379 | wasKeyValueGet( |
||
380 | "task", |
||
381 | body |
||
382 | ) |
||
383 | ); |
||
384 | |||
385 | // get the buttons that the dialog has |
||
386 | permission_requested = wasCSVToList( |
||
387 | wasURLUnescape( |
||
388 | wasKeyValueGet( |
||
389 | "permissions", |
||
390 | body |
||
391 | ) |
||
392 | ) |
||
393 | ); |
||
394 | |||
395 | // get the name of the object owner. |
||
396 | string name = wasURLUnescape( |
||
397 | wasKeyValueGet( |
||
398 | "firstname", |
||
399 | body |
||
400 | ) |
||
401 | ) + " " + wasURLUnescape( |
||
402 | wasKeyValueGet( |
||
403 | "lastname", |
||
404 | body |
||
405 | ) |
||
406 | ); |
||
407 | |||
408 | // DEBUG |
||
409 | llOwnerSay("Requested permissions: " + llDumpList2String(permission_requested, "|")); |
||
410 | listenHandle = llListen(-14, "", llGetOwner(), ""); |
||
411 | llDialog(llGetOwner(), |
||
412 | "[CORRADE]: Script permissions requested: " + wasListToCSV(permission_requested) + " from an object owned by " + name, |
||
413 | [ |
||
414 | "Accept", |
||
415 | "Decline" |
||
416 | ], |
||
417 | -14 |
||
418 | ); |
||
419 | } |
||
420 | listen(integer channel, string name, key id, string message) { |
||
421 | llListenRemove(listenHandle); |
||
422 | if(message == "Decline") |
||
423 | permission_requested = []; |
||
424 | llInstantMessage( |
||
425 | wasKeyValueGet( |
||
426 | "corrade", |
||
427 | configuration |
||
428 | ), |
||
429 | wasKeyValueEncode( |
||
430 | [ |
||
431 | "command", "replytoscriptpermissionrequest", |
||
432 | "group", wasURLEscape( |
||
433 | wasKeyValueGet( |
||
434 | "group", |
||
435 | configuration |
||
436 | ) |
||
437 | ), |
||
438 | "password", wasURLEscape( |
||
439 | wasKeyValueGet( |
||
440 | "password", |
||
441 | configuration |
||
442 | ) |
||
443 | ), |
||
444 | "action", "reply", |
||
445 | "task", permission_task, |
||
446 | "item", permission_item, |
||
447 | "permissions", wasListToCSV(permission_requested), |
||
448 | "region", wasURLEscape(permission_region) |
||
449 | ] |
||
450 | ) |
||
451 | ); |
||
452 | } |
||
453 | attach(key id) { |
||
454 | llResetScript(); |
||
455 | } |
||
456 | on_rez(integer num) { |
||
457 | llResetScript(); |
||
458 | } |
||
459 | changed(integer change) { |
||
460 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
461 | llResetScript(); |
||
462 | } |
||
463 | } |
||
464 | state_exit() { |
||
465 | llSetTimerEvent(0); |
||
466 | } |
||
467 | } |
||
468 | |||
469 | state uninstall { |
||
470 | state_entry() { |
||
471 | // DEBUG |
||
472 | llOwnerSay("Uninstalling script permission notification..."); |
||
473 | llInstantMessage( |
||
474 | (key)wasKeyValueGet( |
||
475 | "corrade", |
||
476 | configuration |
||
477 | ), |
||
478 | wasKeyValueEncode( |
||
479 | [ |
||
480 | "command", "notify", |
||
481 | "group", wasURLEscape( |
||
482 | wasKeyValueGet( |
||
483 | "group", |
||
484 | configuration |
||
485 | ) |
||
486 | ), |
||
487 | "password", wasURLEscape( |
||
488 | wasKeyValueGet( |
||
489 | "password", |
||
490 | configuration |
||
491 | ) |
||
492 | ), |
||
493 | "action", "remove", |
||
494 | "type", "permission", |
||
495 | "URL", wasURLEscape(callback), |
||
496 | "callback", wasURLEscape(callback) |
||
497 | ] |
||
498 | ) |
||
499 | ); |
||
500 | llSetTimerEvent(60); |
||
501 | } |
||
502 | timer() { |
||
503 | // DEBUG |
||
504 | llOwnerSay("Timeout uninstalling the script permission notification..."); |
||
505 | llResetScript(); |
||
506 | } |
||
507 | http_request(key id, string method, string body) { |
||
508 | llHTTPResponse(id, 200, "OK"); |
||
509 | if(wasKeyValueGet("command", body) != "notify" || |
||
510 | wasKeyValueGet("success", body) != "True") { |
||
511 | // DEBUG |
||
512 | llOwnerSay("Failed to uninstall the script permission notification..." + wasKeyValueGet("error", body)); |
||
513 | llResetScript(); |
||
514 | } |
||
515 | // DEBUG |
||
516 | llOwnerSay("Script permission notification uninstalled..."); |
||
517 | llResetScript(); |
||
518 | } |
||
519 | attach(key id) { |
||
520 | llResetScript(); |
||
521 | } |
||
522 | on_rez(integer num) { |
||
523 | llResetScript(); |
||
524 | } |
||
525 | changed(integer change) { |
||
526 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) { |
||
527 | llResetScript(); |
||
528 | } |
||
529 | } |
||
530 | } |