corrade-lsl-templates – Diff between revs 8 and 11

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 8 Rev 11
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", "notice" ]; 125 list notifications = [ "group", "membership" ];
126 // The tag that this script uses for notifications. -  
127 string EGG_TAG = "147d8bf1-4fbc-4c31-b0ea-1d2a72a41041"; -  
128   126  
129 default { 127 default {
130 state_entry() { 128 state_entry() {
131 if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) { 129 if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) {
132 llOwnerSay("[Control] Sorry, could not find a configuration inventory notecard."); 130 llOwnerSay("[Control] Sorry, could not find a configuration inventory notecard.");
133 return; 131 return;
134 } 132 }
135 // DEBUG 133 // DEBUG
136 llOwnerSay("[Control] Reading configuration file..."); 134 llOwnerSay("[Control] Reading configuration file...");
137 llGetNotecardLine("configuration", line); 135 llGetNotecardLine("configuration", line);
138 } 136 }
139 dataserver(key id, string data) { 137 dataserver(key id, string data) {
140 if(data == EOF) { 138 if(data == EOF) {
141 // invariant, length(tuples) % 2 == 0 139 // invariant, length(tuples) % 2 == 0
142 if(llGetListLength(tuples) % 2 != 0) { 140 if(llGetListLength(tuples) % 2 != 0) {
143 llOwnerSay("[Control] Error in configuration notecard."); 141 llOwnerSay("[Control] Error in configuration notecard.");
144 return; 142 return;
145 } 143 }
146 key CORRADE = llList2Key( 144 key CORRADE = llList2Key(
147 tuples, 145 tuples,
148 llListFindList( 146 llListFindList(
149 tuples, 147 tuples,
150 [ 148 [
151 "corrade" 149 "corrade"
152 ] 150 ]
153 ) 151 )
154 +1); 152 +1);
155 if(CORRADE == NULL_KEY) { 153 if(CORRADE == NULL_KEY) {
156 llOwnerSay("[Control] Error in configuration notecard: corrade"); 154 llOwnerSay("[Control] Error in configuration notecard: corrade");
157 return; 155 return;
158 } 156 }
159 string GROUP = llList2String( 157 string GROUP = llList2String(
160 tuples, 158 tuples,
161 llListFindList( 159 llListFindList(
162 tuples, 160 tuples,
163 [ 161 [
164 "group" 162 "group"
165 ] 163 ]
166 ) 164 )
167 +1); 165 +1);
168 if(GROUP == "") { 166 if(GROUP == "") {
169 llOwnerSay("[Control] Error in configuration notecard: group"); 167 llOwnerSay("[Control] Error in configuration notecard: group");
170 return; 168 return;
171 } 169 }
172 string PASSWORD = llList2String( 170 string PASSWORD = llList2String(
173 tuples, 171 tuples,
174 llListFindList( 172 llListFindList(
175 tuples, 173 tuples,
176 [ 174 [
177 "password" 175 "password"
178 ] 176 ]
179 ) 177 )
180 +1); 178 +1);
181 if(PASSWORD == "") { 179 if(PASSWORD == "") {
182 llOwnerSay("[Control] Error in configuration notecard: password"); 180 llOwnerSay("[Control] Error in configuration notecard: password");
183 return; 181 return;
184 } 182 }
185 string VERSION = llList2String( 183 string VERSION = llList2String(
186 tuples, 184 tuples,
187 llListFindList( 185 llListFindList(
188 tuples, 186 tuples,
189 [ 187 [
190 "version" 188 "version"
191 ] 189 ]
192 ) 190 )
193 +1); 191 +1);
194 if(VERSION == "") { 192 if(VERSION == "") {
195 llOwnerSay("[Control] Error in configuration notecard: version"); 193 llOwnerSay("[Control] Error in configuration notecard: version");
196 return; 194 return;
197 } 195 }
198 // DEBUG 196 // DEBUG
199 llOwnerSay("[Control] Read configuration notecard..."); 197 llOwnerSay("[Control] Read configuration notecard...");
200 configuration = wasKeyValueEncode(tuples); 198 configuration = wasKeyValueEncode(tuples);
201 // GC 199 // GC
202 tuples = []; 200 tuples = [];
203 state request_url_notifications; 201 state request_url_notifications;
204 } 202 }
205 if(data == "") jump continue; 203 if(data == "") jump continue;
206 integer i = llSubStringIndex(data, "#"); 204 integer i = llSubStringIndex(data, "#");
207 if(i != -1) data = llDeleteSubString(data, i, -1); 205 if(i != -1) data = llDeleteSubString(data, i, -1);
208 list o = llParseString2List(data, ["="], []); 206 list o = llParseString2List(data, ["="], []);
209 // get rid of starting and ending quotes 207 // get rid of starting and ending quotes
210 string k = llDumpList2String( 208 string k = llDumpList2String(
211 llParseString2List( 209 llParseString2List(
212 llStringTrim( 210 llStringTrim(
213 llList2String( 211 llList2String(
214 o, 212 o,
215 0 213 0
216 ), 214 ),
217 STRING_TRIM), 215 STRING_TRIM),
218 ["\""], [] 216 ["\""], []
219 ), "\""); 217 ), "\"");
220 string v = llDumpList2String( 218 string v = llDumpList2String(
221 llParseString2List( 219 llParseString2List(
222 llStringTrim( 220 llStringTrim(
223 llList2String( 221 llList2String(
224 o, 222 o,
225 1 223 1
226 ), 224 ),
227 STRING_TRIM), 225 STRING_TRIM),
228 ["\""], [] 226 ["\""], []
229 ), "\""); 227 ), "\"");
230 if(k == "" || v == "") jump continue; 228 if(k == "" || v == "") jump continue;
231 tuples += k; 229 tuples += k;
232 tuples += v; 230 tuples += v;
233 @continue; 231 @continue;
234 llGetNotecardLine("configuration", ++line); 232 llGetNotecardLine("configuration", ++line);
235 } 233 }
236 attach(key id) { 234 attach(key id) {
237 llResetScript(); 235 llResetScript();
238 } 236 }
239 on_rez(integer num) { 237 on_rez(integer num) {
240 llResetScript(); 238 llResetScript();
241 } 239 }
242 changed(integer change) { 240 changed(integer change) {
243 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 241 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
244 llResetScript(); 242 llResetScript();
245 } 243 }
246 } 244 }
247 } 245 }
248   246  
249 state request_url_notifications { 247 state request_url_notifications {
250 state_entry() { 248 state_entry() {
251 // DEBUG 249 // DEBUG
252 llOwnerSay("[Control] Requesting URL..."); 250 llOwnerSay("[Control] Requesting URL...");
253 llRequestURL(); 251 llRequestURL();
254 } 252 }
255 http_request(key id, string method, string body) { 253 http_request(key id, string method, string body) {
256 if(method != URL_REQUEST_GRANTED) return; 254 if(method != URL_REQUEST_GRANTED) return;
257 URL = body; 255 URL = body;
258 // DEBUG 256 // DEBUG
259 llOwnerSay("[Control] Got URL..."); 257 llOwnerSay("[Control] Got URL...");
260 state unbind_notifications; 258 state unbind_notifications;
261 } 259 }
262 on_rez(integer num) { 260 on_rez(integer num) {
263 llResetScript(); 261 llResetScript();
264 } 262 }
265 changed(integer change) { 263 changed(integer change) {
266 if((change & CHANGED_INVENTORY) || 264 if((change & CHANGED_INVENTORY) ||
267 (change & CHANGED_REGION_START) || 265 (change & CHANGED_REGION_START) ||
268 (change & CHANGED_OWNER)) { 266 (change & CHANGED_OWNER)) {
269 llResetScript(); 267 llResetScript();
270 } 268 }
271 } 269 }
272 } 270 }
273   271  
274 state unbind_notifications { 272 state unbind_notifications {
275 state_entry() { 273 state_entry() {
276 // DEBUG 274 // DEBUG
277 llOwnerSay("[Control] Releasing notifications..."); 275 llOwnerSay("[Control] Releasing notifications...");
278 llInstantMessage( 276 llInstantMessage(
279 (key)wasKeyValueGet( 277 (key)wasKeyValueGet(
280 "corrade", 278 "corrade",
281 configuration 279 configuration
282 ), 280 ),
283 wasKeyValueEncode( 281 wasKeyValueEncode(
284 [ 282 [
285 "command", "notify", 283 "command", "notify",
286 "group", wasURLEscape( 284 "group", wasURLEscape(
287 wasKeyValueGet( 285 wasKeyValueGet(
288 "group", 286 "group",
289 configuration 287 configuration
290 ) 288 )
291 ), 289 ),
292 "password", wasURLEscape( 290 "password", wasURLEscape(
293 wasKeyValueGet( 291 wasKeyValueGet(
294 "password", 292 "password",
295 configuration 293 configuration
296 ) 294 )
297 ), 295 ),
298 "action", "remove", 296 "action", "remove",
299 "tag", wasURLEscape(EGG_TAG), 297 "tag", wasURLEscape(
-   298 wasKeyValueGet(
-   299 "notification tag",
-   300 configuration
-   301 )
-   302 ),
300 "callback", wasURLEscape(URL) 303 "callback", wasURLEscape(URL)
301 ] 304 ]
302 ) 305 )
303 ); 306 );
304 llSetTimerEvent(60); 307 llSetTimerEvent(60);
305 } 308 }
306 http_request(key id, string method, string body) { 309 http_request(key id, string method, string body) {
307 llHTTPResponse(id, 200, "OK"); 310 llHTTPResponse(id, 200, "OK");
308 if(wasKeyValueGet("command", body) != "notify" || 311 if(wasKeyValueGet("command", body) != "notify" ||
309 wasKeyValueGet("success", body) != "True") { 312 wasKeyValueGet("success", body) != "True") {
310 // DEBUG 313 // DEBUG
311 llOwnerSay("[Control] Unable to release tag: " + 314 llOwnerSay("[Control] Unable to release tag: " +
312 wasURLUnescape( 315 wasURLUnescape(
313 wasKeyValueGet("error", body) 316 wasKeyValueGet("error", body)
314 ) 317 )
315 ); 318 );
316 llResetScript(); 319 llResetScript();
317 } 320 }
318 state bind_notifications; 321 state bind_notifications;
319 } 322 }
320 timer() { 323 timer() {
321 llOwnerSay("[Control] Timeout releasing notifications"); 324 llOwnerSay("[Control] Timeout releasing notifications");
322 llResetScript(); 325 llResetScript();
323 } 326 }
324 on_rez(integer num) { 327 on_rez(integer num) {
325 llResetScript(); 328 llResetScript();
326 } 329 }
327 changed(integer change) { 330 changed(integer change) {
328 if((change & CHANGED_INVENTORY) || 331 if((change & CHANGED_INVENTORY) ||
329 (change & CHANGED_REGION_START) || 332 (change & CHANGED_REGION_START) ||
330 (change & CHANGED_OWNER)) { 333 (change & CHANGED_OWNER)) {
331 llResetScript(); 334 llResetScript();
332 } 335 }
333 } 336 }
334 state_exit() { 337 state_exit() {
335 llSetTimerEvent(0); 338 llSetTimerEvent(0);
336 } 339 }
337 } 340 }
338   341  
339 state bind_notifications { 342 state bind_notifications {
340 state_entry() { 343 state_entry() {
341 // DEBUG 344 // DEBUG
342 llOwnerSay("[Control] Binding to notifications..."); 345 llOwnerSay("[Control] Binding to notifications...");
343 llInstantMessage( 346 llInstantMessage(
344 wasKeyValueGet( 347 wasKeyValueGet(
345 "corrade", 348 "corrade",
346 configuration 349 configuration
347 ), 350 ),
348 wasKeyValueEncode( 351 wasKeyValueEncode(
349 [ 352 [
350 "command", "notify", 353 "command", "notify",
351 "group", wasURLEscape( 354 "group", wasURLEscape(
352 wasKeyValueGet( 355 wasKeyValueGet(
353 "group", 356 "group",
354 configuration 357 configuration
355 ) 358 )
356 ), 359 ),
357 "password", wasURLEscape( 360 "password", wasURLEscape(
358 wasKeyValueGet( 361 wasKeyValueGet(
359 "password", 362 "password",
360 configuration 363 configuration
361 ) 364 )
362 ), 365 ),
363 "action", "add", 366 "action", "add",
364 "type", wasURLEscape( 367 "type", wasURLEscape(
365 wasListToCSV( 368 wasListToCSV(
366 notifications 369 notifications
367 ) 370 )
368 ), 371 ),
369 "URL", wasURLEscape(URL), 372 "URL", wasURLEscape(URL),
370 "tag", wasURLEscape(EGG_TAG), 373 "tag", wasURLEscape(
-   374 wasKeyValueGet(
-   375 "notification tag",
-   376 configuration
-   377 )
-   378 ),
371 "callback", wasURLEscape(URL) 379 "callback", wasURLEscape(URL)
372 ] 380 ]
373 ) 381 )
374 ); 382 );
375 llSetTimerEvent(60); 383 llSetTimerEvent(60);
376 } 384 }
377 http_request(key id, string method, string body) { 385 http_request(key id, string method, string body) {
378 llHTTPResponse(id, 200, "OK"); 386 llHTTPResponse(id, 200, "OK");
379 if(wasKeyValueGet("command", body) != "notify" || 387 if(wasKeyValueGet("command", body) != "notify" ||
380 wasKeyValueGet("success", body) != "True") { 388 wasKeyValueGet("success", body) != "True") {
381 // DEBUG 389 // DEBUG
382 llOwnerSay("[Control] Unable to bind notifications: " + 390 llOwnerSay("[Control] Unable to bind notifications: " +
383 wasURLUnescape( 391 wasURLUnescape(
384 wasKeyValueGet("error", body) 392 wasKeyValueGet("error", body)
385 ) 393 )
386 ); 394 );
387 llResetScript(); 395 llResetScript();
388 } 396 }
389 state serve_configuration; 397 state serve_configuration;
390 } 398 }
391 timer() { 399 timer() {
392 llOwnerSay("[Control] Timeout binding notifications"); 400 llOwnerSay("[Control] Timeout binding notifications");
393 llResetScript(); 401 llResetScript();
394 } 402 }
395 on_rez(integer num) { 403 on_rez(integer num) {
396 llResetScript(); 404 llResetScript();
397 } 405 }
398 changed(integer change) { 406 changed(integer change) {
399 if((change & CHANGED_INVENTORY) || 407 if((change & CHANGED_INVENTORY) ||
400 (change & CHANGED_REGION_START) || 408 (change & CHANGED_REGION_START) ||
401 (change & CHANGED_OWNER)) { 409 (change & CHANGED_OWNER)) {
402 llResetScript(); 410 llResetScript();
403 } 411 }
404 } 412 }
405 state_exit() { 413 state_exit() {
406 llSetTimerEvent(0); 414 llSetTimerEvent(0);
407 } 415 }
408 } 416 }
409   417  
410 state serve_configuration { 418 state serve_configuration {
411 state_entry() { 419 state_entry() {
412 // DEBUG 420 // DEBUG
413 llOwnerSay("[Control] Checking version..."); 421 llOwnerSay("[Control] Checking version...");
414 llInstantMessage( 422 llInstantMessage(
415 wasKeyValueGet( 423 wasKeyValueGet(
416 "corrade", 424 "corrade",
417 configuration 425 configuration
418 ), 426 ),
419 wasKeyValueEncode( 427 wasKeyValueEncode(
420 [ 428 [
421 "command", "version", 429 "command", "version",
422 "group", wasURLEscape( 430 "group", wasURLEscape(
423 wasKeyValueGet( 431 wasKeyValueGet(
424 "group", 432 "group",
425 configuration 433 configuration
426 ) 434 )
427 ), 435 ),
428 "password", wasURLEscape( 436 "password", wasURLEscape(
429 wasKeyValueGet( 437 wasKeyValueGet(
430 "password", 438 "password",
431 configuration 439 configuration
432 ) 440 )
433 ), 441 ),
434 "callback", wasURLEscape(URL) 442 "callback", wasURLEscape(URL)
435 ] 443 ]
436 ) 444 )
437 ); 445 );
438 llSetTimerEvent(60); 446 llSetTimerEvent(60);
439 } 447 }
440 http_request(key id, string method, string body) { 448 http_request(key id, string method, string body) {
441 llHTTPResponse(id, 200, "OK"); 449 llHTTPResponse(id, 200, "OK");
442 llSetTimerEvent(0); 450 llSetTimerEvent(0);
443 if(wasKeyValueGet("command", body) != "version") { 451 if(wasKeyValueGet("command", body) != "version") {
444 llMessageLinked(LINK_THIS, 0, body, "notification"); 452 llMessageLinked(LINK_THIS, 0, body, "notification");
445 return; 453 return;
446 } 454 }
447 455
448 if(wasKeyValueGet("success", body) != "True") { 456 if(wasKeyValueGet("success", body) != "True") {
449 llOwnerSay("[Control] Version check failed..."); 457 llOwnerSay("[Control] Version check failed...");
450 return; 458 return;
451 } 459 }
452 460
453 list v = llParseString2List( 461 list v = llParseString2List(
454 wasKeyValueGet( 462 wasKeyValueGet(
455 "data", 463 "data",
456 body 464 body
457 ), 465 ),
458 ["."], 466 ["."],
459 [] 467 []
460 ); 468 );
461 integer receivedVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); 469 integer receivedVersion = (integer)(llList2String(v, 0) + llList2String(v, 1));
462 v = llParseString2List( 470 v = llParseString2List(
463 wasKeyValueGet( 471 wasKeyValueGet(
464 "version", 472 "version",
465 configuration 473 configuration
466 ), 474 ),
467 ["."], 475 ["."],
468 [] 476 []
469 ); 477 );
470 integer notecardVersion = (integer)(llList2String(v, 0) + llList2String(v, 1)); 478 integer notecardVersion = (integer)(llList2String(v, 0) + llList2String(v, 1));
471 if(receivedVersion < notecardVersion) { 479 if(receivedVersion < notecardVersion) {
472 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: " +
473 wasKeyValueGet( 481 wasKeyValueGet(
474 "version", 482 "version",
475 configuration 483 configuration
476 ) + 484 ) +
477 " for this HUD." 485 " for this template."
478 ); 486 );
479 compatible = FALSE; 487 compatible = FALSE;
480 //llReleaseURL(URL); 488 //llReleaseURL(URL);
481 return; 489 return;
482 } 490 }
483 // DEBUG 491 // DEBUG
484 llOwnerSay("[Control] Version is compatible!"); 492 llOwnerSay("[Control] Version is compatible!");
485 compatible = TRUE; 493 compatible = TRUE;
486 //llReleaseURL(URL); 494 //llReleaseURL(URL);
487 return; 495 return;
488 } 496 }
489 link_message(integer sender, integer num, string message, key id) { 497 link_message(integer sender, integer num, string message, key id) {
490 if(message != "configuration") return; 498 if(message != "configuration") return;
491 llMessageLinked(LINK_THIS, 0, configuration, "configuration"); 499 llMessageLinked(LINK_THIS, 0, configuration, "configuration");
492 } 500 }
493 timer() { 501 timer() {
494 llOwnerSay("[Control] Timeout checking version..."); 502 llOwnerSay("[Control] Timeout checking version...");
495 llResetScript(); 503 llResetScript();
496 } 504 }
497 on_rez(integer num) { 505 on_rez(integer num) {
498 llResetScript(); 506 llResetScript();
499 } 507 }
500 changed(integer change) { 508 changed(integer change) {
501 if((change & CHANGED_INVENTORY) || 509 if((change & CHANGED_INVENTORY) ||
502 (change & CHANGED_REGION_START) || 510 (change & CHANGED_REGION_START) ||
503 (change & CHANGED_OWNER)) { 511 (change & CHANGED_OWNER)) {
504 llResetScript(); 512 llResetScript();
505 } 513 }
506 } 514 }
507 state_exit() { 515 state_exit() {
508 llSetTimerEvent(0); 516 llSetTimerEvent(0);
509 } 517 }
510 } 518 }
511   519