corrade-lsl-templates – Diff between revs 41 and 42

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
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 MOTD module for Corrade Eggdrop. 5 // A MOTD module for Corrade Eggdrop.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
8 8  
9 /////////////////////////////////////////////////////////////////////////// 9 ///////////////////////////////////////////////////////////////////////////
10 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 10 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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 "";
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 30... Line 30...
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) 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);
42 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); 42 float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
43 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) 43 if(llPow(x,2) + llPow(y,2) <= llPow(radius,2))
44 return <x, y, 0>; 44 return <x, y, 0>;
45 return wasCirclePoint(radius); 45 return wasCirclePoint(radius);
46 } 46 }
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 = "";
54 do { 54 do {
Line 66... Line 66...
66 o += llEscapeURL(c); 66 o += llEscapeURL(c);
67 @continue; 67 @continue;
68 } while(i != ""); 68 } while(i != "");
69 return o; 69 return o;
70 } 70 }
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 = [];
78 string m = ""; 78 string m = "";
Line 105... Line 105...
105 @continue; 105 @continue;
106 } while(csv != ""); 106 } while(csv != "");
107 // postcondition: length(s) = 0 107 // postcondition: length(s) = 0
108 return l + m; 108 return l + m;
109 } 109 }
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, ",");
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 )
161 ); 161 );
162 } 162 }
163 163  
164 // configuration data 164 // configuration data
165 string configuration = ""; 165 string configuration = "";
166 // callback URL -  
167 string URL = ""; -  
168 // store message over state. 166 // store message over state.
169 string firstname = ""; 167 string firstname = "";
170 string lastname = ""; 168 string lastname = "";
171 string group = ""; 169 string group = "";
172 string data = ""; 170 string data = "";
173 string jump_state = ""; 171 string jump_state = "";
-   172 integer membershipFee;
174 173  
175 default { 174 default {
176 state_entry() { 175 state_entry() {
177 llOwnerSay("[MOTD] Starting module..."); 176 llOwnerSay("[MOTD] Starting module...");
178 llSetTimerEvent(10); 177 llSetTimerEvent(10);
179 } 178 }
180 link_message(integer sender, integer num, string message, key id) { 179 link_message(integer sender, integer num, string message, key id) {
181 if(id != "configuration") return; 180 if(id != "configuration") return;
182 llOwnerSay("[MOTD] Got configuration..."); 181 llOwnerSay("[MOTD] Got configuration...");
183 configuration = message; 182 configuration = message;
184 jump_state = "create_database"; 183 jump_state = "create_database";
185 state url; 184 state trampoline;
186 } 185 }
187 timer() { 186 timer() {
188 llOwnerSay("[MOTD] Requesting configuration..."); 187 llOwnerSay("[MOTD] Requesting configuration...");
189 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 188 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
190 } 189 }
191 on_rez(integer num) { 190 on_rez(integer num) {
192 llResetScript(); 191 llResetScript();
193 } 192 }
194 changed(integer change) { 193 changed(integer change) {
195 if((change & CHANGED_INVENTORY) || 194 if((change & CHANGED_INVENTORY) ||
196 (change & CHANGED_REGION_START) || 195 (change & CHANGED_REGION_START) ||
197 (change & CHANGED_OWNER)) { 196 (change & CHANGED_OWNER)) {
198 llResetScript(); 197 llResetScript();
199 } 198 }
200 } 199 }
201 state_exit() { 200 state_exit() {
202 llSetTimerEvent(0); 201 llSetTimerEvent(0);
203 } 202 }
204 } 203 }
205 204  
206 state url { 205 state trampoline {
207 state_entry() { 206 state_entry() {
208 // DEBUG -  
209 llOwnerSay("[MOTD] Requesting URL..."); -  
210 llRequestURL(); -  
211 } -  
212 http_request(key id, string method, string body) { -  
213 if(method != URL_REQUEST_GRANTED) return; -  
214 URL = body; -  
215 // DEBUG -  
216 llOwnerSay("[MOTD] Got URL..."); -  
217 if(jump_state == "create_database") 207 if(jump_state == "create_database")
218 state create_database; 208 state create_database;
219 if(jump_state == "greet") 209 if(jump_state == "greet")
220 state greet; 210 state greet;
221 if(jump_state == "get") 211 if(jump_state == "get")
222 state get; 212 state get;
223 if(jump_state == "set") 213 if(jump_state == "set")
224 state set; 214 state set;
-   215 if(jump_state == "fee")
-   216 state fee;
-   217 if(jump_state == "pay")
-   218 state pay;
225 if(jump_state == "listen_group") 219 if(jump_state == "listen_group")
226 state listen_group; 220 state listen_group;
227 221  
228 // DEBUG 222 // DEBUG
229 llOwnerSay("[MOTD] Jump table corrupted, please contact creator..."); 223 llOwnerSay("[MOTD] Jump table corrupted, please contact creator...");
230 llResetScript(); 224 llResetScript();
231 } 225 }
232 on_rez(integer num) { 226 on_rez(integer num) {
233 llResetScript(); 227 llResetScript();
234 } 228 }
235 changed(integer change) { 229 changed(integer change) {
236 if((change & CHANGED_INVENTORY) || 230 if((change & CHANGED_INVENTORY) ||
237 (change & CHANGED_REGION_START) || 231 (change & CHANGED_REGION_START) ||
238 (change & CHANGED_OWNER)) { 232 (change & CHANGED_OWNER)) {
239 llResetScript(); 233 llResetScript();
240 } 234 }
241 } 235 }
242 } 236 }
243 237  
244 state create_database { 238 state create_database {
245 state_entry() { 239 state_entry() {
246 // DEBUG 240 // DEBUG
247 llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration)); 241 llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration));
248 llInstantMessage( 242 llInstantMessage(
249 wasKeyValueGet( 243 wasKeyValueGet(
250 "corrade", 244 "corrade",
251 configuration 245 configuration
252 ), 246 ),
253 wasKeyValueEncode( 247 wasKeyValueEncode(
254 [ 248 [
255 "command", "database", 249 "command", "database",
256 "group", wasURLEscape( 250 "group", wasURLEscape(
257 wasKeyValueGet( 251 wasKeyValueGet(
258 "group", 252 "group",
259 configuration 253 configuration
260 ) 254 )
261 ), 255 ),
262 "password", wasURLEscape( 256 "password", wasURLEscape(
263 wasKeyValueGet( 257 wasKeyValueGet(
264 "password", 258 "password",
265 configuration 259 configuration
266 ) 260 )
267 ), 261 ),
268 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 262 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
269 wasKeyValueGet("motd table", configuration) + 263 wasKeyValueGet("motd table", configuration) +
270 "\" (name text unique collate nocase, data text)"), 264 "\" (name text unique collate nocase, data text)"),
271 "callback", wasURLEscape(URL) 265 "callback", wasURLEscape(
-   266 wasKeyValueGet(
-   267 "URL",
-   268 configuration
-   269 )
-   270 )
272 ] 271 ]
273 ) 272 )
274 ); 273 );
275 llSetTimerEvent(60); 274 llSetTimerEvent(60);
276 } 275 }
277 http_request(key id, string method, string body) { 276 link_message(integer sender, integer num, string body, key id) {
278 llHTTPResponse(id, 200, "OK"); 277 // Only process callbacks for the database command.
279 llReleaseURL(URL); -  
280 if(wasKeyValueGet("command", body) != "database" || 278 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   279 return;
-   280  
281 wasKeyValueGet("success", body) != "True") { 281 if(wasKeyValueGet("success", body) != "True") {
282 // DEBUG 282 // DEBUG
283 llOwnerSay("[MOTD] Unable modify database: " + 283 llOwnerSay("[MOTD] Unable modify database: " +
284 wasURLUnescape( 284 wasURLUnescape(
285 wasKeyValueGet("error", body) 285 wasKeyValueGet("error", body)
286 ) + 286 ) +
287 " " + 287 " " +
288 wasURLUnescape( 288 wasURLUnescape(
289 wasKeyValueGet("data", body) 289 wasKeyValueGet("data", body)
290 ) 290 )
291 291  
292 ); 292 );
293 llResetScript(); 293 llResetScript();
294 } 294 }
295 llOwnerSay("[MOTD] Database created!"); 295 llOwnerSay("[MOTD] Database created!");
296 state listen_group; 296 state listen_group;
297 } 297 }
298 timer() { 298 timer() {
299 llReleaseURL(URL); -  
300 state listen_group; 299 state listen_group;
301 } 300 }
302 on_rez(integer num) { 301 on_rez(integer num) {
303 llResetScript(); 302 llResetScript();
304 } 303 }
305 changed(integer change) { 304 changed(integer change) {
306 if((change & CHANGED_INVENTORY) || 305 if((change & CHANGED_INVENTORY) ||
307 (change & CHANGED_REGION_START) || 306 (change & CHANGED_REGION_START) ||
308 (change & CHANGED_OWNER)) { 307 (change & CHANGED_OWNER)) {
309 llResetScript(); 308 llResetScript();
310 } 309 }
311 } 310 }
312 state_exit() { 311 state_exit() {
313 llSetTimerEvent(0); 312 llSetTimerEvent(0);
314 } 313 }
315 } 314 }
316 315  
317 316  
318 state listen_group { 317 state listen_group {
319 state_entry() { 318 state_entry() {
320 // DEBUG 319 // DEBUG
321 llOwnerSay("[MOTD] Waiting for group messages and new group members."); 320 llOwnerSay("[MOTD] Waiting for group messages and new group members.");
322 } 321 }
323 link_message(integer sender, integer num, string message, key id) { 322 link_message(integer sender, integer num, string message, key id) {
324 // We only care about notifications now. 323 // We only care about notifications now.
325 if(id != "notification") 324 if(id != "notification")
326 return; 325 return;
327 326  
328 // Get the group. 327 // Get the group.
329 group = wasURLUnescape( 328 group = wasURLUnescape(
330 wasKeyValueGet( 329 wasKeyValueGet(
331 "group", 330 "group",
332 message 331 message
333 ) 332 )
334 ); 333 );
335 334  
-   335 // This script only processes group and membership notifications.
-   336 // Esnure that the notification is meant for the configured group.
-   337 if((wasKeyValueGet("type", message) != "membership" && wasKeyValueGet("type", message) != "group") ||
-   338 ((wasKeyValueGet("type", message) == "membership" || wasKeyValueGet("type", message) == "group") &&
-   339 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   340 wasKeyValueGet("group", configuration)))
-   341 return;
-   342  
336 // Retrieve the membership notification. 343 // Retrieve the membership notification.
337 if(wasKeyValueGet("type", message) == "membership" && 344 if(wasKeyValueGet("type", message) == "membership" &&
338 wasKeyValueGet("action", message) == "joined") { 345 wasKeyValueGet("action", message) == "joined") {
339 firstname = wasURLUnescape( 346 firstname = wasURLUnescape(
340 wasKeyValueGet( 347 wasKeyValueGet(
Line 346... Line 353...
346 wasKeyValueGet( 353 wasKeyValueGet(
347 "lastname", 354 "lastname",
348 message 355 message
349 ) 356 )
350 ); 357 );
-   358  
-   359 if(wasKeyValueGet("pay back", configuration) != "true") {
-   360 jump_state = "greet";
-   361 state trampoline;
-   362 }
-   363  
351 jump_state = "greet"; 364 jump_state = "fee";
352 state url; 365 state trampoline;
353 } 366 }
354 367  
355 // This script only processes group notifications. -  
356 if(wasKeyValueGet("type", message) != "group") -  
357 return; -  
358 -  
359 // Get the sent message. 368 // Get the sent message.
360 data = wasURLUnescape( 369 data = wasURLUnescape(
361 wasKeyValueGet( 370 wasKeyValueGet(
362 "message", 371 "message",
363 message 372 message
364 ) 373 )
365 ); 374 );
366 375  
367 // Check if this is an eggdrop command. 376 // Check if this is an eggdrop command.
368 if(llGetSubString(data, 0, 0) != 377 if(llGetSubString(data, 0, 0) !=
369 wasKeyValueGet("command", configuration)) 378 wasKeyValueGet("command", configuration))
370 return; 379 return;
371 380  
372 // Check if the command matches the current module. 381 // Check if the command matches the current module.
373 list command = llParseString2List(data, [" "], []); 382 list command = llParseString2List(data, [" "], []);
374 if(llList2String(command, 0) != 383 if(llList2String(command, 0) !=
375 wasKeyValueGet("command", configuration) + "motd") 384 wasKeyValueGet("command", configuration) + "motd")
376 return; 385 return;
377 386  
378 // Remove command. 387 // Remove command.
379 command = llDeleteSubList(command, 0, 0); 388 command = llDeleteSubList(command, 0, 0);
380 389  
381 // Dump the rest of the message. 390 // Dump the rest of the message.
382 data = llDumpList2String(command, " "); 391 data = llDumpList2String(command, " ");
383 392  
-   393 // DEBUG
-   394 //llOwnerSay("Remaining data: " + data);
-   395  
384 // Get the sent message. 396 // Get the sent message.
385 if(data == "") { 397 if(data == "") {
386 jump_state = "get"; 398 jump_state = "get";
387 state url; 399 state trampoline;
388 } 400 }
389 401  
-   402 data = wasURLEscape(data);
390 jump_state = "set"; 403 jump_state = "set";
391 state url; 404 state trampoline;
392 } 405 }
393 on_rez(integer num) { 406 on_rez(integer num) {
394 llResetScript(); 407 llResetScript();
395 } 408 }
396 changed(integer change) { 409 changed(integer change) {
397 if((change & CHANGED_INVENTORY) || 410 if((change & CHANGED_INVENTORY) ||
398 (change & CHANGED_REGION_START) || 411 (change & CHANGED_REGION_START) ||
399 (change & CHANGED_OWNER)) { 412 (change & CHANGED_OWNER)) {
400 llResetScript(); 413 llResetScript();
401 } 414 }
402 } 415 }
403 } 416 }
404 417  
405 state greet { 418 state greet {
406 state_entry() { 419 state_entry() {
407 // DEBUG 420 // DEBUG
408 llOwnerSay("[MOTD] Member joined, retrieving MOTD..."); 421 llOwnerSay("[MOTD] Retrieving MOTD...");
409 llInstantMessage( 422 llInstantMessage(
410 wasKeyValueGet( 423 wasKeyValueGet(
411 "corrade", 424 "corrade",
412 configuration 425 configuration
413 ), 426 ),
414 wasKeyValueEncode( 427 wasKeyValueEncode(
415 [ 428 [
416 "command", "database", 429 "command", "database",
417 "group", wasURLEscape( 430 "group", wasURLEscape(
418 wasKeyValueGet( 431 wasKeyValueGet(
419 "group", 432 "group",
420 configuration 433 configuration
421 ) 434 )
422 ), 435 ),
423 "password", wasURLEscape( 436 "password", wasURLEscape(
424 wasKeyValueGet( 437 wasKeyValueGet(
425 "password", 438 "password",
426 configuration 439 configuration
427 ) 440 )
428 ), 441 ),
429 "SQL", wasURLEscape("SELECT data FROM \"" + 442 "SQL", wasURLEscape("SELECT data FROM \"" +
430 wasKeyValueGet("motd table", configuration) + 443 wasKeyValueGet("motd table", configuration) +
431 "\" WHERE name=:group"), 444 "\" WHERE name=:group"),
432 "data", wasURLEscape( 445 "data", wasURLEscape(
433 wasListToCSV( 446 wasListToCSV(
434 [ 447 [
435 "group", 448 "group",
436 wasURLEscape(group) 449 wasURLEscape(group)
437 ] 450 ]
438 ) 451 )
439 ), 452 ),
440 "callback", wasURLEscape(URL) 453 "callback", wasURLEscape(
-   454 wasKeyValueGet(
-   455 "URL",
-   456 configuration
-   457 )
-   458 )
441 ] 459 ]
442 ) 460 )
443 ); 461 );
444 llSetTimerEvent(60); 462 llSetTimerEvent(60);
445 } 463 }
446 http_request(key id, string method, string body) { 464 link_message(integer sender, integer num, string body, key id) {
447 llHTTPResponse(id, 200, "OK"); 465 // Only process callbacks for the database command.
448 llReleaseURL(URL); -  
449 if(wasKeyValueGet("command", body) != "database" || 466 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   467 return;
-   468  
450 wasKeyValueGet("success", body) != "True") { 469 if(wasKeyValueGet("success", body) != "True") {
451 // DEBUG 470 // DEBUG
452 llOwnerSay("[MOTD] Unable retrieve from database: " + 471 llOwnerSay("[MOTD] Unable retrieve from database: " +
453 wasURLUnescape( 472 wasURLUnescape(
454 wasKeyValueGet("error", body) 473 wasKeyValueGet("error", body)
455 ) 474 )
456 ); 475 );
457 state listen_group; 476 state listen_group;
458 } 477 }
459 478  
460 data = llDumpList2String( 479 data = llDumpList2String(
461 llDeleteSubList( 480 llDeleteSubList(
462 wasCSVToList( 481 wasCSVToList(
463 wasURLUnescape( 482 wasURLUnescape(
464 wasKeyValueGet("data", body) 483 wasKeyValueGet("data", body)
Line 467... Line 486...
467 0, 486 0,
468 0 487 0
469 ), 488 ),
470 "" 489 ""
471 ); 490 );
472 491  
473 if(data == "") 492 if(data == "")
474 state listen_group; 493 state listen_group;
475 494  
476 data = "Hello " + firstname + " " + lastname + "!" + " " + data; 495 data = "Hello " + firstname + " " + lastname + "!" + " " + data;
477 state tell; 496 state tell;
478 } 497 }
479 timer() { 498 timer() {
480 llReleaseURL(URL); -  
481 state listen_group; 499 state listen_group;
482 } 500 }
483 on_rez(integer num) { 501 on_rez(integer num) {
484 llResetScript(); 502 llResetScript();
485 } 503 }
486 changed(integer change) { 504 changed(integer change) {
487 if((change & CHANGED_INVENTORY) || 505 if((change & CHANGED_INVENTORY) ||
488 (change & CHANGED_REGION_START) || 506 (change & CHANGED_REGION_START) ||
489 (change & CHANGED_OWNER)) { 507 (change & CHANGED_OWNER)) {
490 llResetScript(); 508 llResetScript();
491 } 509 }
492 } 510 }
493 state_exit() { 511 state_exit() {
494 llSetTimerEvent(0); 512 llSetTimerEvent(0);
495 } 513 }
496 } 514 }
497 515  
498 state get { 516 state get {
499 state_entry() { 517 state_entry() {
500 // DEBUG 518 // DEBUG
501 llOwnerSay("[MOTD] Retrieving from database."); 519 llOwnerSay("[MOTD] Retrieving from database.");
502 llInstantMessage( 520 llInstantMessage(
503 wasKeyValueGet( 521 wasKeyValueGet(
504 "corrade", 522 "corrade",
505 configuration 523 configuration
506 ), 524 ),
507 wasKeyValueEncode( 525 wasKeyValueEncode(
508 [ 526 [
509 "command", "database", 527 "command", "database",
510 "group", wasURLEscape( 528 "group", wasURLEscape(
511 wasKeyValueGet( 529 wasKeyValueGet(
512 "group", 530 "group",
513 configuration 531 configuration
514 ) 532 )
515 ), 533 ),
516 "password", wasURLEscape( 534 "password", wasURLEscape(
517 wasKeyValueGet( 535 wasKeyValueGet(
518 "password", 536 "password",
519 configuration 537 configuration
520 ) 538 )
521 ), 539 ),
522 "SQL", wasURLEscape("SELECT data FROM \"" + 540 "SQL", wasURLEscape("SELECT data FROM \"" +
523 wasKeyValueGet("motd table", configuration) + 541 wasKeyValueGet("motd table", configuration) +
524 "\" WHERE name=:group"), 542 "\" WHERE name=:group"),
525 "data", wasURLEscape( 543 "data", wasURLEscape(
526 wasListToCSV( 544 wasListToCSV(
527 [ 545 [
528 "group", 546 "group",
529 wasURLEscape( 547 wasURLEscape(
530 wasKeyValueGet( 548 wasKeyValueGet(
531 "group", 549 "group",
532 configuration 550 configuration
533 ) 551 )
534 ) 552 )
535 ] 553 ]
536 ) 554 )
537 ), 555 ),
538 "callback", wasURLEscape(URL) 556 "callback", wasURLEscape(
-   557 wasKeyValueGet(
-   558 "URL",
-   559 configuration
-   560 )
-   561 )
539 ] 562 ]
540 ) 563 )
541 ); 564 );
542 llSetTimerEvent(60); 565 llSetTimerEvent(60);
543 } 566 }
544 http_request(key id, string method, string body) { 567 link_message(integer sender, integer num, string body, key id) {
545 llHTTPResponse(id, 200, "OK"); 568 // Only process callbacks for the database command.
546 llReleaseURL(URL); -  
547 if(wasKeyValueGet("command", body) != "database" || 569 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   570 return;
-   571  
548 wasKeyValueGet("success", body) != "True") { 572 if(wasKeyValueGet("success", body) != "True") {
549 // DEBUG 573 // DEBUG
550 llOwnerSay("[MOTD] Unable retrieve from database: " + 574 llOwnerSay("[MOTD] Unable retrieve from database: " +
551 wasURLUnescape( 575 wasURLUnescape(
552 wasKeyValueGet("error", body) 576 wasKeyValueGet("error", body)
553 ) 577 )
554 ); 578 );
555 state listen_group; 579 state listen_group;
556 } 580 }
557 581  
558 data = llDumpList2String( 582 data = llDumpList2String(
559 llDeleteSubList( 583 llDeleteSubList(
560 wasCSVToList( 584 wasCSVToList(
561 wasURLUnescape( 585 wasURLUnescape(
562 wasKeyValueGet("data", body) 586 wasKeyValueGet("data", body)
Line 565... Line 589...
565 0, 589 0,
566 0 590 0
567 ), 591 ),
568 "" 592 ""
569 ); 593 );
570 594  
571 if(data == "") { 595 if(data == "") {
572 data = "Sorry, no MOTD is currently set."; 596 data = "Sorry, no MOTD is currently set.";
573 state tell; 597 state tell;
574 } 598 }
575 599  
576 state tell; 600 state tell;
577 } 601 }
578 timer() { 602 timer() {
579 llReleaseURL(URL); -  
580 state listen_group; 603 state listen_group;
581 } 604 }
582 on_rez(integer num) { 605 on_rez(integer num) {
583 llResetScript(); 606 llResetScript();
584 } 607 }
585 changed(integer change) { 608 changed(integer change) {
-   609 if((change & CHANGED_INVENTORY) ||
-   610 (change & CHANGED_REGION_START) ||
-   611 (change & CHANGED_OWNER)) {
-   612 llResetScript();
-   613 }
-   614 }
-   615 state_exit() {
-   616 llSetTimerEvent(0);
-   617 }
-   618 }
-   619  
-   620 state fee {
-   621 state_entry() {
-   622 // DEBUG
-   623 llOwnerSay("[MOTD] Member joined, getting group membership fee...");
-   624 llInstantMessage(
-   625 wasKeyValueGet(
-   626 "corrade",
-   627 configuration
-   628 ),
-   629 wasKeyValueEncode(
-   630 [
-   631 "command", "getgroupdata",
-   632 "group", wasURLEscape(
-   633 wasKeyValueGet(
-   634 "group",
-   635 configuration
-   636 )
-   637 ),
-   638 "password", wasURLEscape(
-   639 wasKeyValueGet(
-   640 "password",
-   641 configuration
-   642 )
-   643 ),
-   644 "data", "MembershipFee",
-   645 "callback", wasURLEscape(
-   646 wasKeyValueGet(
-   647 "URL",
-   648 configuration
-   649 )
-   650 )
-   651 ]
-   652 )
-   653 );
-   654 llSetTimerEvent(60);
-   655 }
-   656 link_message(integer sender, integer num, string body, key id) {
-   657 // Only process callbacks for the database command.
-   658 if(id != "callback" || wasKeyValueGet("command", body) != "getgroupdata")
-   659 return;
-   660  
-   661 if(wasKeyValueGet("success", body) != "True") {
-   662 // DEBUG
-   663 llOwnerSay("[MOTD] Unable to get group data: " +
-   664 wasURLUnescape(
-   665 wasKeyValueGet("error", body)
-   666 )
-   667 );
-   668 state listen_group;
-   669 }
-   670  
-   671 list membership = wasCSVToList(
-   672 wasURLUnescape(
-   673 wasKeyValueGet(
-   674 "data",
-   675 body
-   676 )
-   677 )
-   678 );
-   679  
-   680 membershipFee = llList2Integer(
-   681 membership,
-   682 llListFindList(
-   683 membership,
-   684 [ "MembershipFee" ]
-   685 ) + 1
-   686 );
-   687  
-   688 if(membershipFee <= 0) {
-   689 // DEBUG
-   690 llOwnerSay("The configured group does not have a membership fee!");
-   691 state listen_group;
-   692 }
-   693  
-   694 jump_state = "pay";
-   695 state trampoline;
-   696 }
-   697 timer() {
-   698 state listen_group;
-   699 }
-   700 on_rez(integer num) {
-   701 llResetScript();
-   702 }
-   703 changed(integer change) {
586 if((change & CHANGED_INVENTORY) || 704 if((change & CHANGED_INVENTORY) ||
587 (change & CHANGED_REGION_START) || 705 (change & CHANGED_REGION_START) ||
588 (change & CHANGED_OWNER)) { 706 (change & CHANGED_OWNER)) {
589 llResetScript(); 707 llResetScript();
590 } 708 }
591 } 709 }
592 state_exit() { 710 state_exit() {
593 llSetTimerEvent(0); 711 llSetTimerEvent(0);
594 } 712 }
595 } 713 }
-   714  
-   715 state pay {
-   716 state_entry() {
-   717 // DEBUG
-   718 llOwnerSay("[MOTD] Paying back the entrance fee...");
-   719 llInstantMessage(
-   720 wasKeyValueGet(
-   721 "corrade",
-   722 configuration
-   723 ),
-   724 wasKeyValueEncode(
-   725 [
-   726 "command", "pay",
-   727 "group", wasURLEscape(
-   728 wasKeyValueGet(
-   729 "group",
-   730 configuration
-   731 )
-   732 ),
-   733 "password", wasURLEscape(
-   734 wasKeyValueGet(
-   735 "password",
-   736 configuration
-   737 )
-   738 ),
-   739 "amount", membershipFee,
-   740 "entity", "avatar",
-   741 "firstname", wasURLEscape(firstname),
-   742 "lastname", wasURLEscape(lastname),
-   743 "callback", wasURLEscape(
-   744 wasKeyValueGet(
-   745 "URL",
-   746 configuration
-   747 )
-   748 )
-   749 ]
-   750 )
-   751 );
-   752 llSetTimerEvent(60);
-   753 }
-   754 link_message(integer sender, integer num, string body, key id) {
-   755 // Only process callbacks for the database command.
-   756 if(id != "callback" || wasKeyValueGet("command", body) != "pay")
-   757 return;
-   758  
-   759 if(wasKeyValueGet("success", body) != "True") {
-   760 // DEBUG
-   761 llOwnerSay("[MOTD] Unable to pay the entrance fee: " +
-   762 wasURLUnescape(
-   763 wasKeyValueGet("error", body)
-   764 )
-   765 );
-   766 state listen_group;
-   767 }
-   768  
-   769 // DEBUG
-   770 llOwnerSay("[MOTD] Paid back the entrance fee.");
-   771  
-   772 jump_state = "greet";
-   773 state trampoline;
-   774 }
-   775 timer() {
-   776 state listen_group;
-   777 }
-   778 on_rez(integer num) {
-   779 llResetScript();
-   780 }
-   781 changed(integer change) {
-   782 if((change & CHANGED_INVENTORY) ||
-   783 (change & CHANGED_REGION_START) ||
-   784 (change & CHANGED_OWNER)) {
-   785 llResetScript();
-   786 }
-   787 }
-   788 state_exit() {
-   789 llSetTimerEvent(0);
-   790 }
-   791 }
596 792  
597 state set { 793 state set {
598 state_entry() { 794 state_entry() {
599 // DEBUG 795 // DEBUG
600 llOwnerSay("[MOTD] Adding to database."); 796 llOwnerSay("[MOTD] Adding to database...");
601 llInstantMessage( 797 llInstantMessage(
602 wasKeyValueGet( 798 wasKeyValueGet(
603 "corrade", 799 "corrade",
604 configuration 800 configuration
605 ), 801 ),
606 wasKeyValueEncode( 802 wasKeyValueEncode(
607 [ 803 [
608 "command", "database", 804 "command", "database",
609 "group", wasURLEscape( 805 "group", wasURLEscape(
610 wasKeyValueGet( 806 wasKeyValueGet(
611 "group", 807 "group",
612 configuration 808 configuration
613 ) 809 )
614 ), 810 ),
615 "password", wasURLEscape( 811 "password", wasURLEscape(
616 wasKeyValueGet( 812 wasKeyValueGet(
617 "password", 813 "password",
618 configuration 814 configuration
619 ) 815 )
620 ), 816 ),
621 "SQL", wasURLEscape("REPLACE INTO \"" + 817 "SQL", wasURLEscape("REPLACE INTO \"" +
622 wasKeyValueGet("motd table", configuration) + 818 wasKeyValueGet("motd table", configuration) +
623 "\" (name, data) VALUES (:name, :data)"), 819 "\" (name, data) VALUES (:group, :message)"),
624 "data", wasURLEscape( 820 "data", wasURLEscape(
625 wasListToCSV( 821 wasListToCSV(
626 [ 822 [
627 "name", 823 "group",
628 wasURLEscape( 824 wasURLEscape(
629 wasKeyValueGet( 825 wasKeyValueGet(
630 "group", 826 "group",
631 configuration 827 configuration
632 ) 828 )
633 ), 829 ),
634 "data", 830 "message",
635 wasURLEscape(data) 831 data
636 ] 832 ]
637 ) 833 )
638 ), 834 ),
639 "callback", wasURLEscape(URL) 835 "callback", wasURLEscape(
-   836 wasKeyValueGet(
-   837 "URL",
-   838 configuration
-   839 )
-   840 )
640 ] 841 ]
641 ) 842 )
642 ); 843 );
643 llSetTimerEvent(60); 844 llSetTimerEvent(60);
644 } 845 }
645 http_request(key id, string method, string body) { 846 link_message(integer sender, integer num, string body, key id) {
646 llHTTPResponse(id, 200, "OK"); 847 // Only process callbacks for the database command.
647 llReleaseURL(URL); -  
648 if(wasKeyValueGet("command", body) != "database" || 848 if(id != "callback" || wasKeyValueGet("command", body) != "database")
-   849 return;
-   850  
649 wasKeyValueGet("success", body) != "True") { 851 if(wasKeyValueGet("success", body) != "True") {
650 // DEBUG 852 // DEBUG
651 llOwnerSay("[MOTD] Unable modify database: " + 853 llOwnerSay("[MOTD] Unable modify database: " +
652 wasURLUnescape( 854 wasURLUnescape(
653 wasKeyValueGet("error", body) 855 wasKeyValueGet("error", body)
654 ) 856 )
655 ); 857 );
656 state listen_group; 858 state listen_group;
657 } 859 }
658 data = "Saved"; 860 data = "Saved";
659 state tell; 861 state tell;
660 } 862 }
661 timer() { 863 timer() {
662 llReleaseURL(URL); -  
663 state listen_group; 864 state listen_group;
664 } 865 }
665 on_rez(integer num) { 866 on_rez(integer num) {
666 llResetScript(); 867 llResetScript();
667 } 868 }
668 changed(integer change) { 869 changed(integer change) {
669 if((change & CHANGED_INVENTORY) || 870 if((change & CHANGED_INVENTORY) ||
670 (change & CHANGED_REGION_START) || 871 (change & CHANGED_REGION_START) ||
671 (change & CHANGED_OWNER)) { 872 (change & CHANGED_OWNER)) {
672 llResetScript(); 873 llResetScript();
673 } 874 }
674 } 875 }
675 state_exit() { 876 state_exit() {
676 llSetTimerEvent(0); 877 llSetTimerEvent(0);
677 } 878 }
678 } 879 }
679 880  
680 state tell { 881 state tell {
681 state_entry() { 882 state_entry() {
682 // DEBUG 883 // DEBUG
683 llOwnerSay("[MOTD] Sending to group."); 884 llOwnerSay("[MOTD] Sending to group.");
684 llInstantMessage( 885 llInstantMessage(
685 wasKeyValueGet( 886 wasKeyValueGet(
686 "corrade", 887 "corrade",
687 configuration 888 configuration
688 ), 889 ),
689 wasKeyValueEncode( 890 wasKeyValueEncode(
690 [ 891 [
691 "command", "tell", 892 "command", "tell",
692 "group", wasURLEscape( 893 "group", wasURLEscape(
693 wasKeyValueGet( 894 wasKeyValueGet(
694 "group", 895 "group",
695 configuration 896 configuration
696 ) 897 )
697 ), 898 ),
698 "password", wasURLEscape( 899 "password", wasURLEscape(
699 wasKeyValueGet( 900 wasKeyValueGet(
700 "password", 901 "password",
701 configuration 902 configuration
702 ) 903 )
703 ), 904 ),
704 "entity", "group", 905 "entity", "group",
705 "message", wasURLEscape(data) 906 "message", wasURLEscape(data)