corrade-lsl-templates – Diff between revs 41 and 42
?pathlinks?
Rev 41 | Rev 42 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
|
3 | /////////////////////////////////////////////////////////////////////////// |
3 | /////////////////////////////////////////////////////////////////////////// |
|
4 | // |
4 | // |
|
5 | // A module that sends the current Corrade version to group chat. |
5 | // A module that sends the current Corrade version to group chat. |
|
6 | // |
6 | // |
|
7 | /////////////////////////////////////////////////////////////////////////// |
7 | /////////////////////////////////////////////////////////////////////////// |
|
Line 15... | Line 15... | |||
15 | list a = llParseStringKeepNulls(data, ["&", "="], []); |
15 | list a = llParseStringKeepNulls(data, ["&", "="], []); |
|
16 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
16 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
|
17 | if(i != -1) return llList2String(a, 2*i+1); |
17 | if(i != -1) return llList2String(a, 2*i+1); |
|
18 | return ""; |
18 | return ""; |
|
19 | } |
19 | } |
|
20 | |
20 | |
|
21 | /////////////////////////////////////////////////////////////////////////// |
21 | /////////////////////////////////////////////////////////////////////////// |
|
22 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
|
23 | /////////////////////////////////////////////////////////////////////////// |
23 | /////////////////////////////////////////////////////////////////////////// |
|
24 | string wasKeyValueEncode(list data) { |
24 | string wasKeyValueEncode(list data) { |
|
25 | list k = llList2ListStrided(data, 0, -1, 2); |
25 | list k = llList2ListStrided(data, 0, -1, 2); |
|
26 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
26 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
|
27 | data = []; |
27 | data = []; |
|
Line 32... | Line 32... | |||
32 | } while(llGetListLength(k) != 0); |
32 | } while(llGetListLength(k) != 0); |
|
33 | return llDumpList2String(data, "&"); |
33 | return llDumpList2String(data, "&"); |
|
34 | } |
34 | } |
|
Line 35... | Line 35... | |||
35 | |
35 | |
|
36 | /////////////////////////////////////////////////////////////////////////// |
36 | /////////////////////////////////////////////////////////////////////////// |
|
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // |
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
|
38 | /////////////////////////////////////////////////////////////////////////// |
38 | /////////////////////////////////////////////////////////////////////////// |
|
39 | // http://was.fm/secondlife/wanderer |
39 | // http://was.fm/secondlife/wanderer |
|
40 | vector wasCirclePoint(float radius) { |
40 | vector wasCirclePoint(float radius) { |
|
41 | float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
41 | float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
|
Line 44... | Line 44... | |||
44 | return <x, y, 0>; |
44 | return <x, y, 0>; |
|
45 | return wasCirclePoint(radius); |
45 | return wasCirclePoint(radius); |
|
46 | } |
46 | } |
|
Line 47... | Line 47... | |||
47 | |
47 | |
|
48 | /////////////////////////////////////////////////////////////////////////// |
48 | /////////////////////////////////////////////////////////////////////////// |
|
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
50 | /////////////////////////////////////////////////////////////////////////// |
50 | /////////////////////////////////////////////////////////////////////////// |
|
51 | // escapes a string in conformance with RFC1738 |
51 | // escapes a string in conformance with RFC1738 |
|
52 | string wasURLEscape(string i) { |
52 | string wasURLEscape(string i) { |
|
53 | string o = ""; |
53 | string o = ""; |
|
Line 68... | Line 68... | |||
68 | } while(i != ""); |
68 | } while(i != ""); |
|
69 | return o; |
69 | return o; |
|
70 | } |
70 | } |
|
Line 71... | Line 71... | |||
71 | |
71 | |
|
72 | /////////////////////////////////////////////////////////////////////////// |
72 | /////////////////////////////////////////////////////////////////////////// |
|
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
74 | /////////////////////////////////////////////////////////////////////////// |
74 | /////////////////////////////////////////////////////////////////////////// |
|
75 | list wasCSVToList(string csv) { |
75 | list wasCSVToList(string csv) { |
|
76 | list l = []; |
76 | list l = []; |
|
77 | list s = []; |
77 | list s = []; |
|
Line 107... | Line 107... | |||
107 | // postcondition: length(s) = 0 |
107 | // postcondition: length(s) = 0 |
|
108 | return l + m; |
108 | return l + m; |
|
109 | } |
109 | } |
|
Line 110... | Line 110... | |||
110 | |
110 | |
|
111 | /////////////////////////////////////////////////////////////////////////// |
111 | /////////////////////////////////////////////////////////////////////////// |
|
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
113 | /////////////////////////////////////////////////////////////////////////// |
113 | /////////////////////////////////////////////////////////////////////////// |
|
114 | string wasListToCSV(list l) { |
114 | string wasListToCSV(list l) { |
|
115 | list v = []; |
115 | list v = []; |
|
116 | do { |
116 | do { |
|
117 | string a = llDumpList2String( |
117 | string a = llDumpList2String( |
|
118 | llParseStringKeepNulls( |
118 | llParseStringKeepNulls( |
|
119 | llList2String( |
119 | llList2String( |
|
120 | l, |
120 | l, |
|
121 | 0 |
121 | 0 |
|
122 | ), |
122 | ), |
|
123 | ["\""], |
123 | ["\""], |
|
124 | [] |
124 | [] |
|
125 | ), |
125 | ), |
|
126 | "\"\"" |
126 | "\"\"" |
|
127 | ); |
127 | ); |
|
128 | if(llParseStringKeepNulls( |
128 | if(llParseStringKeepNulls( |
|
129 | a, |
129 | a, |
|
130 | [" ", ",", "\n", "\""], [] |
130 | [" ", ",", "\n", "\""], [] |
|
131 | ) != |
131 | ) != |
|
132 | (list) a |
132 | (list) a |
|
133 | ) a = "\"" + a + "\""; |
133 | ) a = "\"" + a + "\""; |
|
134 | v += a; |
134 | v += a; |
|
135 | l = llDeleteSubList(l, 0, 0); |
135 | l = llDeleteSubList(l, 0, 0); |
|
136 | } while(l != []); |
136 | } while(l != []); |
|
137 | return llDumpList2String(v, ","); |
137 | return llDumpList2String(v, ","); |
|
Line 138... | Line 138... | |||
138 | } |
138 | } |
|
139 | |
139 | |
|
140 | /////////////////////////////////////////////////////////////////////////// |
140 | /////////////////////////////////////////////////////////////////////////// |
|
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
|
142 | /////////////////////////////////////////////////////////////////////////// |
142 | /////////////////////////////////////////////////////////////////////////// |
|
143 | // unescapes a string in conformance with RFC1738 |
143 | // unescapes a string in conformance with RFC1738 |
|
144 | string wasURLUnescape(string i) { |
144 | string wasURLUnescape(string i) { |
|
145 | return llUnescapeURL( |
145 | return llUnescapeURL( |
|
146 | llDumpList2String( |
146 | llDumpList2String( |
|
147 | llParseString2List( |
147 | llParseString2List( |
|
148 | llDumpList2String( |
148 | llDumpList2String( |
|
149 | llParseString2List( |
149 | llParseString2List( |
|
150 | i, |
150 | i, |
|
151 | ["+"], |
151 | ["+"], |
|
152 | [] |
152 | [] |
|
153 | ), |
153 | ), |
|
154 | " " |
154 | " " |
|
155 | ), |
155 | ), |
|
156 | ["%0D%0A"], |
156 | ["%0D%0A"], |
|
157 | [] |
157 | [] |
|
158 | ), |
158 | ), |
|
159 | "\n" |
159 | "\n" |
|
160 | ) |
160 | ) |
|
Line 161... | Line 161... | |||
161 | ); |
161 | ); |
|
162 | } |
162 | } |
|
163 | |
163 | |
|
164 | /////////////////////////////////////////////////////////////////////////// |
164 | /////////////////////////////////////////////////////////////////////////// |
|
165 | // Copyright (C) 2017 Wizardry and Steamworks - License: CC BY 2.0 // |
165 | // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 // |
|
166 | /////////////////////////////////////////////////////////////////////////// |
166 | /////////////////////////////////////////////////////////////////////////// |
|
167 | list wasSetIntersect(list a, list b) { |
167 | list wasSetIntersect(list a, list b) { |
|
Line 173... | Line 173... | |||
173 | return i + wasSetIntersect(a, b); |
173 | return i + wasSetIntersect(a, b); |
|
174 | } |
174 | } |
|
Line 175... | Line 175... | |||
175 | |
175 | |
|
176 | // configuration data |
176 | // configuration data |
|
177 | string configuration = ""; |
- | ||
178 | // callback URL |
- | ||
179 | string URL = ""; |
177 | string configuration = ""; |
|
180 | // store message over state. |
178 | // store message over state. |
|
Line 181... | Line 179... | |||
181 | string data = ""; |
179 | string data = ""; |
|
182 | |
180 | |
|
Line 197... | Line 195... | |||
197 | } |
195 | } |
|
198 | on_rez(integer num) { |
196 | on_rez(integer num) { |
|
199 | llResetScript(); |
197 | llResetScript(); |
|
200 | } |
198 | } |
|
201 | changed(integer change) { |
199 | changed(integer change) { |
|
202 | if((change & CHANGED_INVENTORY) || |
200 | if((change & CHANGED_INVENTORY) || |
|
203 | (change & CHANGED_REGION_START) || |
201 | (change & CHANGED_REGION_START) || |
|
204 | (change & CHANGED_OWNER)) { |
202 | (change & CHANGED_OWNER)) { |
|
205 | llResetScript(); |
203 | llResetScript(); |
|
206 | } |
204 | } |
|
207 | } |
205 | } |
|
208 | state_exit() { |
206 | state_exit() { |
|
Line 217... | Line 215... | |||
217 | } |
215 | } |
|
218 | link_message(integer sender, integer num, string message, key id) { |
216 | link_message(integer sender, integer num, string message, key id) { |
|
219 | // We only care about notifications now. |
217 | // We only care about notifications now. |
|
220 | if(id != "notification") |
218 | if(id != "notification") |
|
221 | return; |
219 | return; |
|
222 | |
220 | |
|
223 | // This script only processes group notifications. |
221 | // This script only processes group notifications. |
|
224 | if(wasKeyValueGet("type", message) != "group") |
222 | if(wasKeyValueGet("type", message) != "group" || |
|
- | 223 | (wasKeyValueGet("type", message) == "group" && |
||
- | 224 | wasURLUnescape(wasKeyValueGet("group", message)) != |
||
- | 225 | wasKeyValueGet("group", configuration))) |
||
225 | return; |
226 | return; |
|
226 | |
227 | |
|
227 | // Get the sent message. |
228 | // Get the sent message. |
|
228 | data = wasURLUnescape( |
229 | data = wasURLUnescape( |
|
229 | wasKeyValueGet( |
230 | wasKeyValueGet( |
|
230 | "message", |
231 | "message", |
|
231 | message |
232 | message |
|
232 | ) |
233 | ) |
|
233 | ); |
234 | ); |
|
234 | |
235 | |
|
235 | // Check if this is an eggdrop command. |
236 | // Check if this is an eggdrop command. |
|
236 | if(llGetSubString(data, 0, 0) != |
237 | if(llGetSubString(data, 0, 0) != |
|
237 | wasKeyValueGet("command", configuration)) |
238 | wasKeyValueGet("command", configuration)) |
|
238 | return; |
239 | return; |
|
239 | |
240 | |
|
240 | // Check if the command matches the current module. |
241 | // Check if the command matches the current module. |
|
241 | list command = llParseString2List(data, [" "], []); |
242 | list command = llParseString2List(data, [" "], []); |
|
242 | if(llList2String(command, 0) != |
243 | if(llList2String(command, 0) != |
|
243 | wasKeyValueGet("command", configuration) + "version") |
244 | wasKeyValueGet("command", configuration) + "version") |
|
244 | return; |
245 | return; |
|
245 | |
246 | |
|
246 | // Remove command. |
247 | // Remove command. |
|
247 | command = llDeleteSubList(command, 0, 0); |
248 | command = llDeleteSubList(command, 0, 0); |
|
Line 248... | Line 249... | |||
248 | |
249 | |
|
249 | // Get an URL. |
- | ||
250 | state url; |
- | ||
251 | } |
- | ||
252 | on_rez(integer num) { |
- | ||
253 | llResetScript(); |
- | ||
254 | } |
- | ||
255 | changed(integer change) { |
- | ||
256 | if((change & CHANGED_INVENTORY) || |
- | ||
257 | (change & CHANGED_REGION_START) || |
- | ||
258 | (change & CHANGED_OWNER)) { |
- | ||
259 | llResetScript(); |
- | ||
260 | } |
- | ||
261 | } |
- | ||
262 | } |
- | ||
263 | |
- | ||
264 | state url { |
- | ||
265 | state_entry() { |
- | ||
266 | // DEBUG |
- | ||
267 | llOwnerSay("[Version] Requesting URL..."); |
- | ||
268 | llRequestURL(); |
- | ||
269 | } |
- | ||
270 | http_request(key id, string method, string body) { |
- | ||
271 | if(method != URL_REQUEST_GRANTED) return; |
- | ||
272 | URL = body; |
- | ||
273 | // DEBUG |
- | ||
274 | llOwnerSay("[Version] Got URL..."); |
250 | // Get version. |
|
275 | state version; |
251 | state version; |
|
276 | } |
252 | } |
|
277 | on_rez(integer num) { |
253 | on_rez(integer num) { |
|
278 | llResetScript(); |
254 | llResetScript(); |
|
279 | } |
255 | } |
|
280 | changed(integer change) { |
256 | changed(integer change) { |
|
281 | if((change & CHANGED_INVENTORY) || |
257 | if((change & CHANGED_INVENTORY) || |
|
282 | (change & CHANGED_REGION_START) || |
258 | (change & CHANGED_REGION_START) || |
|
283 | (change & CHANGED_OWNER)) { |
259 | (change & CHANGED_OWNER)) { |
|
284 | llResetScript(); |
260 | llResetScript(); |
|
285 | } |
261 | } |
|
286 | } |
262 | } |
|
Line 290... | Line 266... | |||
290 | state_entry() { |
266 | state_entry() { |
|
291 | // DEBUG |
267 | // DEBUG |
|
292 | llOwnerSay("[Version] Getting version..."); |
268 | llOwnerSay("[Version] Getting version..."); |
|
293 | llInstantMessage( |
269 | llInstantMessage( |
|
294 | wasKeyValueGet( |
270 | wasKeyValueGet( |
|
295 | "corrade", |
271 | "corrade", |
|
296 | configuration |
272 | configuration |
|
297 | ), |
273 | ), |
|
298 | wasKeyValueEncode( |
274 | wasKeyValueEncode( |
|
299 | [ |
275 | [ |
|
300 | "command", "version", |
276 | "command", "version", |
|
301 | "group", wasURLEscape( |
277 | "group", wasURLEscape( |
|
302 | wasKeyValueGet( |
278 | wasKeyValueGet( |
|
303 | "group", |
279 | "group", |
|
304 | configuration |
280 | configuration |
|
305 | ) |
281 | ) |
|
306 | ), |
282 | ), |
|
307 | "password", wasURLEscape( |
283 | "password", wasURLEscape( |
|
308 | wasKeyValueGet( |
284 | wasKeyValueGet( |
|
309 | "password", |
285 | "password", |
|
310 | configuration |
286 | configuration |
|
311 | ) |
287 | ) |
|
312 | ), |
288 | ), |
|
313 | "callback", wasURLEscape(URL) |
289 | "callback", wasURLEscape( |
|
- | 290 | wasKeyValueGet( |
||
- | 291 | "URL", |
||
- | 292 | configuration |
||
- | 293 | ) |
||
- | 294 | ) |
||
314 | ] |
295 | ] |
|
315 | ) |
296 | ) |
|
316 | ); |
297 | ); |
|
317 | llSetTimerEvent(60); |
298 | llSetTimerEvent(60); |
|
318 | } |
299 | } |
|
319 | http_request(key id, string method, string body) { |
300 | link_message(integer sender, integer num, string body, key id) { |
|
320 | llHTTPResponse(id, 200, "OK"); |
301 | // Only process callbacks for the database command. |
|
321 | llReleaseURL(URL); |
- | ||
322 | if(wasKeyValueGet("command", body) != "version" || |
302 | if(id != "callback" || wasKeyValueGet("command", body) != "version") |
|
- | 303 | return; |
||
- | 304 | |
||
323 | wasKeyValueGet("success", body) != "True") { |
305 | if(wasKeyValueGet("success", body) != "True") { |
|
324 | // DEBUG |
306 | // DEBUG |
|
325 | llOwnerSay("[Version] Unable to get version: " + |
307 | llOwnerSay("[Version] Unable to get version: " + |
|
326 | wasURLUnescape( |
308 | wasURLUnescape( |
|
327 | wasKeyValueGet("error", body) |
309 | wasKeyValueGet("error", body) |
|
328 | ) |
310 | ) |
|
329 | ); |
311 | ); |
|
330 | state listen_group; |
312 | state listen_group; |
|
331 | } |
313 | } |
|
332 | |
314 | |
|
333 | data = "I'm a " + wasKeyValueGet("data", body); |
315 | data = "I'm a " + wasKeyValueGet("data", body); |
|
334 | |
316 | |
|
335 | state tell; |
317 | state tell; |
|
336 | } |
318 | } |
|
337 | timer() { |
319 | timer() { |
|
338 | llReleaseURL(URL); |
- | ||
339 | state listen_group; |
320 | state listen_group; |
|
340 | } |
321 | } |
|
341 | on_rez(integer num) { |
322 | on_rez(integer num) { |
|
342 | llResetScript(); |
323 | llResetScript(); |
|
343 | } |
324 | } |
|
344 | changed(integer change) { |
325 | changed(integer change) { |
|
345 | if((change & CHANGED_INVENTORY) || |
326 | if((change & CHANGED_INVENTORY) || |
|
346 | (change & CHANGED_REGION_START) || |
327 | (change & CHANGED_REGION_START) || |
|
347 | (change & CHANGED_OWNER)) { |
328 | (change & CHANGED_OWNER)) { |
|
348 | llResetScript(); |
329 | llResetScript(); |
|
349 | } |
330 | } |
|
350 | } |
331 | } |
|
351 | state_exit() { |
332 | state_exit() { |
|
Line 357... | Line 338... | |||
357 | state_entry() { |
338 | state_entry() { |
|
358 | // DEBUG |
339 | // DEBUG |
|
359 | llOwnerSay("[Version] Sending to group."); |
340 | llOwnerSay("[Version] Sending to group."); |
|
360 | llInstantMessage( |
341 | llInstantMessage( |
|
361 | wasKeyValueGet( |
342 | wasKeyValueGet( |
|
362 | "corrade", |
343 | "corrade", |
|
363 | configuration |
344 | configuration |
|
364 | ), |
345 | ), |
|
365 | wasKeyValueEncode( |
346 | wasKeyValueEncode( |
|
366 | [ |
347 | [ |
|
367 | "command", "tell", |
348 | "command", "tell", |
|
368 | "group", wasURLEscape( |
349 | "group", wasURLEscape( |
|
369 | wasKeyValueGet( |
350 | wasKeyValueGet( |
|
370 | "group", |
351 | "group", |
|
371 | configuration |
352 | configuration |
|
372 | ) |
353 | ) |
|
373 | ), |
354 | ), |
|
374 | "password", wasURLEscape( |
355 | "password", wasURLEscape( |
|
375 | wasKeyValueGet( |
356 | wasKeyValueGet( |
|
376 | "password", |
357 | "password", |
|
377 | configuration |
358 | configuration |
|
378 | ) |
359 | ) |
|
379 | ), |
360 | ), |
|
380 | "entity", "group", |
361 | "entity", "group", |
|
381 | "message", wasURLEscape(data) |
362 | "message", wasURLEscape(data) |