corrade-lsl-templates – Diff between revs 19 and 20

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