corrade-lsl-templates – Diff between revs 24 and 29

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 24 Rev 29
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
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) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 10 // Copyright (C) 2014 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 "";
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(a, [ k ]); 16 integer i = llListFindList(a, [ k ]);
17 if(i != -1) return llList2String(a, i+1); 17 if(i != -1) return llList2String(a, 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: 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);
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) 2011 Wizardry and Steamworks - License: GNU GPLv3 // 37 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 49 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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 {
55 string c = llGetSubString(i, 0, 0); 55 string c = llGetSubString(i, 0, 0);
56 i = llDeleteSubString(i, 0, 0); 56 i = llDeleteSubString(i, 0, 0);
57 if(c == "") jump continue; 57 if(c == "") jump continue;
58 if(c == " ") { 58 if(c == " ") {
59 o += "+"; 59 o += "+";
60 jump continue; 60 jump continue;
61 } 61 }
62 if(c == "\n") { 62 if(c == "\n") {
63 o += "%0D" + llEscapeURL(c); 63 o += "%0D" + llEscapeURL(c);
64 jump continue; 64 jump continue;
65 } 65 }
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: GNU GPLv3 // 73 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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 = "";
79 do { 79 do {
80 string a = llGetSubString(csv, 0, 0); 80 string a = llGetSubString(csv, 0, 0);
81 csv = llDeleteSubString(csv, 0, 0); 81 csv = llDeleteSubString(csv, 0, 0);
82 if(a == ",") { 82 if(a == ",") {
83 if(llList2String(s, -1) != "\"") { 83 if(llList2String(s, -1) != "\"") {
84 l += m; 84 l += m;
85 m = ""; 85 m = "";
86 jump continue; 86 jump continue;
87 } 87 }
88 m += a; 88 m += a;
89 jump continue; 89 jump continue;
90 } 90 }
91 if(a == "\"" && llGetSubString(csv, 0, 0) == a) { 91 if(a == "\"" && llGetSubString(csv, 0, 0) == a) {
92 m += a; 92 m += a;
93 csv = llDeleteSubString(csv, 0, 0); 93 csv = llDeleteSubString(csv, 0, 0);
94 jump continue; 94 jump continue;
95 } 95 }
96 if(a == "\"") { 96 if(a == "\"") {
97 if(llList2String(s, -1) != a) { 97 if(llList2String(s, -1) != a) {
98 s += a; 98 s += a;
99 jump continue; 99 jump continue;
100 } 100 }
101 s = llDeleteSubList(s, -1, -1); 101 s = llDeleteSubList(s, -1, -1);
102 jump continue; 102 jump continue;
103 } 103 }
104 m += a; 104 m += a;
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: GNU GPLv3 // 112 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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: GNU GPLv3 // 141 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
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 166 // callback URL
167 string URL = ""; 167 string URL = "";
168 // store message over state. 168 // store message over state.
169 string firstname = ""; 169 string firstname = "";
170 string lastname = ""; 170 string lastname = "";
171 string group = ""; 171 string group = "";
172 string data = ""; 172 string data = "";
173 string jump_state = ""; 173 string jump_state = "";
174 174
175 default { 175 default {
176 state_entry() { 176 state_entry() {
177 llOwnerSay("[MOTD] Starting module..."); 177 llOwnerSay("[MOTD] Starting module...");
178 llSetTimerEvent(10); 178 llSetTimerEvent(10);
179 } 179 }
180 link_message(integer sender, integer num, string message, key id) { 180 link_message(integer sender, integer num, string message, key id) {
181 if(id != "configuration") return; 181 if(id != "configuration") return;
182 llOwnerSay("[MOTD] Got configuration..."); 182 llOwnerSay("[MOTD] Got configuration...");
183 configuration = message; 183 configuration = message;
184 jump_state = "create_database"; 184 jump_state = "create_database";
185 state url; 185 state url;
186 } 186 }
187 timer() { 187 timer() {
188 llOwnerSay("[MOTD] Requesting configuration..."); 188 llOwnerSay("[MOTD] Requesting configuration...");
189 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 189 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
190 } 190 }
191 on_rez(integer num) { 191 on_rez(integer num) {
192 llResetScript(); 192 llResetScript();
193 } 193 }
194 changed(integer change) { 194 changed(integer change) {
195 if((change & CHANGED_INVENTORY) || 195 if((change & CHANGED_INVENTORY) ||
196 (change & CHANGED_REGION_START) || 196 (change & CHANGED_REGION_START) ||
197 (change & CHANGED_OWNER)) { 197 (change & CHANGED_OWNER)) {
198 llResetScript(); 198 llResetScript();
199 } 199 }
200 } 200 }
201 state_exit() { 201 state_exit() {
202 llSetTimerEvent(0); 202 llSetTimerEvent(0);
203 } 203 }
204 } 204 }
205 205
206 state url { 206 state url {
207 state_entry() { 207 state_entry() {
208 // DEBUG 208 // DEBUG
209 llOwnerSay("[MOTD] Requesting URL..."); 209 llOwnerSay("[MOTD] Requesting URL...");
210 llRequestURL(); 210 llRequestURL();
211 } 211 }
212 http_request(key id, string method, string body) { 212 http_request(key id, string method, string body) {
213 if(method != URL_REQUEST_GRANTED) return; 213 if(method != URL_REQUEST_GRANTED) return;
214 URL = body; 214 URL = body;
215 // DEBUG 215 // DEBUG
216 llOwnerSay("[MOTD] Got URL..."); 216 llOwnerSay("[MOTD] Got URL...");
217 if(jump_state == "create_database") 217 if(jump_state == "create_database")
218 state create_database; 218 state create_database;
219 if(jump_state == "greet") 219 if(jump_state == "greet")
220 state greet; 220 state greet;
221 if(jump_state == "get") 221 if(jump_state == "get")
222 state get; 222 state get;
223 if(jump_state == "set") 223 if(jump_state == "set")
224 state set; 224 state set;
225 if(jump_state == "listen_group") 225 if(jump_state == "listen_group")
226 state listen_group; 226 state listen_group;
227 227
228 // DEBUG 228 // DEBUG
229 llOwnerSay("[MOTD] Jump table corrupted, please contact creator..."); 229 llOwnerSay("[MOTD] Jump table corrupted, please contact creator...");
230 llResetScript(); 230 llResetScript();
231 } 231 }
232 on_rez(integer num) { 232 on_rez(integer num) {
233 llResetScript(); 233 llResetScript();
234 } 234 }
235 changed(integer change) { 235 changed(integer change) {
236 if((change & CHANGED_INVENTORY) || 236 if((change & CHANGED_INVENTORY) ||
237 (change & CHANGED_REGION_START) || 237 (change & CHANGED_REGION_START) ||
238 (change & CHANGED_OWNER)) { 238 (change & CHANGED_OWNER)) {
239 llResetScript(); 239 llResetScript();
240 } 240 }
241 } 241 }
242 } 242 }
243 243
244 state create_database { 244 state create_database {
245 state_entry() { 245 state_entry() {
246 // DEBUG 246 // DEBUG
247 llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration)); 247 llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration));
248 llInstantMessage( 248 llInstantMessage(
249 wasKeyValueGet( 249 wasKeyValueGet(
250 "corrade", 250 "corrade",
251 configuration 251 configuration
252 ), 252 ),
253 wasKeyValueEncode( 253 wasKeyValueEncode(
254 [ 254 [
255 "command", "database", 255 "command", "database",
256 "group", wasURLEscape( 256 "group", wasURLEscape(
257 wasKeyValueGet( 257 wasKeyValueGet(
258 "group", 258 "group",
259 configuration 259 configuration
260 ) 260 )
261 ), 261 ),
262 "password", wasURLEscape( 262 "password", wasURLEscape(
263 wasKeyValueGet( 263 wasKeyValueGet(
264 "password", 264 "password",
265 configuration 265 configuration
266 ) 266 )
267 ), 267 ),
268 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 268 "SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
269 wasKeyValueGet("motd table", configuration) + 269 wasKeyValueGet("motd table", configuration) +
270 "\" (name text unique collate nocase, data text)"), 270 "\" (name text unique collate nocase, data text)"),
271 "callback", wasURLEscape(URL) 271 "callback", wasURLEscape(URL)
272 ] 272 ]
273 ) 273 )
274 ); 274 );
275 llSetTimerEvent(60); 275 llSetTimerEvent(60);
276 } 276 }
277 http_request(key id, string method, string body) { 277 http_request(key id, string method, string body) {
278 llHTTPResponse(id, 200, "OK"); 278 llHTTPResponse(id, 200, "OK");
279 llReleaseURL(URL); 279 llReleaseURL(URL);
280 if(wasKeyValueGet("command", body) != "database" || 280 if(wasKeyValueGet("command", body) != "database" ||
281 wasKeyValueGet("success", body) != "True") { 281 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); 299 llReleaseURL(URL);
300 state listen_group; 300 state listen_group;
301 } 301 }
302 on_rez(integer num) { 302 on_rez(integer num) {
303 llResetScript(); 303 llResetScript();
304 } 304 }
305 changed(integer change) { 305 changed(integer change) {
306 if((change & CHANGED_INVENTORY) || 306 if((change & CHANGED_INVENTORY) ||
307 (change & CHANGED_REGION_START) || 307 (change & CHANGED_REGION_START) ||
308 (change & CHANGED_OWNER)) { 308 (change & CHANGED_OWNER)) {
309 llResetScript(); 309 llResetScript();
310 } 310 }
311 } 311 }
312 state_exit() { 312 state_exit() {
313 llSetTimerEvent(0); 313 llSetTimerEvent(0);
314 } 314 }
315 } 315 }
316 316
317 317
318 state listen_group { 318 state listen_group {
319 state_entry() { 319 state_entry() {
320 // DEBUG 320 // DEBUG
321 llOwnerSay("[MOTD] Waiting for group messages and new group members."); 321 llOwnerSay("[MOTD] Waiting for group messages and new group members.");
322 } 322 }
323 link_message(integer sender, integer num, string message, key id) { 323 link_message(integer sender, integer num, string message, key id) {
324 // We only care about notifications now. 324 // We only care about notifications now.
325 if(id != "notification") 325 if(id != "notification")
326 return; 326 return;
327 327
328 // Get the group. 328 // Get the group.
329 group = wasURLUnescape( 329 group = wasURLUnescape(
330 wasKeyValueGet( 330 wasKeyValueGet(
331 "group", 331 "group",
332 message 332 message
333 ) 333 )
334 ); 334 );
335 335
336 // Retrieve the membership notification. 336 // Retrieve the membership notification.
337 if(wasKeyValueGet("type", message) == "membership" && 337 if(wasKeyValueGet("type", message) == "membership" &&
338 wasKeyValueGet("action", message) == "joined") { 338 wasKeyValueGet("action", message) == "joined") {
339 firstname = wasURLUnescape( 339 firstname = wasURLUnescape(
340 wasKeyValueGet( 340 wasKeyValueGet(
341 "firstname", 341 "firstname",
342 message 342 message
343 ) 343 )
344 ); 344 );
345 lastname = wasURLUnescape( 345 lastname = wasURLUnescape(
346 wasKeyValueGet( 346 wasKeyValueGet(
347 "lastname", 347 "lastname",
348 message 348 message
349 ) 349 )
350 ); 350 );
351 jump_state = "greet"; 351 jump_state = "greet";
352 state url; 352 state url;
353 } 353 }
354 354
355 // This script only processes group notifications. 355 // This script only processes group notifications.
356 if(wasKeyValueGet("type", message) != "group") 356 if(wasKeyValueGet("type", message) != "group")
357 return; 357 return;
358 358
359 // Get the sent message. 359 // Get the sent message.
360 data = wasURLUnescape( 360 data = wasURLUnescape(
361 wasKeyValueGet( 361 wasKeyValueGet(
362 "message", 362 "message",
363 message 363 message
364 ) 364 )
365 ); 365 );
366 366
367 // Check if this is an eggdrop command. 367 // Check if this is an eggdrop command.
368 if(llGetSubString(data, 0, 0) != 368 if(llGetSubString(data, 0, 0) !=
369 wasKeyValueGet("command", configuration)) 369 wasKeyValueGet("command", configuration))
370 return; 370 return;
371 371
372 // Check if the command matches the current module. 372 // Check if the command matches the current module.
373 list command = llParseString2List(data, [" "], []); 373 list command = llParseString2List(data, [" "], []);
374 if(llList2String(command, 0) != 374 if(llList2String(command, 0) !=
375 wasKeyValueGet("command", configuration) + "motd") 375 wasKeyValueGet("command", configuration) + "motd")
376 return; 376 return;
377 377
378 // Remove command. 378 // Remove command.
379 command = llDeleteSubList(command, 0, 0); 379 command = llDeleteSubList(command, 0, 0);
380 380
381 // Dump the rest of the message. 381 // Dump the rest of the message.
382 data = llDumpList2String(command, " "); 382 data = llDumpList2String(command, " ");
383 383
384 // Get the sent message. 384 // Get the sent message.
385 if(data == "") { 385 if(data == "") {
386 jump_state = "get"; 386 jump_state = "get";
387 state url; 387 state url;
388 } 388 }
389 389
390 jump_state = "set"; 390 jump_state = "set";
391 state url; 391 state url;
392 } 392 }
393 on_rez(integer num) { 393 on_rez(integer num) {
394 llResetScript(); 394 llResetScript();
395 } 395 }
396 changed(integer change) { 396 changed(integer change) {
397 if((change & CHANGED_INVENTORY) || 397 if((change & CHANGED_INVENTORY) ||
398 (change & CHANGED_REGION_START) || 398 (change & CHANGED_REGION_START) ||
399 (change & CHANGED_OWNER)) { 399 (change & CHANGED_OWNER)) {
400 llResetScript(); 400 llResetScript();
401 } 401 }
402 } 402 }
403 } 403 }
404 404
405 state greet { 405 state greet {
406 state_entry() { 406 state_entry() {
407 // DEBUG 407 // DEBUG
408 llOwnerSay("[MOTD] Member joined, retrieving MOTD..."); 408 llOwnerSay("[MOTD] Member joined, retrieving MOTD...");
409 llInstantMessage( 409 llInstantMessage(
410 wasKeyValueGet( 410 wasKeyValueGet(
411 "corrade", 411 "corrade",
412 configuration 412 configuration
413 ), 413 ),
414 wasKeyValueEncode( 414 wasKeyValueEncode(
415 [ 415 [
416 "command", "database", 416 "command", "database",
417 "group", wasURLEscape( 417 "group", wasURLEscape(
418 wasKeyValueGet( 418 wasKeyValueGet(
419 "group", 419 "group",
420 configuration 420 configuration
421 ) 421 )
422 ), 422 ),
423 "password", wasURLEscape( 423 "password", wasURLEscape(
424 wasKeyValueGet( 424 wasKeyValueGet(
425 "password", 425 "password",
426 configuration 426 configuration
427 ) 427 )
428 ), 428 ),
429 "SQL", wasURLEscape("SELECT data FROM \"" + 429 "SQL", wasURLEscape("SELECT data FROM \"" +
430 wasKeyValueGet("motd table", configuration) + 430 wasKeyValueGet("motd table", configuration) +
431 "\" WHERE name=:group"), 431 "\" WHERE name=:group"),
432 "data", wasURLEscape( 432 "data", wasURLEscape(
433 wasListToCSV( 433 wasListToCSV(
434 [ 434 [
435 "group", 435 "group",
436 wasURLEscape(group) 436 wasURLEscape(group)
437 ] 437 ]
438 ) 438 )
439 ), 439 ),
440 "callback", wasURLEscape(URL) 440 "callback", wasURLEscape(URL)
441 ] 441 ]
442 ) 442 )
443 ); 443 );
444 llSetTimerEvent(60); 444 llSetTimerEvent(60);
445 } 445 }
446 http_request(key id, string method, string body) { 446 http_request(key id, string method, string body) {
447 llHTTPResponse(id, 200, "OK"); 447 llHTTPResponse(id, 200, "OK");
448 llReleaseURL(URL); 448 llReleaseURL(URL);
449 if(wasKeyValueGet("command", body) != "database" || 449 if(wasKeyValueGet("command", body) != "database" ||
450 wasKeyValueGet("success", body) != "True") { 450 wasKeyValueGet("success", body) != "True") {
451 // DEBUG 451 // DEBUG
452 llOwnerSay("[MOTD] Unable retrieve from database: " + 452 llOwnerSay("[MOTD] Unable retrieve from database: " +
453 wasURLUnescape( 453 wasURLUnescape(
454 wasKeyValueGet("error", body) 454 wasKeyValueGet("error", body)
455 ) 455 )
456 ); 456 );
457 state listen_group; 457 state listen_group;
458 } 458 }
459 459
460 data = llDumpList2String( 460 data = llDumpList2String(
461 llDeleteSubList( 461 llDeleteSubList(
462 wasCSVToList( 462 wasCSVToList(
463 wasURLUnescape( 463 wasURLUnescape(
464 wasKeyValueGet("data", body) 464 wasKeyValueGet("data", body)
465 ) 465 )
466 ), 466 ),
467 0, 467 0,
468 0 468 0
469 ), 469 ),
470 "" 470 ""
471 ); 471 );
472 472
473 if(data == "") 473 if(data == "")
474 state listen_group; 474 state listen_group;
475 475
476 data = "Hello " + firstname + " " + lastname + "!" + " " + data; 476 data = "Hello " + firstname + " " + lastname + "!" + " " + data;
477 state tell; 477 state tell;
478 } 478 }
479 timer() { 479 timer() {
480 llReleaseURL(URL); 480 llReleaseURL(URL);
481 state listen_group; 481 state listen_group;
482 } 482 }
483 on_rez(integer num) { 483 on_rez(integer num) {
484 llResetScript(); 484 llResetScript();
485 } 485 }
486 changed(integer change) { 486 changed(integer change) {
487 if((change & CHANGED_INVENTORY) || 487 if((change & CHANGED_INVENTORY) ||
488 (change & CHANGED_REGION_START) || 488 (change & CHANGED_REGION_START) ||
489 (change & CHANGED_OWNER)) { 489 (change & CHANGED_OWNER)) {
490 llResetScript(); 490 llResetScript();
491 } 491 }
492 } 492 }
493 state_exit() { 493 state_exit() {
494 llSetTimerEvent(0); 494 llSetTimerEvent(0);
495 } 495 }
496 } 496 }
497 497
498 state get { 498 state get {
499 state_entry() { 499 state_entry() {
500 // DEBUG 500 // DEBUG
501 llOwnerSay("[MOTD] Retrieving from database."); 501 llOwnerSay("[MOTD] Retrieving from database.");
502 llInstantMessage( 502 llInstantMessage(
503 wasKeyValueGet( 503 wasKeyValueGet(
504 "corrade", 504 "corrade",
505 configuration 505 configuration
506 ), 506 ),
507 wasKeyValueEncode( 507 wasKeyValueEncode(
508 [ 508 [
509 "command", "database", 509 "command", "database",
510 "group", wasURLEscape( 510 "group", wasURLEscape(
511 wasKeyValueGet( 511 wasKeyValueGet(
512 "group", 512 "group",
513 configuration 513 configuration
514 ) 514 )
515 ), 515 ),
516 "password", wasURLEscape( 516 "password", wasURLEscape(
517 wasKeyValueGet( 517 wasKeyValueGet(
518 "password", 518 "password",
519 configuration 519 configuration
520 ) 520 )
521 ), 521 ),
522 "SQL", wasURLEscape("SELECT data FROM \"" + 522 "SQL", wasURLEscape("SELECT data FROM \"" +
523 wasKeyValueGet("motd table", configuration) + 523 wasKeyValueGet("motd table", configuration) +
524 "\" WHERE name=:group"), 524 "\" WHERE name=:group"),
525 "data", wasURLEscape( 525 "data", wasURLEscape(
526 wasListToCSV( 526 wasListToCSV(
527 [ 527 [
528 "group", 528 "group",
529 wasURLEscape( 529 wasURLEscape(
530 wasKeyValueGet( 530 wasKeyValueGet(
531 "group", 531 "group",
532 configuration 532 configuration
533 ) 533 )
534 ) 534 )
535 ] 535 ]
536 ) 536 )
537 ), 537 ),
538 "callback", wasURLEscape(URL) 538 "callback", wasURLEscape(URL)
539 ] 539 ]
540 ) 540 )
541 ); 541 );
542 llSetTimerEvent(60); 542 llSetTimerEvent(60);
543 } 543 }
544 http_request(key id, string method, string body) { 544 http_request(key id, string method, string body) {
545 llHTTPResponse(id, 200, "OK"); 545 llHTTPResponse(id, 200, "OK");
546 llReleaseURL(URL); 546 llReleaseURL(URL);
547 if(wasKeyValueGet("command", body) != "database" || 547 if(wasKeyValueGet("command", body) != "database" ||
548 wasKeyValueGet("success", body) != "True") { 548 wasKeyValueGet("success", body) != "True") {
549 // DEBUG 549 // DEBUG
550 llOwnerSay("[MOTD] Unable retrieve from database: " + 550 llOwnerSay("[MOTD] Unable retrieve from database: " +
551 wasURLUnescape( 551 wasURLUnescape(
552 wasKeyValueGet("error", body) 552 wasKeyValueGet("error", body)
553 ) 553 )
554 ); 554 );
555 state listen_group; 555 state listen_group;
556 } 556 }
557 557
558 data = llDumpList2String( 558 data = llDumpList2String(
559 llDeleteSubList( 559 llDeleteSubList(
560 wasCSVToList( 560 wasCSVToList(
561 wasURLUnescape( 561 wasURLUnescape(
562 wasKeyValueGet("data", body) 562 wasKeyValueGet("data", body)
563 ) 563 )
564 ), 564 ),
565 0, 565 0,
566 0 566 0
567 ), 567 ),
568 "" 568 ""
569 ); 569 );
570 570
571 if(data == "") { 571 if(data == "") {
572 data = "Sorry, no MOTD is currently set."; 572 data = "Sorry, no MOTD is currently set.";
573 state tell; 573 state tell;
574 } 574 }
575 575
576 state tell; 576 state tell;
577 } 577 }
578 timer() { 578 timer() {
579 llReleaseURL(URL); 579 llReleaseURL(URL);
580 state listen_group; 580 state listen_group;
581 } 581 }
582 on_rez(integer num) { 582 on_rez(integer num) {
583 llResetScript(); 583 llResetScript();
584 } 584 }
585 changed(integer change) { 585 changed(integer change) {
586 if((change & CHANGED_INVENTORY) || 586 if((change & CHANGED_INVENTORY) ||
587 (change & CHANGED_REGION_START) || 587 (change & CHANGED_REGION_START) ||
588 (change & CHANGED_OWNER)) { 588 (change & CHANGED_OWNER)) {
589 llResetScript(); 589 llResetScript();
590 } 590 }
591 } 591 }
592 state_exit() { 592 state_exit() {
593 llSetTimerEvent(0); 593 llSetTimerEvent(0);
594 } 594 }
595 } 595 }
596 596
597 state set { 597 state set {
598 state_entry() { 598 state_entry() {
599 // DEBUG 599 // DEBUG
600 llOwnerSay("[MOTD] Adding to database."); 600 llOwnerSay("[MOTD] Adding to database.");
601 llInstantMessage( 601 llInstantMessage(
602 wasKeyValueGet( 602 wasKeyValueGet(
603 "corrade", 603 "corrade",
604 configuration 604 configuration
605 ), 605 ),
606 wasKeyValueEncode( 606 wasKeyValueEncode(
607 [ 607 [
608 "command", "database", 608 "command", "database",
609 "group", wasURLEscape( 609 "group", wasURLEscape(
610 wasKeyValueGet( 610 wasKeyValueGet(
611 "group", 611 "group",
612 configuration 612 configuration
613 ) 613 )
614 ), 614 ),
615 "password", wasURLEscape( 615 "password", wasURLEscape(
616 wasKeyValueGet( 616 wasKeyValueGet(
617 "password", 617 "password",
618 configuration 618 configuration
619 ) 619 )
620 ), 620 ),
621 "SQL", wasURLEscape("REPLACE INTO \"" + 621 "SQL", wasURLEscape("REPLACE INTO \"" +
622 wasKeyValueGet("motd table", configuration) + 622 wasKeyValueGet("motd table", configuration) +
623 "\" (name, data) VALUES (:name, :data)"), 623 "\" (name, data) VALUES (:name, :data)"),
624 "data", wasURLEscape( 624 "data", wasURLEscape(
625 wasListToCSV( 625 wasListToCSV(
626 [ 626 [
627 "name", 627 "name",
628 wasURLEscape( 628 wasURLEscape(
629 wasKeyValueGet( 629 wasKeyValueGet(
630 "group", 630 "group",
631 configuration 631 configuration
632 ) 632 )
633 ), 633 ),
634 "data", 634 "data",
635 wasURLEscape(data) 635 wasURLEscape(data)
636 ] 636 ]
637 ) 637 )
638 ), 638 ),
639 "callback", wasURLEscape(URL) 639 "callback", wasURLEscape(URL)
640 ] 640 ]
641 ) 641 )
642 ); 642 );
643 llSetTimerEvent(60); 643 llSetTimerEvent(60);
644 } 644 }
645 http_request(key id, string method, string body) { 645 http_request(key id, string method, string body) {
646 llHTTPResponse(id, 200, "OK"); 646 llHTTPResponse(id, 200, "OK");
647 llReleaseURL(URL); 647 llReleaseURL(URL);
648 if(wasKeyValueGet("command", body) != "database" || 648 if(wasKeyValueGet("command", body) != "database" ||
649 wasKeyValueGet("success", body) != "True") { 649 wasKeyValueGet("success", body) != "True") {
650 // DEBUG 650 // DEBUG
651 llOwnerSay("[MOTD] Unable modify database: " + 651 llOwnerSay("[MOTD] Unable modify database: " +
652 wasURLUnescape( 652 wasURLUnescape(
653 wasKeyValueGet("error", body) 653 wasKeyValueGet("error", body)
654 ) 654 )
655 ); 655 );
656 state listen_group; 656 state listen_group;
657 } 657 }
658 data = "Saved"; 658 data = "Saved";
659 state tell; 659 state tell;
660 } 660 }
661 timer() { 661 timer() {
662 llReleaseURL(URL); 662 llReleaseURL(URL);
663 state listen_group; 663 state listen_group;
664 } 664 }
665 on_rez(integer num) { 665 on_rez(integer num) {
666 llResetScript(); 666 llResetScript();
667 } 667 }
668 changed(integer change) { 668 changed(integer change) {
669 if((change & CHANGED_INVENTORY) || 669 if((change & CHANGED_INVENTORY) ||
670 (change & CHANGED_REGION_START) || 670 (change & CHANGED_REGION_START) ||
671 (change & CHANGED_OWNER)) { 671 (change & CHANGED_OWNER)) {
672 llResetScript(); 672 llResetScript();
673 } 673 }
674 } 674 }
675 state_exit() { 675 state_exit() {
676 llSetTimerEvent(0); 676 llSetTimerEvent(0);
677 } 677 }
678 } 678 }
679 679
680 state tell { 680 state tell {
681 state_entry() { 681 state_entry() {
682 // DEBUG 682 // DEBUG
683 llOwnerSay("[MOTD] Sending to group."); 683 llOwnerSay("[MOTD] Sending to group.");
684 llInstantMessage( 684 llInstantMessage(
685 wasKeyValueGet( 685 wasKeyValueGet(
686 "corrade", 686 "corrade",
687 configuration 687 configuration
688 ), 688 ),
689 wasKeyValueEncode( 689 wasKeyValueEncode(
690 [ 690 [
691 "command", "tell", 691 "command", "tell",
692 "group", wasURLEscape( 692 "group", wasURLEscape(
693 wasKeyValueGet( 693 wasKeyValueGet(
694 "group", 694 "group",
695 configuration 695 configuration
696 ) 696 )
697 ), 697 ),
698 "password", wasURLEscape( 698 "password", wasURLEscape(
699 wasKeyValueGet( 699 wasKeyValueGet(
700 "password", 700 "password",
701 configuration 701 configuration
702 ) 702 )
703 ), 703 ),
704 "entity", "group", 704 "entity", "group",
705 "message", wasURLEscape(data) 705 "message", wasURLEscape(data)
706 ] 706 ]
707 ) 707 )
708 ); 708 );
709 state listen_group; 709 state listen_group;
710 } 710 }
711 } 711 }
712   712