corrade-lsl-templates – Diff between revs 41 and 42
?pathlinks?
Rev 41 | Rev 42 | |||
---|---|---|---|---|
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: CC BY 2.0 // |
|
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); |
|
Line 115... | Line 115... | |||
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 != []); |
|
Line 145... | Line 145... | |||
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 | ) |
|
161 | ); |
161 | ); |
|
162 | } |
162 | } |
|
Line 197... | Line 197... | |||
197 | } |
197 | } |
|
198 | on_rez(integer num) { |
198 | on_rez(integer num) { |
|
199 | llResetScript(); |
199 | llResetScript(); |
|
200 | } |
200 | } |
|
201 | changed(integer change) { |
201 | changed(integer change) { |
|
202 | if((change & CHANGED_INVENTORY) || |
202 | if((change & CHANGED_INVENTORY) || |
|
203 | (change & CHANGED_REGION_START) || |
203 | (change & CHANGED_REGION_START) || |
|
204 | (change & CHANGED_OWNER)) { |
204 | (change & CHANGED_OWNER)) { |
|
205 | llResetScript(); |
205 | llResetScript(); |
|
206 | } |
206 | } |
|
207 | } |
207 | } |
|
208 | state_exit() { |
208 | state_exit() { |
|
Line 217... | Line 217... | |||
217 | } |
217 | } |
|
218 | link_message(integer sender, integer num, string message, key id) { |
218 | link_message(integer sender, integer num, string message, key id) { |
|
219 | // We only care about notifications now. |
219 | // We only care about notifications now. |
|
220 | if(id != "notification") |
220 | if(id != "notification") |
|
221 | return; |
221 | return; |
|
222 | |
222 | |
|
223 | // This script only processes group notifications. |
223 | // This script only processes group notifications. |
|
224 | if(wasKeyValueGet("type", message) != "group" || |
224 | if(wasKeyValueGet("type", message) != "group" || |
|
225 | (wasKeyValueGet("type", message) == "group" && |
225 | (wasKeyValueGet("type", message) == "group" && |
|
226 | wasURLUnescape(wasKeyValueGet("group", message)) != |
226 | wasURLUnescape(wasKeyValueGet("group", message)) != |
|
227 | wasKeyValueGet("group", configuration))) |
227 | wasKeyValueGet("group", configuration))) |
|
228 | return; |
228 | return; |
|
229 | |
229 | |
|
230 | // Get the sent message. |
230 | // Get the sent message. |
|
231 | data = wasURLUnescape( |
231 | data = wasURLUnescape( |
|
232 | wasKeyValueGet( |
232 | wasKeyValueGet( |
|
233 | "message", |
233 | "message", |
|
234 | message |
234 | message |
|
235 | ) |
235 | ) |
|
236 | ); |
236 | ); |
|
237 | |
237 | |
|
238 | // Check if this is an eggdrop command. |
238 | // Check if this is an eggdrop command. |
|
239 | if(llGetSubString(data, 0, 0) != |
239 | if(llGetSubString(data, 0, 0) != |
|
240 | wasKeyValueGet("command", configuration)) |
240 | wasKeyValueGet("command", configuration)) |
|
241 | return; |
241 | return; |
|
242 | |
242 | |
|
243 | // Check if the command matches the current module. |
243 | // Check if the command matches the current module. |
|
244 | list command = llParseString2List(data, [" "], []); |
244 | list command = llParseString2List(data, [" "], []); |
|
245 | if(llList2String(command, 0) != |
245 | if(llList2String(command, 0) != |
|
246 | wasKeyValueGet("command", configuration) + "heartbeat") |
246 | wasKeyValueGet("command", configuration) + "heartbeat") |
|
247 | return; |
247 | return; |
|
248 | |
248 | |
|
249 | // Remove command. |
249 | // Remove command. |
|
250 | command = llDeleteSubList(command, 0, 0); |
250 | command = llDeleteSubList(command, 0, 0); |
|
Line 251... | Line 251... | |||
251 | |
251 | |
|
252 | // Get an URL. |
- | ||
253 | state url; |
- | ||
254 | } |
- | ||
255 | on_rez(integer num) { |
- | ||
256 | llResetScript(); |
- | ||
257 | } |
- | ||
258 | changed(integer change) { |
- | ||
259 | if((change & CHANGED_INVENTORY) || |
- | ||
260 | (change & CHANGED_REGION_START) || |
- | ||
261 | (change & CHANGED_OWNER)) { |
- | ||
262 | llResetScript(); |
- | ||
263 | } |
- | ||
264 | } |
- | ||
265 | } |
- | ||
266 | |
- | ||
267 | state url { |
- | ||
268 | state_entry() { |
- | ||
269 | // DEBUG |
- | ||
270 | llOwnerSay("[Heartbeat] Requesting URL..."); |
- | ||
271 | llRequestURL(); |
- | ||
272 | } |
- | ||
273 | http_request(key id, string method, string body) { |
- | ||
274 | if(method != URL_REQUEST_GRANTED) return; |
- | ||
275 | URL = body; |
- | ||
276 | // DEBUG |
- | ||
277 | llOwnerSay("[Heartbeat] Got URL..."); |
252 | // Get heartbeat. |
|
278 | state version; |
253 | state heartbeat; |
|
279 | } |
254 | } |
|
280 | on_rez(integer num) { |
255 | on_rez(integer num) { |
|
281 | llResetScript(); |
256 | llResetScript(); |
|
282 | } |
257 | } |
|
283 | changed(integer change) { |
258 | changed(integer change) { |
|
284 | if((change & CHANGED_INVENTORY) || |
259 | if((change & CHANGED_INVENTORY) || |
|
285 | (change & CHANGED_REGION_START) || |
260 | (change & CHANGED_REGION_START) || |
|
286 | (change & CHANGED_OWNER)) { |
261 | (change & CHANGED_OWNER)) { |
|
287 | llResetScript(); |
262 | llResetScript(); |
|
288 | } |
263 | } |
|
289 | } |
264 | } |
|
Line 290... | Line 265... | |||
290 | } |
265 | } |
|
291 | |
266 | |
|
292 | state version { |
267 | state heartbeat { |
|
293 | state_entry() { |
268 | state_entry() { |
|
294 | // DEBUG |
269 | // DEBUG |
|
295 | llOwnerSay("[Heartbeat] Getting heartbeat data..."); |
270 | llOwnerSay("[Heartbeat] Getting heartbeat data..."); |
|
296 | llInstantMessage( |
271 | llInstantMessage( |
|
297 | wasKeyValueGet( |
272 | wasKeyValueGet( |
|
298 | "corrade", |
273 | "corrade", |
|
299 | configuration |
274 | configuration |
|
300 | ), |
275 | ), |
|
301 | wasKeyValueEncode( |
276 | wasKeyValueEncode( |
|
302 | [ |
277 | [ |
|
303 | "command", "getheartbeatdata", |
278 | "command", "getheartbeatdata", |
|
304 | "group", wasURLEscape( |
279 | "group", wasURLEscape( |
|
305 | wasKeyValueGet( |
280 | wasKeyValueGet( |
|
306 | "group", |
281 | "group", |
|
307 | configuration |
282 | configuration |
|
308 | ) |
283 | ) |
|
309 | ), |
284 | ), |
|
310 | "password", wasURLEscape( |
285 | "password", wasURLEscape( |
|
311 | wasKeyValueGet( |
286 | wasKeyValueGet( |
|
312 | "password", |
287 | "password", |
|
313 | configuration |
288 | configuration |
|
314 | ) |
289 | ) |
|
315 | ), |
290 | ), |
|
316 | "data", wasListToCSV( |
291 | "data", wasListToCSV( |
|
317 | [ |
292 | [ |
|
- | 293 | "AverageCPUUsage", |
||
318 | "AverageCPUUsage", |
294 | "AverageRAMUsage", |
|
319 | "AverageRAMUsage", |
295 | "AverageNETUsage", |
|
320 | "Uptime" |
296 | "Uptime" |
|
321 | ] |
297 | ] |
|
- | 298 | ), |
||
- | 299 | "callback", wasURLEscape( |
||
- | 300 | wasKeyValueGet( |
||
- | 301 | "URL", |
||
- | 302 | configuration |
||
322 | ), |
303 | ) |
|
323 | "callback", wasURLEscape(URL) |
304 | ) |
|
324 | ] |
305 | ] |
|
325 | ) |
306 | ) |
|
326 | ); |
307 | ); |
|
327 | llSetTimerEvent(60); |
308 | llSetTimerEvent(60); |
|
328 | } |
309 | } |
|
329 | http_request(key id, string method, string body) { |
- | ||
330 | llHTTPResponse(id, 200, "OK"); |
310 | link_message(integer sender, integer num, string body, key id) { |
|
- | 311 | // Only process callbacks for the database command. |
||
- | 312 | if(id != "callback" || wasKeyValueGet("command", body) != "getheartbeatdata") |
||
331 | llReleaseURL(URL); |
313 | return; |
|
332 | if(wasKeyValueGet("command", body) != "getheartbeatdata" || |
314 | |
|
333 | wasKeyValueGet("success", body) != "True") { |
315 | if(wasKeyValueGet("success", body) != "True") { |
|
334 | // DEBUG |
316 | // DEBUG |
|
335 | llOwnerSay("[Heartbeat] Unable to get heartbeat data: " + |
317 | llOwnerSay("[Heartbeat] Unable to get heartbeat data: " + |
|
336 | wasURLUnescape( |
318 | wasURLUnescape( |
|
337 | wasKeyValueGet("error", body) |
319 | wasKeyValueGet("error", body) |
|
338 | ) |
320 | ) |
|
339 | ); |
321 | ); |
|
340 | state listen_group; |
322 | state listen_group; |
|
341 | } |
323 | } |
|
342 | |
324 | |
|
343 | list stats = wasCSVToList( |
325 | list stats = wasCSVToList( |
|
344 | wasURLUnescape( |
326 | wasURLUnescape( |
|
345 | wasKeyValueGet( |
327 | wasKeyValueGet( |
|
346 | "data", |
328 | "data", |
|
347 | body |
329 | body |
|
348 | ) |
330 | ) |
|
349 | ) |
331 | ) |
|
350 | ); |
332 | ); |
|
351 | |
333 | |
|
352 | string CPU = llList2String( |
334 | string CPU = llList2String( |
|
353 | stats, |
335 | stats, |
|
354 | llListFindList( |
336 | llListFindList( |
|
355 | stats, |
337 | stats, |
|
356 | ["AverageCPUUsage"] |
338 | ["AverageCPUUsage"] |
|
357 | ) + 1 |
339 | ) + 1 |
|
358 | ); |
340 | ); |
|
359 | |
341 | |
|
360 | // AverageRAMUsage is returned in bytes, |
342 | // AverageRAMUsage is returned in bytes, |
|
361 | // so convert the value to MiB and round. |
343 | // so convert the value to MiB and round. |
|
362 | string RAM = (string)llRound( |
344 | string RAM = (string)llRound( |
|
363 | llList2Float( |
345 | llList2Float( |
|
364 | stats, |
346 | stats, |
|
365 | llListFindList( |
347 | llListFindList( |
|
366 | stats, |
348 | stats, |
|
367 | ["AverageRAMUsage"] |
349 | ["AverageRAMUsage"] |
|
368 | ) + 1 |
350 | ) + 1 |
|
369 | ) / 1024 / 1024 |
351 | ) / 1024 / 1024 |
|
- | 352 | ); |
||
- | 353 | |
||
- | 354 | // AverageNETUsage is returned in bytes, |
||
- | 355 | // so convert the value to MiB and round. |
||
- | 356 | string NET = (string)llRound( |
||
- | 357 | llList2Float( |
||
- | 358 | stats, |
||
- | 359 | llListFindList( |
||
- | 360 | stats, |
||
- | 361 | ["AverageNETUsage"] |
||
- | 362 | ) + 1 |
||
- | 363 | ) / 1024 / 1024 |
||
370 | ); |
364 | ); |
|
371 | |
365 | |
|
372 | string uptime = llList2String( |
366 | string uptime = llList2String( |
|
373 | stats, |
367 | stats, |
|
374 | llListFindList( |
368 | llListFindList( |
|
375 | stats, |
369 | stats, |
|
376 | ["Uptime"] |
370 | ["Uptime"] |
|
377 | ) + 1 |
371 | ) + 1 |
|
378 | ); |
372 | ); |
|
379 | |
373 | |
|
380 | data = "RAM: " + RAM + "MiB" + " CPU: " + CPU + "%" + " Uptime: " + uptime; |
374 | data = "RAM: " + RAM + "MiB" + " CPU: " + CPU + "%" + " NET: " + NET + "MiB" + " Uptime: " + uptime; |
|
381 | |
375 | |
|
382 | state tell; |
376 | state tell; |
|
383 | } |
- | ||
384 | timer() { |
377 | } |
|
385 | llReleaseURL(URL); |
378 | timer() { |
|
386 | state listen_group; |
379 | state listen_group; |
|
387 | } |
380 | } |
|
388 | on_rez(integer num) { |
381 | on_rez(integer num) { |
|
389 | llResetScript(); |
382 | llResetScript(); |
|
390 | } |
383 | } |
|
391 | changed(integer change) { |
384 | changed(integer change) { |
|
392 | if((change & CHANGED_INVENTORY) || |
385 | if((change & CHANGED_INVENTORY) || |
|
393 | (change & CHANGED_REGION_START) || |
386 | (change & CHANGED_REGION_START) || |
|
394 | (change & CHANGED_OWNER)) { |
387 | (change & CHANGED_OWNER)) { |
|
395 | llResetScript(); |
388 | llResetScript(); |
|
396 | } |
389 | } |
|
Line 404... | Line 397... | |||
404 | state_entry() { |
397 | state_entry() { |
|
405 | // DEBUG |
398 | // DEBUG |
|
406 | llOwnerSay("[Heartbeat] Sending to group."); |
399 | llOwnerSay("[Heartbeat] Sending to group."); |
|
407 | llInstantMessage( |
400 | llInstantMessage( |
|
408 | wasKeyValueGet( |
401 | wasKeyValueGet( |
|
409 | "corrade", |
402 | "corrade", |
|
410 | configuration |
403 | configuration |
|
411 | ), |
404 | ), |
|
412 | wasKeyValueEncode( |
405 | wasKeyValueEncode( |
|
413 | [ |
406 | [ |
|
414 | "command", "tell", |
407 | "command", "tell", |
|
415 | "group", wasURLEscape( |
408 | "group", wasURLEscape( |
|
416 | wasKeyValueGet( |
409 | wasKeyValueGet( |
|
417 | "group", |
410 | "group", |
|
418 | configuration |
411 | configuration |
|
419 | ) |
412 | ) |
|
420 | ), |
413 | ), |
|
421 | "password", wasURLEscape( |
414 | "password", wasURLEscape( |
|
422 | wasKeyValueGet( |
415 | wasKeyValueGet( |
|
423 | "password", |
416 | "password", |
|
424 | configuration |
417 | configuration |
|
425 | ) |
418 | ) |
|
426 | ), |
419 | ), |
|
427 | "entity", "group", |
420 | "entity", "group", |
|
428 | "message", wasURLEscape(data) |
421 | "message", wasURLEscape(data) |