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