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

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