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

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 29 Rev 30
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2018 - License: CC BY 2.0 // 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: 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 "";
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(llList2ListStrided(a, 0, -1, 2), [ k ]);
17 if(i != -1) return llList2String(a, 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 = [];
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: 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 {
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: 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 = "";
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: 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 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 ) + 1;
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 (wasKeyValueGet("type", message) == "group" &&
-   416 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   417 wasKeyValueGet("group", configuration)))
415 return; 418 return;
416 419
417 // Get the message sender. 420 // Get the message sender.
418 firstname = wasURLUnescape( 421 firstname = wasURLUnescape(
419 wasKeyValueGet( 422 wasKeyValueGet(
420 "firstname", 423 "firstname",
421 message 424 message
422 ) 425 )
423 ); 426 );
424 427
425 lastname = wasURLUnescape( 428 lastname = wasURLUnescape(
426 wasKeyValueGet( 429 wasKeyValueGet(
427 "lastname", 430 "lastname",
428 message 431 message
429 ) 432 )
430 ); 433 );
431 434
432 // Get the sent message. 435 // Get the sent message.
433 data = wasURLUnescape( 436 data = wasURLUnescape(
434 wasKeyValueGet( 437 wasKeyValueGet(
435 "message", 438 "message",
436 message 439 message
437 ) 440 )
438 ); 441 );
439 442
440 // Check if this is an eggdrop command. 443 // Check if this is an eggdrop command.
441 if(llGetSubString(data, 0, 0) != 444 if(llGetSubString(data, 0, 0) !=
442 wasKeyValueGet("command", configuration)) 445 wasKeyValueGet("command", configuration))
443 return; 446 return;
444 447
445 // Check if the command matches the current module. 448 // Check if the command matches the current module.
446 list command = llParseString2List(data, [" "], []); 449 list command = llParseString2List(data, [" "], []);
447 if(llList2String(command, 0) != 450 if(llList2String(command, 0) !=
448 wasKeyValueGet("command", configuration) + "joke") 451 wasKeyValueGet("command", configuration) + "joke")
449 return; 452 return;
450 453
451 // Remove command. 454 // Remove command.
452 command = llDeleteSubList(command, 0, 0); 455 command = llDeleteSubList(command, 0, 0);
453 456
454 // Remove action. 457 // Remove action.
455 string action = llList2String(command, 0); 458 string action = llList2String(command, 0);
456 // Jump to the "add" state for adding 459 // Jump to the "add" state for adding
457 if(action == "add") { 460 if(action == "add") {
458 command = llDeleteSubList(command, 0, 0); 461 command = llDeleteSubList(command, 0, 0);
459 data = llDumpList2String(command, " "); 462 data = llDumpList2String(command, " ");
460 if(data == "") { 463 if(data == "") {
461 data = "The joke's too short to be funny."; 464 data = "The joke's too short to be funny.";
462 state tell; 465 state tell;
463 } 466 }
464 jump_state = "add"; 467 jump_state = "add";
465 state url; 468 state url;
466 } 469 }
467 470
468 // Jump to the "remove" state for removing 471 // Jump to the "remove" state for removing
469 if(action == "remove") { 472 if(action == "remove") {
470 command = llDeleteSubList(command, 0, 0); 473 command = llDeleteSubList(command, 0, 0);
471 data = llDumpList2String(command, " "); 474 data = llDumpList2String(command, " ");
472 if((integer)data == 0) { 475 if((integer)data == 0) {
473 data = "Which one though? Please provide a joke id."; 476 data = "Which one though? Please provide a joke id.";
474 state tell; 477 state tell;
475 } 478 }
476 jump_state = "remove"; 479 jump_state = "remove";
477 state url; 480 state url;
478 } 481 }
479 482
480 data = llDumpList2String(command, " "); 483 data = llDumpList2String(command, " ");
481 if((integer)data == 0) 484 if((integer)data <= 0)
482 data = ""; 485 data = "";
483 jump_state = "get"; 486 jump_state = "get";
484 state url; 487 state url;
485 } 488 }
486 on_rez(integer num) { 489 on_rez(integer num) {
487 llResetScript(); 490 llResetScript();
488 } 491 }
489 changed(integer change) { 492 changed(integer change) {
490 if((change & CHANGED_INVENTORY) || 493 if((change & CHANGED_INVENTORY) ||
491 (change & CHANGED_REGION_START) || 494 (change & CHANGED_REGION_START) ||
492 (change & CHANGED_OWNER)) { 495 (change & CHANGED_OWNER)) {
493 llResetScript(); 496 llResetScript();
494 } 497 }
495 } 498 }
496 } 499 }
497 500
498 state get { 501 state get {
499 state_entry() { 502 state_entry() {
500 // DEBUG 503 // DEBUG
501 llOwnerSay("[Joke] Retrieving from database."); 504 llOwnerSay("[Joke] Retrieving from database.");
502 if(data == "") { 505 if(data == "") {
503 llInstantMessage( 506 llInstantMessage(
504 wasKeyValueGet( 507 wasKeyValueGet(
505 "corrade", 508 "corrade",
506 configuration 509 configuration
507 ), 510 ),
508 wasKeyValueEncode( 511 wasKeyValueEncode(
509 [ 512 [
510 "command", "database", 513 "command", "database",
511 "group", wasURLEscape( 514 "group", wasURLEscape(
512 wasKeyValueGet( 515 wasKeyValueGet(
513 "group", 516 "group",
514 configuration 517 configuration
515 ) 518 )
516 ), 519 ),
517 "password", wasURLEscape( 520 "password", wasURLEscape(
518 wasKeyValueGet( 521 wasKeyValueGet(
519 "password", 522 "password",
520 configuration 523 configuration
521 ) 524 )
522 ), 525 ),
523 "SQL", wasURLEscape("SELECT * FROM \"" + 526 "SQL", wasURLEscape("SELECT * FROM \"" +
524 wasKeyValueGet("joke table", configuration) + 527 wasKeyValueGet("joke table", configuration) +
525 "\" WHERE name=:group LIMIT 1 OFFSET :id"), 528 "\" WHERE name=:group LIMIT 1 OFFSET :id"),
526 "data", wasURLEscape( 529 "data", wasURLEscape(
527 wasListToCSV( 530 wasListToCSV(
528 [ 531 [
529 "group", 532 "group",
530 wasURLEscape( 533 wasURLEscape(
531 wasKeyValueGet( 534 wasKeyValueGet(
532 "group", 535 "group",
533 configuration 536 configuration
534 ) 537 )
535 ), 538 ),
536 "id", 539 "id",
537 (string)( 540 (string)(
538 (integer)llFrand( 541 (integer)llFrand(
539 joke_counter 542 joke_counter
540 ) + 1 543 ) + 1
541 ) 544 )
542 ] 545 ]
543 ) 546 )
544 ), 547 ),
545 "callback", wasURLEscape(URL) 548 "callback", wasURLEscape(URL)
546 ] 549 ]
547 ) 550 )
548 ); 551 );
549 llSetTimerEvent(60); 552 llSetTimerEvent(60);
550 return; 553 return;
551 } 554 }
552 llInstantMessage( 555 llInstantMessage(
553 wasKeyValueGet( 556 wasKeyValueGet(
554 "corrade", 557 "corrade",
555 configuration 558 configuration
556 ), 559 ),
557 wasKeyValueEncode( 560 wasKeyValueEncode(
558 [ 561 [
559 "command", "database", 562 "command", "database",
560 "group", wasURLEscape( 563 "group", wasURLEscape(
561 wasKeyValueGet( 564 wasKeyValueGet(
562 "group", 565 "group",
563 configuration 566 configuration
564 ) 567 )
565 ), 568 ),
566 "password", wasURLEscape( 569 "password", wasURLEscape(
567 wasKeyValueGet( 570 wasKeyValueGet(
568 "password", 571 "password",
569 configuration 572 configuration
570 ) 573 )
571 ), 574 ),
572 "SQL", wasURLEscape("SELECT * FROM \"" + 575 "SQL", wasURLEscape("SELECT * FROM \"" +
573 wasKeyValueGet("joke table", configuration) + 576 wasKeyValueGet("joke table", configuration) +
574 "\" WHERE name=:group AND id=:id"), 577 "\" WHERE name=:group AND id=:id"),
575 "data", wasURLEscape( 578 "data", wasURLEscape(
576 wasListToCSV( 579 wasListToCSV(
577 [ 580 [
578 "group", 581 "group",
579 wasURLEscape( 582 wasURLEscape(
580 wasKeyValueGet( 583 wasKeyValueGet(
581 "group", 584 "group",
582 configuration 585 configuration
583 ) 586 )
584 ), 587 ),
585 "id", 588 "id",
586 data 589 data
587 ] 590 ]
588 ) 591 )
589 ), 592 ),
590 "callback", wasURLEscape(URL) 593 "callback", wasURLEscape(URL)
591 ] 594 ]
592 ) 595 )
593 ); 596 );
594 llSetTimerEvent(60); 597 llSetTimerEvent(60);
595 } 598 }
596 http_request(key id, string method, string body) { 599 http_request(key id, string method, string body) {
597 llHTTPResponse(id, 200, "OK"); 600 llHTTPResponse(id, 200, "OK");
598 llReleaseURL(URL); 601 llReleaseURL(URL);
599 if(wasKeyValueGet("command", body) != "database" || 602 if(wasKeyValueGet("command", body) != "database" ||
600 wasKeyValueGet("success", body) != "True") { 603 wasKeyValueGet("success", body) != "True") {
601 // DEBUG 604 // DEBUG
602 llOwnerSay("[Joke] Unable retrieve from database: " + 605 llOwnerSay("[Joke] Unable retrieve from database: " +
603 wasURLUnescape( 606 wasURLUnescape(
604 wasKeyValueGet("error", body) 607 wasKeyValueGet("error", body)
605 ) 608 )
606 ); 609 );
607 state listen_group; 610 state listen_group;
608 } 611 }
609 612
610 list result = wasCSVToList( 613 list result = wasCSVToList(
611 wasURLUnescape( 614 wasURLUnescape(
612 wasKeyValueGet("data", body) 615 wasKeyValueGet("data", body)
613 ) 616 )
614 ); 617 );
615 618
616 if(llGetListLength(result) != 10) { 619 if(llGetListLength(result) != 10) {
617 data = "No joke found. . ."; 620 data = "No joke found. . .";
618 state tell; 621 state tell;
619 } 622 }
620 623
621 data = llList2String( 624 data = llList2String(
622 result, 625 result,
623 llListFindList(result, ["data"]) + 1 626 llListFindList(result, ["data"]) + 1
624 ); 627 );
625 628
626 string firstname = llList2String( 629 string firstname = llList2String(
627 result, 630 result,
628 llListFindList(result, ["firstname"]) + 1 631 llListFindList(result, ["firstname"]) + 1
629 ); 632 );
630 633
631 string lastname = llList2String( 634 string lastname = llList2String(
632 result, 635 result,
633 llListFindList(result, ["lastname"]) + 1 636 llListFindList(result, ["lastname"]) + 1
634 ); 637 );
635 638
636 string id = llList2String( 639 string id = llList2String(
637 result, 640 result,
638 llListFindList(result, ["id"]) + 1 641 llListFindList(result, ["id"]) + 1
639 ); 642 );
640 643
641 // Build data to be sent. 644 // Build data to be sent.
642 data += " " + "[" + firstname + " " + lastname + "/" + id + "]"; 645 data += " " + "[" + firstname + " " + lastname + "/" + id + "]";
643 646
644 state tell; 647 state tell;
645 } 648 }
646 timer() { 649 timer() {
647 llReleaseURL(URL); 650 llReleaseURL(URL);
648 state listen_group; 651 state listen_group;
649 } 652 }
650 on_rez(integer num) { 653 on_rez(integer num) {
651 llResetScript(); 654 llResetScript();
652 } 655 }
653 changed(integer change) { 656 changed(integer change) {
654 if((change & CHANGED_INVENTORY) || 657 if((change & CHANGED_INVENTORY) ||
655 (change & CHANGED_REGION_START) || 658 (change & CHANGED_REGION_START) ||
656 (change & CHANGED_OWNER)) { 659 (change & CHANGED_OWNER)) {
657 llResetScript(); 660 llResetScript();
658 } 661 }
659 } 662 }
660 state_exit() { 663 state_exit() {
661 llSetTimerEvent(0); 664 llSetTimerEvent(0);
662 } 665 }
663 } 666 }
664 667
665 state add { 668 state add {
666 state_entry() { 669 state_entry() {
667 // DEBUG 670 // DEBUG
668 llOwnerSay("[Joke] Adding to database."); 671 llOwnerSay("[Joke] Adding to database: " + (string)(joke_counter + 1));
669 llInstantMessage( 672 llInstantMessage(
670 wasKeyValueGet( 673 wasKeyValueGet(
671 "corrade", 674 "corrade",
672 configuration 675 configuration
673 ), 676 ),
674 wasKeyValueEncode( 677 wasKeyValueEncode(
675 [ 678 [
676 "command", "database", 679 "command", "database",
677 "group", wasURLEscape( 680 "group", wasURLEscape(
678 wasKeyValueGet( 681 wasKeyValueGet(
679 "group", 682 "group",
680 configuration 683 configuration
681 ) 684 )
682 ), 685 ),
683 "password", wasURLEscape( 686 "password", wasURLEscape(
684 wasKeyValueGet( 687 wasKeyValueGet(
685 "password", 688 "password",
686 configuration 689 configuration
687 ) 690 )
688 ), 691 ),
689 "SQL", wasURLEscape("INSERT INTO \"" + 692 "SQL", wasURLEscape("INSERT INTO \"" +
690 wasKeyValueGet("joke table", configuration) + 693 wasKeyValueGet("joke table", configuration) +
691 "\" (name, data, firstname, lastname, id) VALUES (:name, :data, :firstname, :lastname, :id)"), 694 "\" (name, data, firstname, lastname, id) VALUES (:name, :data, :firstname, :lastname, :id)"),
692 "data", wasURLEscape( 695 "data", wasURLEscape(
693 wasListToCSV( 696 wasListToCSV(
694 [ 697 [
695 "name", 698 "name",
696 wasURLEscape( 699 wasURLEscape(
697 wasKeyValueGet( 700 wasKeyValueGet(
698 "group", 701 "group",
699 configuration 702 configuration
700 ) 703 )
701 ), 704 ),
702 "data", 705 "data",
703 wasURLEscape(data), 706 wasURLEscape(data),
704 "firstname", 707 "firstname",
705 wasURLEscape(firstname), 708 wasURLEscape(firstname),
706 "lastname", 709 "lastname",
707 wasURLEscape(lastname), 710 wasURLEscape(lastname),
708 "id", 711 "id",
709 (string)(joke_counter + 1) 712 (string)(joke_counter + 1)
710 ] 713 ]
711 ) 714 )
712 ), 715 ),
713 "callback", wasURLEscape(URL) 716 "callback", wasURLEscape(URL)
714 ] 717 ]
715 ) 718 )
716 ); 719 );
717 llSetTimerEvent(60); 720 llSetTimerEvent(60);
718 } 721 }
719 http_request(key id, string method, string body) { 722 http_request(key id, string method, string body) {
720 llHTTPResponse(id, 200, "OK"); 723 llHTTPResponse(id, 200, "OK");
721 llReleaseURL(URL); 724 llReleaseURL(URL);
722 if(wasKeyValueGet("command", body) != "database" || 725 if(wasKeyValueGet("command", body) != "database" ||
723 wasKeyValueGet("success", body) != "True") { 726 wasKeyValueGet("success", body) != "True") {
724 // DEBUG 727 // DEBUG
725 llOwnerSay("[Joke] Unable modify database: " + 728 llOwnerSay("[Joke] Unable modify database: " +
726 wasURLUnescape( 729 wasURLUnescape(
727 wasKeyValueGet("error", body) 730 wasKeyValueGet("data", body)
728 ) 731 )
729 ); 732 );
730 state listen_group; 733 state listen_group;
731 } 734 }
732 ++joke_counter; 735 ++joke_counter;
733 data = "Joke " + (string)joke_counter + " has been stored."; 736 data = "Joke " + (string)joke_counter + " has been stored.";
734 state tell; 737 state tell;
735 } 738 }
736 timer() { 739 timer() {
737 llReleaseURL(URL); 740 llReleaseURL(URL);
738 state listen_group; 741 state listen_group;
739 } 742 }
740 on_rez(integer num) { 743 on_rez(integer num) {
741 llResetScript(); 744 llResetScript();
742 } 745 }
743 changed(integer change) { 746 changed(integer change) {
744 if((change & CHANGED_INVENTORY) || 747 if((change & CHANGED_INVENTORY) ||
745 (change & CHANGED_REGION_START) || 748 (change & CHANGED_REGION_START) ||
746 (change & CHANGED_OWNER)) { 749 (change & CHANGED_OWNER)) {
747 llResetScript(); 750 llResetScript();
748 } 751 }
749 } 752 }
750 state_exit() { 753 state_exit() {
751 llSetTimerEvent(0); 754 llSetTimerEvent(0);
752 } 755 }
753 } 756 }
754   757  
755 state remove { 758 state remove {
756 state_entry() { 759 state_entry() {
757 // DEBUG 760 // DEBUG
758 llOwnerSay("[Joke] Removing from database."); 761 llOwnerSay("[Joke] Removing from database.");
759 llInstantMessage( 762 llInstantMessage(
760 wasKeyValueGet( 763 wasKeyValueGet(
761 "corrade", 764 "corrade",
762 configuration 765 configuration
763 ), 766 ),
764 wasKeyValueEncode( 767 wasKeyValueEncode(
765 [ 768 [
766 "command", "database", 769 "command", "database",
767 "group", wasURLEscape( 770 "group", wasURLEscape(
768 wasKeyValueGet( 771 wasKeyValueGet(
769 "group", 772 "group",
770 configuration 773 configuration
771 ) 774 )
772 ), 775 ),
773 "password", wasURLEscape( 776 "password", wasURLEscape(
774 wasKeyValueGet( 777 wasKeyValueGet(
775 "password", 778 "password",
776 configuration 779 configuration
777 ) 780 )
778 ), 781 ),
779 "SQL", wasURLEscape("DELETE FROM \"" + 782 "SQL", wasURLEscape("DELETE FROM \"" +
780 wasKeyValueGet("joke table", configuration) + 783 wasKeyValueGet("joke table", configuration) +
781 "\" WHERE name=:name AND id=:id"), 784 "\" WHERE name=:name AND id=:id"),
782 "data", wasURLEscape( 785 "data", wasURLEscape(
783 wasListToCSV( 786 wasListToCSV(
784 [ 787 [
785 "name", 788 "name",
786 wasURLEscape( 789 wasURLEscape(
787 wasKeyValueGet( 790 wasKeyValueGet(
788 "group", 791 "group",
789 configuration 792 configuration
790 ) 793 )
791 ), 794 ),
792 "id", 795 "id",
793 data 796 data
794 ] 797 ]
795 ) 798 )
796 ), 799 ),
797 "callback", wasURLEscape(URL) 800 "callback", wasURLEscape(URL)
798 ] 801 ]
799 ) 802 )
800 ); 803 );
801 llSetTimerEvent(60); 804 llSetTimerEvent(60);
802 } 805 }
803 http_request(key id, string method, string body) { 806 http_request(key id, string method, string body) {
804 llHTTPResponse(id, 200, "OK"); 807 llHTTPResponse(id, 200, "OK");
805 llReleaseURL(URL); 808 llReleaseURL(URL);
806 if(wasKeyValueGet("command", body) != "database" || 809 if(wasKeyValueGet("command", body) != "database" ||
807 wasKeyValueGet("success", body) != "True") { 810 wasKeyValueGet("success", body) != "True") {
808 // DEBUG 811 // DEBUG
809 llOwnerSay("[Joke] Unable modify database: " + 812 llOwnerSay("[Joke] Unable modify database: " +
810 wasURLUnescape( 813 wasURLUnescape(
811 wasKeyValueGet("error", body) 814 wasKeyValueGet("error", body)
812 ) 815 )
813 ); 816 );
814 state listen_group; 817 state listen_group;
815 } 818 }
816 --joke_counter; 819 --joke_counter;
817 data = "Joke " + data + " has been removed."; 820 data = "Joke " + data + " has been removed.";
818 state tell; 821 state tell;
819 } 822 }
820 timer() { 823 timer() {
821 llReleaseURL(URL); 824 llReleaseURL(URL);
822 state listen_group; 825 state listen_group;
823 } 826 }
824 on_rez(integer num) { 827 on_rez(integer num) {
825 llResetScript(); 828 llResetScript();
826 } 829 }
827 changed(integer change) { 830 changed(integer change) {
828 if((change & CHANGED_INVENTORY) || 831 if((change & CHANGED_INVENTORY) ||
829 (change & CHANGED_REGION_START) || 832 (change & CHANGED_REGION_START) ||
830 (change & CHANGED_OWNER)) { 833 (change & CHANGED_OWNER)) {
831 llResetScript(); 834 llResetScript();
832 } 835 }
833 } 836 }
834 state_exit() { 837 state_exit() {
835 llSetTimerEvent(0); 838 llSetTimerEvent(0);
836 } 839 }
837 } 840 }
838 841
839 state tell { 842 state tell {
840 state_entry() { 843 state_entry() {
841 // DEBUG 844 // DEBUG
842 llOwnerSay("[Joke] Sending to group."); 845 llOwnerSay("[Joke] Sending to group.");
843 llInstantMessage( 846 llInstantMessage(
844 wasKeyValueGet( 847 wasKeyValueGet(
845 "corrade", 848 "corrade",
846 configuration 849 configuration
847 ), 850 ),
848 wasKeyValueEncode( 851 wasKeyValueEncode(
849 [ 852 [
850 "command", "tell", 853 "command", "tell",
851 "group", wasURLEscape( 854 "group", wasURLEscape(
852 wasKeyValueGet( 855 wasKeyValueGet(
853 "group", 856 "group",
854 configuration 857 configuration
855 ) 858 )
856 ), 859 ),
857 "password", wasURLEscape( 860 "password", wasURLEscape(
858 wasKeyValueGet( 861 wasKeyValueGet(
859 "password", 862 "password",
860 configuration 863 configuration
861 ) 864 )
862 ), 865 ),
863 "entity", "group", 866 "entity", "group",
864 "message", wasURLEscape(data) 867 "message", wasURLEscape(data)
865 ] 868 ]
866 ) 869 )
867 ); 870 );
868 state listen_group; 871 state listen_group;
869 } 872 }
870 } 873 }
871   874