corrade-lsl-templates – Diff between revs 11 and 15
?pathlinks?
Rev 11 | Rev 15 | |||
---|---|---|---|---|
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 | // An eggdrop-like group bot using Corrade. |
5 | // An eggdrop-like group bot using Corrade. |
|
6 | // |
6 | // |
|
7 | /////////////////////////////////////////////////////////////////////////// |
7 | /////////////////////////////////////////////////////////////////////////// |
|
8 | |
8 | |
|
9 | /////////////////////////////////////////////////////////////////////////// |
9 | /////////////////////////////////////////////////////////////////////////// |
|
10 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
10 | // Copyright (C) 2015 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(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: 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) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
37 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
38 | /////////////////////////////////////////////////////////////////////////// |
38 | /////////////////////////////////////////////////////////////////////////// |
|
39 | // escapes a string in conformance with RFC1738 |
39 | // escapes a string in conformance with RFC1738 |
|
40 | string wasURLEscape(string i) { |
40 | string wasURLEscape(string i) { |
|
41 | string o = ""; |
41 | string o = ""; |
|
42 | do { |
42 | do { |
|
43 | string c = llGetSubString(i, 0, 0); |
43 | string c = llGetSubString(i, 0, 0); |
|
44 | i = llDeleteSubString(i, 0, 0); |
44 | i = llDeleteSubString(i, 0, 0); |
|
45 | if(c == "") jump continue; |
45 | if(c == "") jump continue; |
|
46 | if(c == " ") { |
46 | if(c == " ") { |
|
47 | o += "+"; |
47 | o += "+"; |
|
48 | jump continue; |
48 | jump continue; |
|
49 | } |
49 | } |
|
50 | if(c == "\n") { |
50 | if(c == "\n") { |
|
51 | o += "%0D" + llEscapeURL(c); |
51 | o += "%0D" + llEscapeURL(c); |
|
52 | jump continue; |
52 | jump continue; |
|
53 | } |
53 | } |
|
54 | o += llEscapeURL(c); |
54 | o += llEscapeURL(c); |
|
55 | @continue; |
55 | @continue; |
|
56 | } while(i != ""); |
56 | } while(i != ""); |
|
57 | return o; |
57 | return o; |
|
58 | } |
58 | } |
|
59 | |
59 | |
|
60 | /////////////////////////////////////////////////////////////////////////// |
60 | /////////////////////////////////////////////////////////////////////////// |
|
61 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
61 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
62 | /////////////////////////////////////////////////////////////////////////// |
62 | /////////////////////////////////////////////////////////////////////////// |
|
63 | // unescapes a string in conformance with RFC1738 |
63 | // unescapes a string in conformance with RFC1738 |
|
64 | string wasURLUnescape(string i) { |
64 | string wasURLUnescape(string i) { |
|
65 | return llUnescapeURL( |
65 | return llUnescapeURL( |
|
66 | llDumpList2String( |
66 | llDumpList2String( |
|
67 | llParseString2List( |
67 | llParseString2List( |
|
68 | llDumpList2String( |
68 | llDumpList2String( |
|
69 | llParseString2List( |
69 | llParseString2List( |
|
70 | i, |
70 | i, |
|
71 | ["+"], |
71 | ["+"], |
|
72 | [] |
72 | [] |
|
73 | ), |
73 | ), |
|
74 | " " |
74 | " " |
|
75 | ), |
75 | ), |
|
76 | ["%0D%0A"], |
76 | ["%0D%0A"], |
|
77 | [] |
77 | [] |
|
78 | ), |
78 | ), |
|
79 | "\n" |
79 | "\n" |
|
80 | ) |
80 | ) |
|
81 | ); |
81 | ); |
|
82 | } |
82 | } |
|
83 | |
83 | |
|
84 | /////////////////////////////////////////////////////////////////////////// |
84 | /////////////////////////////////////////////////////////////////////////// |
|
85 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
85 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
86 | /////////////////////////////////////////////////////////////////////////// |
86 | /////////////////////////////////////////////////////////////////////////// |
|
87 | string wasListToCSV(list l) { |
87 | string wasListToCSV(list l) { |
|
88 | list v = []; |
88 | list v = []; |
|
89 | do { |
89 | do { |
|
90 | string a = llDumpList2String( |
90 | string a = llDumpList2String( |
|
91 | llParseStringKeepNulls( |
91 | llParseStringKeepNulls( |
|
92 | llList2String( |
92 | llList2String( |
|
93 | l, |
93 | l, |
|
94 | 0 |
94 | 0 |
|
95 | ), |
95 | ), |
|
96 | ["\""], |
96 | ["\""], |
|
97 | [] |
97 | [] |
|
98 | ), |
98 | ), |
|
99 | "\"\"" |
99 | "\"\"" |
|
100 | ); |
100 | ); |
|
101 | if(llParseStringKeepNulls( |
101 | if(llParseStringKeepNulls( |
|
102 | a, |
102 | a, |
|
103 | [" ", ",", "\n", "\""], [] |
103 | [" ", ",", "\n", "\""], [] |
|
104 | ) != |
104 | ) != |
|
105 | (list) a |
105 | (list) a |
|
106 | ) a = "\"" + a + "\""; |
106 | ) a = "\"" + a + "\""; |
|
107 | v += a; |
107 | v += a; |
|
108 | l = llDeleteSubList(l, 0, 0); |
108 | l = llDeleteSubList(l, 0, 0); |
|
109 | } while(l != []); |
109 | } while(l != []); |
|
110 | return llDumpList2String(v, ","); |
110 | return llDumpList2String(v, ","); |
|
111 | } |
111 | } |
|
112 | |
112 | |
|
113 | // for notecard reading |
113 | // for notecard reading |
|
114 | integer line = 0; |
114 | integer line = 0; |
|
115 | |
115 | |
|
116 | // key-value data will be read into this list |
116 | // key-value data will be read into this list |
|
117 | list tuples = []; |
117 | list tuples = []; |
|
118 | string configuration = ""; |
118 | string configuration = ""; |
|
119 | // Corrade's online status. |
119 | // Corrade's online status. |
|
120 | integer online = FALSE; |
120 | integer online = FALSE; |
|
121 | integer compatible = FALSE; |
121 | integer compatible = FALSE; |
|
122 | string URL = ""; |
122 | string URL = ""; |
|
123 | |
123 | |
|
124 | // The notifications to bind to. |
124 | // The notifications to bind to. |
|
125 | list notifications = [ "group", "membership" ]; |
125 | list notifications = [ "group", "membership", "login" ]; |
|
126 | |
126 | |
|
127 | default { |
127 | default { |
|
128 | state_entry() { |
128 | state_entry() { |
|
129 | if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) { |
129 | if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) { |
|
130 | llOwnerSay("[Control] Sorry, could not find a configuration inventory notecard."); |
130 | llOwnerSay("[Control] Sorry, could not find a configuration inventory notecard."); |
|
131 | return; |
131 | return; |
|
132 | } |
132 | } |
|
133 | // DEBUG |
133 | // DEBUG |
|
134 | llOwnerSay("[Control] Reading configuration file..."); |
134 | llOwnerSay("[Control] Reading configuration file..."); |
|
135 | llGetNotecardLine("configuration", line); |
135 | llGetNotecardLine("configuration", line); |
|
136 | } |
136 | } |
|
137 | dataserver(key id, string data) { |
137 | dataserver(key id, string data) { |
|
138 | if(data == EOF) { |
138 | if(data == EOF) { |
|
139 | // invariant, length(tuples) % 2 == 0 |
139 | // invariant, length(tuples) % 2 == 0 |
|
140 | if(llGetListLength(tuples) % 2 != 0) { |
140 | if(llGetListLength(tuples) % 2 != 0) { |
|
141 | llOwnerSay("[Control] Error in configuration notecard."); |
141 | llOwnerSay("[Control] Error in configuration notecard."); |
|
142 | return; |
142 | return; |
|
143 | } |
143 | } |
|
144 | key CORRADE = llList2Key( |
144 | key CORRADE = llList2Key( |
|
145 | tuples, |
145 | tuples, |
|
146 | llListFindList( |
146 | llListFindList( |
|
147 | tuples, |
147 | tuples, |
|
148 | [ |
148 | [ |
|
149 | "corrade" |
149 | "corrade" |
|
150 | ] |
150 | ] |
|
151 | ) |
151 | ) |
|
152 | +1); |
152 | +1); |
|
153 | if(CORRADE == NULL_KEY) { |
153 | if(CORRADE == NULL_KEY) { |
|
154 | llOwnerSay("[Control] Error in configuration notecard: corrade"); |
154 | llOwnerSay("[Control] Error in configuration notecard: corrade"); |
|
155 | return; |
155 | return; |
|
156 | } |
156 | } |
|
157 | string GROUP = llList2String( |
157 | string GROUP = llList2String( |
|
158 | tuples, |
158 | tuples, |
|
159 | llListFindList( |
159 | llListFindList( |
|
160 | tuples, |
160 | tuples, |
|
161 | [ |
161 | [ |
|
162 | "group" |
162 | "group" |
|
163 | ] |
163 | ] |
|
164 | ) |
164 | ) |
|
165 | +1); |
165 | +1); |
|
166 | if(GROUP == "") { |
166 | if(GROUP == "") { |
|
167 | llOwnerSay("[Control] Error in configuration notecard: group"); |
167 | llOwnerSay("[Control] Error in configuration notecard: group"); |
|
168 | return; |
168 | return; |
|
169 | } |
169 | } |
|
170 | string PASSWORD = llList2String( |
170 | string PASSWORD = llList2String( |
|
171 | tuples, |
171 | tuples, |
|
172 | llListFindList( |
172 | llListFindList( |
|
173 | tuples, |
173 | tuples, |
|
174 | [ |
174 | [ |
|
175 | "password" |
175 | "password" |
|
176 | ] |
176 | ] |
|
177 | ) |
177 | ) |
|
178 | +1); |
178 | +1); |
|
179 | if(PASSWORD == "") { |
179 | if(PASSWORD == "") { |
|
180 | llOwnerSay("[Control] Error in configuration notecard: password"); |
180 | llOwnerSay("[Control] Error in configuration notecard: password"); |
|
181 | return; |
181 | return; |
|
182 | } |
182 | } |
|
183 | string VERSION = llList2String( |
183 | string VERSION = llList2String( |
|
184 | tuples, |
184 | tuples, |
|
185 | llListFindList( |
185 | llListFindList( |
|
186 | tuples, |
186 | tuples, |
|
187 | [ |
187 | [ |
|
188 | "version" |
188 | "version" |
|
189 | ] |
189 | ] |
|
190 | ) |
190 | ) |
|
191 | +1); |
191 | +1); |
|
192 | if(VERSION == "") { |
192 | if(VERSION == "") { |
|
193 | llOwnerSay("[Control] Error in configuration notecard: version"); |
193 | llOwnerSay("[Control] Error in configuration notecard: version"); |
|
194 | return; |
194 | return; |
|
195 | } |
195 | } |
|
196 | // DEBUG |
196 | // DEBUG |
|
197 | llOwnerSay("[Control] Read configuration notecard..."); |
197 | llOwnerSay("[Control] Read configuration notecard..."); |
|
198 | configuration = wasKeyValueEncode(tuples); |
198 | configuration = wasKeyValueEncode(tuples); |
|
199 | // GC |
199 | // GC |
|
200 | tuples = []; |
200 | tuples = []; |
|
201 | state request_url_notifications; |
201 | state request_url_notifications; |
|
202 | } |
202 | } |
|
203 | if(data == "") jump continue; |
203 | if(data == "") jump continue; |
|
204 | integer i = llSubStringIndex(data, "#"); |
204 | integer i = llSubStringIndex(data, "#"); |
|
205 | if(i != -1) data = llDeleteSubString(data, i, -1); |
205 | if(i != -1) data = llDeleteSubString(data, i, -1); |
|
206 | list o = llParseString2List(data, ["="], []); |
206 | list o = llParseString2List(data, ["="], []); |
|
207 | // get rid of starting and ending quotes |
207 | // get rid of starting and ending quotes |
|
208 | string k = llDumpList2String( |
208 | string k = llDumpList2String( |
|
209 | llParseString2List( |
209 | llParseString2List( |
|
210 | llStringTrim( |
210 | llStringTrim( |
|
211 | llList2String( |
211 | llList2String( |
|
212 | o, |
212 | o, |
|
213 | 0 |
213 | 0 |
|
214 | ), |
214 | ), |
|
215 | STRING_TRIM), |
215 | STRING_TRIM), |
|
216 | ["\""], [] |
216 | ["\""], [] |
|
217 | ), "\""); |
217 | ), "\""); |
|
218 | string v = llDumpList2String( |
218 | string v = llDumpList2String( |
|
219 | llParseString2List( |
219 | llParseString2List( |
|
220 | llStringTrim( |
220 | llStringTrim( |
|
221 | llList2String( |
221 | llList2String( |
|
222 | o, |
222 | o, |
|
223 | 1 |
223 | 1 |
|
224 | ), |
224 | ), |
|
225 | STRING_TRIM), |
225 | STRING_TRIM), |
|
226 | ["\""], [] |
226 | ["\""], [] |
|
227 | ), "\""); |
227 | ), "\""); |
|
228 | if(k == "" || v == "") jump continue; |
228 | if(k == "" || v == "") jump continue; |
|
229 | tuples += k; |
229 | tuples += k; |
|
230 | tuples += v; |
230 | tuples += v; |
|
231 | @continue; |
231 | @continue; |
|
232 | llGetNotecardLine("configuration", ++line); |
232 | llGetNotecardLine("configuration", ++line); |
|
233 | } |
233 | } |
|
234 | attach(key id) { |
234 | attach(key id) { |
|
235 | llResetScript(); |
235 | llResetScript(); |
|
236 | } |
236 | } |
|
237 | on_rez(integer num) { |
237 | on_rez(integer num) { |
|
238 | llResetScript(); |
238 | llResetScript(); |
|
239 | } |
239 | } |
|
240 | changed(integer change) { |
240 | changed(integer change) { |
|
241 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
241 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
|
242 | llResetScript(); |
242 | llResetScript(); |
|
243 | } |
243 | } |
|
244 | } |
244 | } |
|
245 | } |
245 | } |
|
246 | |
246 | |
|
247 | state request_url_notifications { |
247 | state request_url_notifications { |
|
248 | state_entry() { |
248 | state_entry() { |
|
249 | // DEBUG |
249 | // DEBUG |
|
250 | llOwnerSay("[Control] Requesting URL..."); |
250 | llOwnerSay("[Control] Requesting URL..."); |
|
251 | llRequestURL(); |
251 | llRequestURL(); |
|
252 | } |
252 | } |
|
253 | http_request(key id, string method, string body) { |
253 | http_request(key id, string method, string body) { |
|
254 | if(method != URL_REQUEST_GRANTED) return; |
254 | if(method != URL_REQUEST_GRANTED) return; |
|
255 | URL = body; |
255 | URL = body; |
|
256 | // DEBUG |
256 | // DEBUG |
|
257 | llOwnerSay("[Control] Got URL..."); |
257 | llOwnerSay("[Control] Got URL..."); |
|
258 | state unbind_notifications; |
258 | state unbind_notifications; |
|
259 | } |
259 | } |
|
260 | on_rez(integer num) { |
260 | on_rez(integer num) { |
|
261 | llResetScript(); |
261 | llResetScript(); |
|
262 | } |
262 | } |
|
263 | changed(integer change) { |
263 | changed(integer change) { |
|
264 | if((change & CHANGED_INVENTORY) || |
264 | if((change & CHANGED_INVENTORY) || |
|
265 | (change & CHANGED_REGION_START) || |
265 | (change & CHANGED_REGION_START) || |
|
266 | (change & CHANGED_OWNER)) { |
266 | (change & CHANGED_OWNER)) { |
|
267 | llResetScript(); |
267 | llResetScript(); |
|
268 | } |
268 | } |
|
269 | } |
269 | } |
|
270 | } |
270 | } |
|
271 | |
271 | |
|
272 | state unbind_notifications { |
272 | state unbind_notifications { |
|
273 | state_entry() { |
273 | state_entry() { |
|
274 | // DEBUG |
274 | // DEBUG |
|
275 | llOwnerSay("[Control] Releasing notifications..."); |
275 | llOwnerSay("[Control] Releasing notifications..."); |
|
276 | llInstantMessage( |
276 | llInstantMessage( |
|
277 | (key)wasKeyValueGet( |
277 | (key)wasKeyValueGet( |
|
278 | "corrade", |
278 | "corrade", |
|
279 | configuration |
279 | configuration |
|
280 | ), |
280 | ), |
|
281 | wasKeyValueEncode( |
281 | wasKeyValueEncode( |
|
282 | [ |
282 | [ |
|
283 | "command", "notify", |
283 | "command", "notify", |
|
284 | "group", wasURLEscape( |
284 | "group", wasURLEscape( |
|
285 | wasKeyValueGet( |
285 | wasKeyValueGet( |
|
286 | "group", |
286 | "group", |
|
287 | configuration |
287 | configuration |
|
288 | ) |
288 | ) |
|
289 | ), |
289 | ), |
|
290 | "password", wasURLEscape( |
290 | "password", wasURLEscape( |
|
291 | wasKeyValueGet( |
291 | wasKeyValueGet( |
|
292 | "password", |
292 | "password", |
|
293 | configuration |
293 | configuration |
|
294 | ) |
294 | ) |
|
295 | ), |
295 | ), |
|
296 | "action", "remove", |
296 | "action", "remove", |
|
297 | "tag", wasURLEscape( |
297 | "tag", wasURLEscape( |
|
298 | wasKeyValueGet( |
298 | wasKeyValueGet( |
|
299 | "notification tag", |
299 | "notification tag", |
|
300 | configuration |
300 | configuration |
|
301 | ) |
301 | ) |
|
302 | ), |
302 | ), |
|
303 | "callback", wasURLEscape(URL) |
303 | "callback", wasURLEscape(URL) |
|
304 | ] |
304 | ] |
|
305 | ) |
305 | ) |
|
306 | ); |
306 | ); |
|
307 | llSetTimerEvent(60); |
307 | llSetTimerEvent(60); |
|
308 | } |
308 | } |
|
309 | http_request(key id, string method, string body) { |
309 | http_request(key id, string method, string body) { |
|
310 | llHTTPResponse(id, 200, "OK"); |
310 | llHTTPResponse(id, 200, "OK"); |
|
311 | if(wasKeyValueGet("command", body) != "notify" || |
311 | if(wasKeyValueGet("command", body) != "notify" || |
|
312 | wasKeyValueGet("success", body) != "True") { |
312 | wasKeyValueGet("success", body) != "True") { |
|
313 | // DEBUG |
313 | // DEBUG |
|
314 | llOwnerSay("[Control] Unable to release tag: " + |
314 | llOwnerSay("[Control] Unable to release tag: " + |
|
315 | wasURLUnescape( |
315 | wasURLUnescape( |
|
316 | wasKeyValueGet("error", body) |
316 | wasKeyValueGet("error", body) |
|
317 | ) |
317 | ) |
|
318 | ); |
318 | ); |
|
319 | llResetScript(); |
319 | llResetScript(); |
|
320 | } |
320 | } |
|
321 | state bind_notifications; |
321 | state bind_notifications; |
|
322 | } |
322 | } |
|
323 | timer() { |
323 | timer() { |
|
324 | llOwnerSay("[Control] Timeout releasing notifications"); |
324 | llOwnerSay("[Control] Timeout releasing notifications"); |
|
325 | llResetScript(); |
325 | llResetScript(); |
|
326 | } |
326 | } |
|
327 | on_rez(integer num) { |
327 | on_rez(integer num) { |
|
328 | llResetScript(); |
328 | llResetScript(); |
|
329 | } |
329 | } |
|
330 | changed(integer change) { |
330 | changed(integer change) { |
|
331 | if((change & CHANGED_INVENTORY) || |
331 | if((change & CHANGED_INVENTORY) || |
|
332 | (change & CHANGED_REGION_START) || |
332 | (change & CHANGED_REGION_START) || |
|
333 | (change & CHANGED_OWNER)) { |
333 | (change & CHANGED_OWNER)) { |
|
334 | llResetScript(); |
334 | llResetScript(); |
|
335 | } |
335 | } |
|
336 | } |
336 | } |
|
337 | state_exit() { |
337 | state_exit() { |
|
338 | llSetTimerEvent(0); |
338 | llSetTimerEvent(0); |
|
339 | } |
339 | } |
|
340 | } |
340 | } |
|
341 | |
341 | |
|
342 | state bind_notifications { |
342 | state bind_notifications { |
|
343 | state_entry() { |
343 | state_entry() { |
|
344 | // DEBUG |
344 | // DEBUG |
|
345 | llOwnerSay("[Control] Binding to notifications..."); |
345 | llOwnerSay("[Control] Binding to notifications..."); |
|
346 | llInstantMessage( |
346 | llInstantMessage( |
|
347 | wasKeyValueGet( |
347 | wasKeyValueGet( |
|
348 | "corrade", |
348 | "corrade", |
|
349 | configuration |
349 | configuration |
|
350 | ), |
350 | ), |
|
351 | wasKeyValueEncode( |
351 | wasKeyValueEncode( |
|
352 | [ |
352 | [ |
|
353 | "command", "notify", |
353 | "command", "notify", |
|
354 | "group", wasURLEscape( |
354 | "group", wasURLEscape( |
|
355 | wasKeyValueGet( |
355 | wasKeyValueGet( |
|
356 | "group", |
356 | "group", |
|
357 | configuration |
357 | configuration |
|
358 | ) |
358 | ) |
|
359 | ), |
359 | ), |
|
360 | "password", wasURLEscape( |
360 | "password", wasURLEscape( |
|
361 | wasKeyValueGet( |
361 | wasKeyValueGet( |
|
362 | "password", |
362 | "password", |
|
363 | configuration |
363 | configuration |
|
364 | ) |
364 | ) |
|
365 | ), |
365 | ), |
|
366 | "action", "add", |
366 | "action", "add", |
|
367 | "type", wasURLEscape( |
367 | "type", wasURLEscape( |
|
368 | wasListToCSV( |
368 | wasListToCSV( |
|
369 | notifications |
369 | notifications |
|
370 | ) |
370 | ) |
|
371 | ), |
371 | ), |
|
372 | "URL", wasURLEscape(URL), |
372 | "URL", wasURLEscape(URL), |
|
373 | "tag", wasURLEscape( |
373 | "tag", wasURLEscape( |
|
374 | wasKeyValueGet( |
374 | wasKeyValueGet( |
|
375 | "notification tag", |
375 | "notification tag", |
|
376 | configuration |
376 | configuration |
|
377 | ) |
377 | ) |
|
378 | ), |
378 | ), |
|
379 | "callback", wasURLEscape(URL) |
379 | "callback", wasURLEscape(URL) |
|
380 | ] |
380 | ] |
|
381 | ) |
381 | ) |
|
382 | ); |
382 | ); |
|
383 | llSetTimerEvent(60); |
383 | llSetTimerEvent(60); |
|
384 | } |
384 | } |
|
385 | http_request(key id, string method, string body) { |
385 | http_request(key id, string method, string body) { |
|
386 | llHTTPResponse(id, 200, "OK"); |
386 | llHTTPResponse(id, 200, "OK"); |
|
387 | if(wasKeyValueGet("command", body) != "notify" || |
387 | if(wasKeyValueGet("command", body) != "notify" || |
|
388 | wasKeyValueGet("success", body) != "True") { |
388 | wasKeyValueGet("success", body) != "True") { |
|
389 | // DEBUG |
389 | // DEBUG |
|
390 | llOwnerSay("[Control] Unable to bind notifications: " + |
390 | llOwnerSay("[Control] Unable to bind notifications: " + |
|
391 | wasURLUnescape( |
391 | wasURLUnescape( |
|
392 | wasKeyValueGet("error", body) |
392 | wasKeyValueGet("error", body) |
|
393 | ) |
393 | ) |
|
394 | ); |
394 | ); |
|
395 | llResetScript(); |
395 | llResetScript(); |
|
396 | } |
396 | } |
|
397 | state serve_configuration; |
397 | state serve_configuration; |
|
398 | } |
398 | } |
|
399 | timer() { |
399 | timer() { |
|
400 | llOwnerSay("[Control] Timeout binding notifications"); |
400 | llOwnerSay("[Control] Timeout binding notifications"); |
|
401 | llResetScript(); |
401 | llResetScript(); |
|
402 | } |
402 | } |
|
403 | on_rez(integer num) { |
403 | on_rez(integer num) { |
|
404 | llResetScript(); |
404 | llResetScript(); |
|
405 | } |
405 | } |
|
406 | changed(integer change) { |
406 | changed(integer change) { |
|
407 | if((change & CHANGED_INVENTORY) || |
407 | if((change & CHANGED_INVENTORY) || |
|
408 | (change & CHANGED_REGION_START) || |
408 | (change & CHANGED_REGION_START) || |
|
409 | (change & CHANGED_OWNER)) { |
409 | (change & CHANGED_OWNER)) { |
|
410 | llResetScript(); |
410 | llResetScript(); |
|
411 | } |
411 | } |
|
412 | } |
412 | } |
|
413 | state_exit() { |
413 | state_exit() { |
|
414 | llSetTimerEvent(0); |
414 | llSetTimerEvent(0); |
|
415 | } |
415 | } |
|
416 | } |
416 | } |
|
417 | |
417 | |
|
418 | state serve_configuration { |
418 | state serve_configuration { |
|
419 | state_entry() { |
419 | state_entry() { |
|
420 | // DEBUG |
420 | // DEBUG |
|
421 | llOwnerSay("[Control] Checking version..."); |
421 | llOwnerSay("[Control] Checking version..."); |
|
422 | llInstantMessage( |
422 | llInstantMessage( |
|
423 | wasKeyValueGet( |
423 | wasKeyValueGet( |
|
424 | "corrade", |
424 | "corrade", |
|
425 | configuration |
425 | configuration |
|
426 | ), |
426 | ), |
|
427 | wasKeyValueEncode( |
427 | wasKeyValueEncode( |
|
428 | [ |
428 | [ |
|
429 | "command", "version", |
429 | "command", "version", |
|
430 | "group", wasURLEscape( |
430 | "group", wasURLEscape( |
|
431 | wasKeyValueGet( |
431 | wasKeyValueGet( |
|
432 | "group", |
432 | "group", |
|
433 | configuration |
433 | configuration |
|
434 | ) |
434 | ) |
|
435 | ), |
435 | ), |
|
436 | "password", wasURLEscape( |
436 | "password", wasURLEscape( |
|
437 | wasKeyValueGet( |
437 | wasKeyValueGet( |
|
438 | "password", |
438 | "password", |
|
439 | configuration |
439 | configuration |
|
440 | ) |
440 | ) |
|
441 | ), |
441 | ), |
|
442 | "callback", wasURLEscape(URL) |
442 | "callback", wasURLEscape(URL) |
|
443 | ] |
443 | ] |
|
444 | ) |
444 | ) |
|
445 | ); |
445 | ); |
|
446 | llSetTimerEvent(60); |
446 | llSetTimerEvent(60); |
|
447 | } |
447 | } |
|
448 | http_request(key id, string method, string body) { |
448 | http_request(key id, string method, string body) { |
|
449 | llHTTPResponse(id, 200, "OK"); |
449 | llHTTPResponse(id, 200, "OK"); |
|
450 | llSetTimerEvent(0); |
450 | llSetTimerEvent(0); |
|
451 | if(wasKeyValueGet("command", body) != "version") { |
451 | if(wasKeyValueGet("command", body) != "version") { |
|
452 | llMessageLinked(LINK_THIS, 0, body, "notification"); |
452 | llMessageLinked(LINK_THIS, 0, body, "notification"); |
|
453 | return; |
453 | return; |
|
454 | } |
454 | } |
|
455 | |
455 | |
|
456 | if(wasKeyValueGet("success", body) != "True") { |
456 | if(wasKeyValueGet("success", body) != "True") { |
|
457 | llOwnerSay("[Control] Version check failed..."); |
457 | llOwnerSay("[Control] Version check failed..."); |
|
458 | return; |
458 | return; |
|
459 | } |
459 | } |
|
460 | |
460 | |
|
461 | list v = llParseString2List( |
461 | list v = llParseString2List( |
|
462 | wasKeyValueGet( |
462 | wasKeyValueGet( |
|
463 | "data", |
463 | "data", |
|
464 | body |
464 | body |
|
465 | ), |
465 | ), |
|
466 | ["."], |
466 | ["."], |
|
467 | [] |
467 | [] |
|
468 | ); |
468 | ); |
|
469 | integer receivedVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); |
469 | integer receivedVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); |
|
470 | v = llParseString2List( |
470 | v = llParseString2List( |
|
471 | wasKeyValueGet( |
471 | wasKeyValueGet( |
|
472 | "version", |
472 | "version", |
|
473 | configuration |
473 | configuration |
|
474 | ), |
474 | ), |
|
475 | ["."], |
475 | ["."], |
|
476 | [] |
476 | [] |
|
477 | ); |
477 | ); |
|
478 | integer notecardVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); |
478 | integer notecardVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); |
|
479 | if(receivedVersion < notecardVersion) { |
479 | if(receivedVersion < notecardVersion) { |
|
480 | llOwnerSay("[Control] Version is incompatible! You need a Corrade of at least version: " + |
480 | llOwnerSay("[Control] Version is incompatible! You need a Corrade of at least version: " + |
|
481 | wasKeyValueGet( |
481 | wasKeyValueGet( |
|
482 | "version", |
482 | "version", |
|
483 | configuration |
483 | configuration |
|
484 | ) + |
484 | ) + |
|
485 | " for this template." |
485 | " for this template." |
|
486 | ); |
486 | ); |
|
487 | compatible = FALSE; |
487 | compatible = FALSE; |
|
488 | //llReleaseURL(URL); |
488 | //llReleaseURL(URL); |
|
489 | return; |
489 | return; |
|
490 | } |
490 | } |
|
491 | // DEBUG |
491 | // DEBUG |
|
492 | llOwnerSay("[Control] Version is compatible!"); |
492 | llOwnerSay("[Control] Version is compatible!"); |
|
493 | compatible = TRUE; |
493 | compatible = TRUE; |
|
494 | //llReleaseURL(URL); |
494 | //llReleaseURL(URL); |
|
495 | return; |
495 | return; |
|
496 | } |
496 | } |
|
497 | link_message(integer sender, integer num, string message, key id) { |
497 | link_message(integer sender, integer num, string message, key id) { |
|
498 | if(message != "configuration") return; |
498 | if(message != "configuration") return; |
|
499 | llMessageLinked(LINK_THIS, 0, configuration, "configuration"); |
499 | llMessageLinked(LINK_THIS, 0, configuration, "configuration"); |
|
500 | } |
500 | } |
|
501 | timer() { |
501 | timer() { |
|
502 | llOwnerSay("[Control] Timeout checking version..."); |
502 | llOwnerSay("[Control] Timeout checking version..."); |
|
503 | llResetScript(); |
503 | llResetScript(); |
|
504 | } |
504 | } |
|
505 | on_rez(integer num) { |
505 | on_rez(integer num) { |
|
506 | llResetScript(); |
506 | llResetScript(); |
|
507 | } |
507 | } |
|
508 | changed(integer change) { |
508 | changed(integer change) { |
|
509 | if((change & CHANGED_INVENTORY) || |
509 | if((change & CHANGED_INVENTORY) || |
|
510 | (change & CHANGED_REGION_START) || |
510 | (change & CHANGED_REGION_START) || |
|
511 | (change & CHANGED_OWNER)) { |
511 | (change & CHANGED_OWNER)) { |
|
512 | llResetScript(); |
512 | llResetScript(); |
|
513 | } |
513 | } |
|
514 | } |
514 | } |
|
515 | state_exit() { |
515 | state_exit() { |
|
516 | llSetTimerEvent(0); |
516 | llSetTimerEvent(0); |
|
517 | } |
517 | } |
|
518 | } |
518 | } |
|
519 | |
519 | |