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

Subversion Repositories:
Rev:
Only display areas with differencesRegard whitespace
Rev 29 Rev 41
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // A wiki module that can memorize strings and recall them by path. 5 // A wiki module that can memorize strings and recall them by path.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
8   8  
9 /////////////////////////////////////////////////////////////////////////// 9 ///////////////////////////////////////////////////////////////////////////
10 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 // 10 // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 //
11 /////////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////////
12 integer wasIsAlNum(string a) { 12 integer wasIsAlNum(string a) {
13 if(a == "") return FALSE; 13 if(a == "") return FALSE;
14 integer x = llBase64ToInteger("AAAA" + 14 integer x = llBase64ToInteger("AAAA" +
15 llStringToBase64(llGetSubString(a, 0, 0))); 15 llStringToBase64(llGetSubString(a, 0, 0)));
16 return (x >= 65 && x <= 90) || (x >= 97 && x <= 122) || 16 return (x >= 65 && x <= 90) || (x >= 97 && x <= 122) ||
17 (x >= 48 && x <= 57); 17 (x >= 48 && x <= 57);
18 } 18 }
-   19  
19 /////////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////////
20 // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // 21 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
21 /////////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////////
22 string wasKeyValueGet(string k, string data) { 23 string wasKeyValueGet(string k, string data) {
23 if(llStringLength(data) == 0) return ""; 24 if(llStringLength(data) == 0) return "";
24 if(llStringLength(k) == 0) return ""; 25 if(llStringLength(k) == 0) return "";
25 list a = llParseString2List(data, ["&", "="], []); 26 list a = llParseStringKeepNulls(data, ["&", "="], []);
26 integer i = llListFindList(a, [ k ]); 27 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
27 if(i != -1) return llList2String(a, i+1); 28 if(i != -1) return llList2String(a, 2*i+1);
28 return ""; 29 return "";
29 } 30 }
30 31
31 /////////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////////
32 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 33 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
33 /////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////
34 string wasKeyValueEncode(list data) { 35 string wasKeyValueEncode(list data) {
35 list k = llList2ListStrided(data, 0, -1, 2); 36 list k = llList2ListStrided(data, 0, -1, 2);
36 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); 37 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
37 data = []; 38 data = [];
38 do { 39 do {
39 data += llList2String(k, 0) + "=" + llList2String(v, 0); 40 data += llList2String(k, 0) + "=" + llList2String(v, 0);
40 k = llDeleteSubList(k, 0, 0); 41 k = llDeleteSubList(k, 0, 0);
41 v = llDeleteSubList(v, 0, 0); 42 v = llDeleteSubList(v, 0, 0);
42 } while(llGetListLength(k) != 0); 43 } while(llGetListLength(k) != 0);
43 return llDumpList2String(data, "&"); 44 return llDumpList2String(data, "&");
44 } 45 }
45   46  
46 /////////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////////
47 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 48 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
48 /////////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////////
49 // escapes a string in conformance with RFC1738 50 // escapes a string in conformance with RFC1738
50 string wasURLEscape(string i) { 51 string wasURLEscape(string i) {
51 string o = ""; 52 string o = "";
52 do { 53 do {
53 string c = llGetSubString(i, 0, 0); 54 string c = llGetSubString(i, 0, 0);
54 i = llDeleteSubString(i, 0, 0); 55 i = llDeleteSubString(i, 0, 0);
55 if(c == "") jump continue; 56 if(c == "") jump continue;
56 if(c == " ") { 57 if(c == " ") {
57 o += "+"; 58 o += "+";
58 jump continue; 59 jump continue;
59 } 60 }
60 if(c == "\n") { 61 if(c == "\n") {
61 o += "%0D" + llEscapeURL(c); 62 o += "%0D" + llEscapeURL(c);
62 jump continue; 63 jump continue;
63 } 64 }
64 o += llEscapeURL(c); 65 o += llEscapeURL(c);
65 @continue; 66 @continue;
66 } while(i != ""); 67 } while(i != "");
67 return o; 68 return o;
68 } 69 }
69   70  
70 /////////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////////
71 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 72 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
72 /////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////
73 list wasCSVToList(string csv) { 74 list wasCSVToList(string csv) {
74 list l = []; 75 list l = [];
75 list s = []; 76 list s = [];
76 string m = ""; 77 string m = "";
77 do { 78 do {
78 string a = llGetSubString(csv, 0, 0); 79 string a = llGetSubString(csv, 0, 0);
79 csv = llDeleteSubString(csv, 0, 0); 80 csv = llDeleteSubString(csv, 0, 0);
80 if(a == ",") { 81 if(a == ",") {
81 if(llList2String(s, -1) != "\"") { 82 if(llList2String(s, -1) != "\"") {
82 l += m; 83 l += m;
83 m = ""; 84 m = "";
84 jump continue; 85 jump continue;
85 } 86 }
86 m += a; 87 m += a;
87 jump continue; 88 jump continue;
88 } 89 }
89 if(a == "\"" && llGetSubString(csv, 0, 0) == a) { 90 if(a == "\"" && llGetSubString(csv, 0, 0) == a) {
90 m += a; 91 m += a;
91 csv = llDeleteSubString(csv, 0, 0); 92 csv = llDeleteSubString(csv, 0, 0);
92 jump continue; 93 jump continue;
93 } 94 }
94 if(a == "\"") { 95 if(a == "\"") {
95 if(llList2String(s, -1) != a) { 96 if(llList2String(s, -1) != a) {
96 s += a; 97 s += a;
97 jump continue; 98 jump continue;
98 } 99 }
99 s = llDeleteSubList(s, -1, -1); 100 s = llDeleteSubList(s, -1, -1);
100 jump continue; 101 jump continue;
101 } 102 }
102 m += a; 103 m += a;
103 @continue; 104 @continue;
104 } while(csv != ""); 105 } while(csv != "");
105 // postcondition: length(s) = 0 106 // postcondition: length(s) = 0
106 return l + m; 107 return l + m;
107 } 108 }
108   109  
109 /////////////////////////////////////////////////////////////////////////// 110 ///////////////////////////////////////////////////////////////////////////
110 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 111 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
111 /////////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////
112 string wasListToCSV(list l) { 113 string wasListToCSV(list l) {
113 list v = []; 114 list v = [];
114 do { 115 do {
115 string a = llDumpList2String( 116 string a = llDumpList2String(
116 llParseStringKeepNulls( 117 llParseStringKeepNulls(
117 llList2String( 118 llList2String(
118 l, 119 l,
119 0 120 0
120 ), 121 ),
121 ["\""], 122 ["\""],
122 [] 123 []
123 ), 124 ),
124 "\"\"" 125 "\"\""
125 ); 126 );
126 if(llParseStringKeepNulls( 127 if(llParseStringKeepNulls(
127 a, 128 a,
128 [" ", ",", "\n", "\""], [] 129 [" ", ",", "\n", "\""], []
129 ) != 130 ) !=
130 (list) a 131 (list) a
131 ) a = "\"" + a + "\""; 132 ) a = "\"" + a + "\"";
132 v += a; 133 v += a;
133 l = llDeleteSubList(l, 0, 0); 134 l = llDeleteSubList(l, 0, 0);
134 } while(l != []); 135 } while(l != []);
135 return llDumpList2String(v, ","); 136 return llDumpList2String(v, ",");
136 } 137 }
137   138  
138 /////////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////////
139 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 140 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
140 /////////////////////////////////////////////////////////////////////////// 141 ///////////////////////////////////////////////////////////////////////////
141 // unescapes a string in conformance with RFC1738 142 // unescapes a string in conformance with RFC1738
142 string wasURLUnescape(string i) { 143 string wasURLUnescape(string i) {
143 return llUnescapeURL( 144 return llUnescapeURL(
144 llDumpList2String( 145 llDumpList2String(
145 llParseString2List( 146 llParseString2List(
146 llDumpList2String( 147 llDumpList2String(
147 llParseString2List( 148 llParseString2List(
148 i, 149 i,
149 ["+"], 150 ["+"],
150 [] 151 []
151 ), 152 ),
152 " " 153 " "
153 ), 154 ),
154 ["%0D%0A"], 155 ["%0D%0A"],
155 [] 156 []
156 ), 157 ),
157 "\n" 158 "\n"
158 ) 159 )
159 ); 160 );
160 } 161 }
161   162  
162 // configuration data 163 // configuration data
163 string configuration = ""; 164 string configuration = "";
164 // callback URL 165 // callback URL
165 string URL = ""; 166 string URL = "";
166 // store message over state. 167 // store message over state.
167 string path = ""; 168 string path = "";
168 string data = ""; 169 string data = "";
169 string action = ""; 170 string action = "";
170 string statement = ""; 171 string statement = "";
171 string parameters = ""; 172 string parameters = "";
172   173  
173 default { 174 default {
174 state_entry() { 175 state_entry() {
175 llOwnerSay("[Wiki] Starting..."); 176 llOwnerSay("[Wiki] Starting...");
176 llSetTimerEvent(10); 177 llSetTimerEvent(10);
177 } 178 }
178 link_message(integer sender, integer num, string message, key id) { 179 link_message(integer sender, integer num, string message, key id) {
179 if(id != "configuration") return; 180 if(id != "configuration") return;
180 llOwnerSay("[Wiki] Got configuration..."); 181 llOwnerSay("[Wiki] Got configuration...");
181 configuration = message; 182 configuration = message;
182 action = "create"; 183 action = "create";
183 state url; 184 state url;
184 } 185 }
185 timer() { 186 timer() {
186 llOwnerSay("[Wiki] Requesting configuration..."); 187 llOwnerSay("[Wiki] Requesting configuration...");
187 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 188 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
188 } 189 }
189 on_rez(integer num) { 190 on_rez(integer num) {
190 llResetScript(); 191 llResetScript();
191 } 192 }
192 changed(integer change) { 193 changed(integer change) {
193 if((change & CHANGED_INVENTORY) || 194 if((change & CHANGED_INVENTORY) ||
194 (change & CHANGED_REGION_START) || 195 (change & CHANGED_REGION_START) ||
195 (change & CHANGED_OWNER)) { 196 (change & CHANGED_OWNER)) {
196 llResetScript(); 197 llResetScript();
197 } 198 }
198 } 199 }
199 state_exit() { 200 state_exit() {
200 llSetTimerEvent(0); 201 llSetTimerEvent(0);
201 } 202 }
202 } 203 }
203   204  
204 state url { 205 state url {
205 state_entry() { 206 state_entry() {
206 // DEBUG 207 // DEBUG
207 llOwnerSay("[Wiki] Requesting URL..."); 208 llOwnerSay("[Wiki] Requesting URL...");
208 llRequestURL(); 209 llRequestURL();
209 } 210 }
210 http_request(key id, string method, string body) { 211 http_request(key id, string method, string body) {
211 if(method != URL_REQUEST_GRANTED) return; 212 if(method != URL_REQUEST_GRANTED) return;
212 URL = body; 213 URL = body;
213 // DEBUG 214 // DEBUG
214 llOwnerSay("[Wiki] Got URL."); 215 llOwnerSay("[Wiki] Got URL.");
215 216
216 if(action == "create") { 217 if(action == "create") {
217 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + 218 statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
218 wasKeyValueGet("wiki table", configuration) + 219 wasKeyValueGet("wiki table", configuration) +
219 "\" (path text unique collate nocase, data text)"); 220 "\" (path text unique collate nocase, data text)");
220 state query; 221 state query;
221 } 222 }
222 223
223 if(action == "get") { 224 if(action == "get") {
224 statement = wasURLEscape("SELECT data FROM \"" + 225 statement = wasURLEscape("SELECT data FROM \"" +
225 wasKeyValueGet("wiki table", configuration) + 226 wasKeyValueGet("wiki table", configuration) +
226 "\" WHERE path=:path"); 227 "\" WHERE path=:path");
227 parameters = wasURLEscape( 228 parameters = wasURLEscape(
228 wasListToCSV( 229 wasListToCSV(
229 [ 230 [
230 "path", 231 "path",
231 wasURLEscape(path) 232 wasURLEscape(path)
232 ] 233 ]
233 ) 234 )
234 ); 235 );
235 state query; 236 state query;
236 } 237 }
237 238
238 if(action == "set") { 239 if(action == "set") {
239 if(data == "") { 240 if(data == "") {
240 statement = wasURLEscape("DELETE FROM \"" + 241 statement = wasURLEscape("DELETE FROM \"" +
241 wasKeyValueGet("wiki table", configuration) + 242 wasKeyValueGet("wiki table", configuration) +
242 "\" WHERE path=:path"); 243 "\" WHERE path=:path");
243 parameters = wasURLEscape( 244 parameters = wasURLEscape(
244 wasListToCSV( 245 wasListToCSV(
245 [ 246 [
246 "path", 247 "path",
247 wasURLEscape(path) 248 wasURLEscape(path)
248 ] 249 ]
249 ) 250 )
250 ); 251 );
251 state query; 252 state query;
252 } 253 }
253 statement = wasURLEscape("REPLACE INTO \"" + 254 statement = wasURLEscape("REPLACE INTO \"" +
254 wasKeyValueGet("wiki table", configuration) + 255 wasKeyValueGet("wiki table", configuration) +
255 "\" (path, data) VALUES (:path, :data)"); 256 "\" (path, data) VALUES (:path, :data)");
256 parameters = wasURLEscape( 257 parameters = wasURLEscape(
257 wasListToCSV( 258 wasListToCSV(
258 [ 259 [
259 "path", 260 "path",
260 wasURLEscape(path), 261 wasURLEscape(path),
261 "data", 262 "data",
262 wasURLEscape(data) 263 wasURLEscape(data)
263 ] 264 ]
264 ) 265 )
265 ); 266 );
266 state query; 267 state query;
267 } 268 }
268 269
269 if(action == "dir") { 270 if(action == "dir") {
270 if(path == "/") { 271 if(path == "/") {
271 path = ""; 272 path = "";
272 statement = wasURLEscape( 273 statement = wasURLEscape(
273 "SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + 274 "SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" +
274 wasKeyValueGet("wiki table", configuration) + 275 wasKeyValueGet("wiki table", configuration) +
275 "\" WHERE path LIKE '/%' LIMIT " + 276 "\" WHERE path LIKE '/%' LIMIT " +
276 wasKeyValueGet("wiki results limit", configuration) 277 wasKeyValueGet("wiki results limit", configuration)
277 ); 278 );
278 state query; 279 state query;
279 } 280 }
280 statement = wasURLEscape( 281 statement = wasURLEscape(
281 "SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + 282 "SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" +
282 wasKeyValueGet("wiki table", configuration) + 283 wasKeyValueGet("wiki table", configuration) +
283 "\" WHERE path LIKE :path LIMIT " + 284 "\" WHERE path LIKE :path LIMIT " +
284 wasKeyValueGet("wiki results limit", configuration) 285 wasKeyValueGet("wiki results limit", configuration)
285 ); 286 );
286 parameters = wasURLEscape( 287 parameters = wasURLEscape(
287 wasListToCSV( 288 wasListToCSV(
288 [ 289 [
289 "path", 290 "path",
290 wasURLEscape(path + "/" + "%"), 291 wasURLEscape(path + "/" + "%"),
291 "base", 292 "base",
292 wasURLEscape("/" + 293 wasURLEscape("/" +
293 llDumpList2String( 294 llDumpList2String(
294 llParseString2List( 295 llParseString2List(
295 path, 296 path,
296 ["/"], 297 ["/"],
297 [] 298 []
298 ), 299 ),
299 "/" 300 "/"
300 ) + 301 ) +
301 "/" 302 "/"
302 ) 303 )
303 ] 304 ]
304 ) 305 )
305 ); 306 );
306 state query; 307 state query;
307 } 308 }
308 309
309 if(action == "find") { 310 if(action == "find") {
310 if(data == "") { 311 if(data == "") {
311 data = "Command requires two parameters: a path followed by a search term."; 312 data = "Command requires two parameters: a path followed by a search term.";
312 state tell; 313 state tell;
313 } 314 }
314 if(path == "/") 315 if(path == "/")
315 path = ""; 316 path = "";
316 statement = wasURLEscape( 317 statement = wasURLEscape(
317 "SELECT DISTINCT path FROM \"" + 318 "SELECT DISTINCT path FROM \"" +
318 wasKeyValueGet("wiki table", configuration) + 319 wasKeyValueGet("wiki table", configuration) +
319 "\" WHERE path LIKE :path AND ( data LIKE :data OR path LIKE :data ) COLLATE NOCASE LIMIT " + 320 "\" WHERE path LIKE :path AND ( data LIKE :data OR path LIKE :data ) COLLATE NOCASE LIMIT " +
320 wasKeyValueGet("wiki search limit", configuration) 321 wasKeyValueGet("wiki search limit", configuration)
321 ); 322 );
322 parameters = wasURLEscape( 323 parameters = wasURLEscape(
323 wasListToCSV( 324 wasListToCSV(
324 [ 325 [
325 "path", 326 "path",
326 wasURLEscape(path + "/" + "%"), 327 wasURLEscape(path + "/" + "%"),
327 "data", 328 "data",
328 wasURLEscape("%" + data + "%") 329 wasURLEscape("%" + data + "%")
329 ] 330 ]
330 ) 331 )
331 ); 332 );
332 state query; 333 state query;
333 } 334 }
334 335
335 // DEBUG 336 // DEBUG
336 llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); 337 llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
337 llResetScript(); 338 llResetScript();
338 } 339 }
339 on_rez(integer num) { 340 on_rez(integer num) {
340 llResetScript(); 341 llResetScript();
341 } 342 }
342 changed(integer change) { 343 changed(integer change) {
343 if((change & CHANGED_INVENTORY) || 344 if((change & CHANGED_INVENTORY) ||
344 (change & CHANGED_REGION_START) || 345 (change & CHANGED_REGION_START) ||
345 (change & CHANGED_OWNER)) { 346 (change & CHANGED_OWNER)) {
346 llResetScript(); 347 llResetScript();
347 } 348 }
348 } 349 }
349 } 350 }
350   351  
351 state listen_group { 352 state listen_group {
352 state_entry() { 353 state_entry() {
353 // DEBUG 354 // DEBUG
354 llOwnerSay("[Wiki] Waiting for group messages..."); 355 llOwnerSay("[Wiki] Waiting for group messages...");
355 } 356 }
356 link_message(integer sender, integer num, string message, key id) { 357 link_message(integer sender, integer num, string message, key id) {
357 // We only care about notifications now. 358 // We only care about notifications now.
358 if(id != "notification") 359 if(id != "notification")
359 return; 360 return;
360 361
361 // This script only processes group notifications. 362 // This script only processes group notifications.
362 if(wasKeyValueGet("type", message) != "group") 363 if(wasKeyValueGet("type", message) != "group")
363 return; 364 return;
364 365
365 // Get the sent message. 366 // Get the sent message.
366 data = wasURLUnescape( 367 data = wasURLUnescape(
367 wasKeyValueGet( 368 wasKeyValueGet(
368 "message", 369 "message",
369 message 370 message
370 ) 371 )
371 ); 372 );
372 373
373 // Check if this is an eggdrop command. 374 // Check if this is an eggdrop command.
374 if(llGetSubString(data, 0, 0) != 375 if(llGetSubString(data, 0, 0) !=
375 wasKeyValueGet("command", configuration)) 376 wasKeyValueGet("command", configuration))
376 return; 377 return;
377 378
378 // Check if the command matches the current module. 379 // Check if the command matches the current module.
379 list command = llParseString2List(data, [" "], []); 380 list command = llParseString2List(data, [" "], []);
380 if(llList2String(command, 0) != 381 if(llList2String(command, 0) !=
381 wasKeyValueGet("command", configuration) + "wiki") 382 wasKeyValueGet("command", configuration) + "wiki")
382 return; 383 return;
383 384
384 // Remove command. 385 // Remove command.
385 command = llDeleteSubList(command, 0, 0); 386 command = llDeleteSubList(command, 0, 0);
386 387
387 // Check for supported sub-commands. 388 // Check for supported sub-commands.
388 if(llList2String(command, 0) != "set" && 389 if(llList2String(command, 0) != "set" &&
389 llList2String(command, 0) != "get" && 390 llList2String(command, 0) != "get" &&
390 llList2String(command, 0) != "dir" && 391 llList2String(command, 0) != "dir" &&
391 llList2String(command, 0) != "find") { 392 llList2String(command, 0) != "find") {
392 data = "Subcommands are: get, set, dir or find"; 393 data = "Subcommands are: get, set, dir or find";
393 state tell; 394 state tell;
394 } 395 }
395 396
396 // Get the sub-command and store it as a jump state. 397 // Get the sub-command and store it as a jump state.
397 action = llList2String(command, 0); 398 action = llList2String(command, 0);
398 399
399 // Remove sub-command. 400 // Remove sub-command.
400 command = llDeleteSubList(command, 0, 0); 401 command = llDeleteSubList(command, 0, 0);
401 402
402 // Get the path parts. 403 // Get the path parts.
403 list path_parts = llParseString2List( 404 list path_parts = llParseString2List(
404 llList2String(command, 0), ["/"], [] 405 llList2String(command, 0), ["/"], []
405 ); 406 );
406 407
407 // Dump the path and store it over states. 408 // Dump the path and store it over states.
408 path = llStringTrim( 409 path = llStringTrim(
409 llDumpList2String( 410 llDumpList2String(
410 path_parts, 411 path_parts,
411 "/" 412 "/"
412 ), 413 ),
413 STRING_TRIM 414 STRING_TRIM
414 ); 415 );
415 416
416 if(path != "") { 417 if(path != "") {
417 integer i = llStringLength(path) - 1; 418 integer i = llStringLength(path) - 1;
418 do { 419 do {
419 string c = llGetSubString(path, i, i); 420 string c = llGetSubString(path, i, i);
420 if(c != "/" && !wasIsAlNum(c)) { 421 if(c != "/" && !wasIsAlNum(c)) {
421 data = "Only alpha-numerics accepted in the path string."; 422 data = "Only alpha-numerics accepted in the path string.";
422 state tell; 423 state tell;
423 } 424 }
424 } while(--i > -1); 425 } while(--i > -1);
425 } 426 }
426 427
427 path = "/" + path; 428 path = "/" + path;
428 429
429 // Remove path. 430 // Remove path.
430 command = llDeleteSubList(command, 0, 0); 431 command = llDeleteSubList(command, 0, 0);
431 432
432 // Dump the rest of the message. 433 // Dump the rest of the message.
433 data = llDumpList2String(command, " "); 434 data = llDumpList2String(command, " ");
434 435
435 // Get an URL. 436 // Get an URL.
436 state url; 437 state url;
437 } 438 }
438 on_rez(integer num) { 439 on_rez(integer num) {
439 llResetScript(); 440 llResetScript();
440 } 441 }
441 changed(integer change) { 442 changed(integer change) {
442 if((change & CHANGED_INVENTORY) || 443 if((change & CHANGED_INVENTORY) ||
443 (change & CHANGED_REGION_START) || 444 (change & CHANGED_REGION_START) ||
444 (change & CHANGED_OWNER)) { 445 (change & CHANGED_OWNER)) {
445 llResetScript(); 446 llResetScript();
446 } 447 }
447 } 448 }
448 } 449 }
449   450  
450 state query { 451 state query {
451 state_entry() { 452 state_entry() {
452 // Check messge length. 453 // Check messge length.
453 string message = wasKeyValueEncode( 454 string message = wasKeyValueEncode(
454 [ 455 [
455 "command", "database", 456 "command", "database",
456 "group", wasURLEscape( 457 "group", wasURLEscape(
457 wasKeyValueGet( 458 wasKeyValueGet(
458 "group", 459 "group",
459 configuration 460 configuration
460 ) 461 )
461 ), 462 ),
462 "password", wasURLEscape( 463 "password", wasURLEscape(
463 wasKeyValueGet( 464 wasKeyValueGet(
464 "password", 465 "password",
465 configuration 466 configuration
466 ) 467 )
467 ), 468 ),
468 "SQL", statement, 469 "SQL", statement,
469 "data", parameters, 470 "data", parameters,
470 "callback", wasURLEscape(URL) 471 "callback", wasURLEscape(URL)
471 ] 472 ]
472 ); 473 );
473 // GC - none of these are needed anymore. 474 // GC - none of these are needed anymore.
474 statement = ""; 475 statement = "";
475 parameters = ""; 476 parameters = "";
476 if(llStringLength(message) > 1023) { 477 if(llStringLength(message) > 1023) {
477 data = "Message length exceeded 1023 characters."; 478 data = "Message length exceeded 1023 characters.";
478 state tell; 479 state tell;
479 } 480 }
480 // DEBUG 481 // DEBUG
481 llOwnerSay("[Wiki] Executing action: " + action); 482 llOwnerSay("[Wiki] Executing action: " + action);
482 llInstantMessage( 483 llInstantMessage(
483 wasKeyValueGet( 484 wasKeyValueGet(
484 "corrade", 485 "corrade",
485 configuration 486 configuration
486 ), 487 ),
487 message 488 message
488 ); 489 );
489 // GC 490 // GC
490 message = ""; 491 message = "";
491 llSetTimerEvent(60); 492 llSetTimerEvent(60);
492 } 493 }
493 http_request(key id, string method, string body) { 494 http_request(key id, string method, string body) {
494 llHTTPResponse(id, 200, "OK"); 495 llHTTPResponse(id, 200, "OK");
495 llReleaseURL(URL); 496 llReleaseURL(URL);
496 if(wasKeyValueGet("command", body) != "database" || 497 if(wasKeyValueGet("command", body) != "database" ||
497 wasKeyValueGet("success", body) != "True") { 498 wasKeyValueGet("success", body) != "True") {
498 // DEBUG 499 // DEBUG
499 llOwnerSay("[Wiki] Unable query database: " + 500 llOwnerSay("[Wiki] Unable query database: " +
500 wasURLUnescape( 501 wasURLUnescape(
501 wasKeyValueGet("error", body) 502 wasKeyValueGet("error", body)
502 ) 503 )
503 ); 504 );
504 state listen_group; 505 state listen_group;
505 } 506 }
506 507
507 // Process actions. 508 // Process actions.
508 509
509 if(action == "set") { 510 if(action == "set") {
510 if(data == "") { 511 if(data == "") {
511 data = "Deleted from " + path; 512 data = "Deleted from " + path;
512 state tell; 513 state tell;
513 } 514 }
514 data = "Stored into " + path; 515 data = "Stored into " + path;
515 state tell; 516 state tell;
516 } 517 }
517   518  
518 if(action == "find") { 519 if(action == "find") {
519 data = llDumpList2String( 520 data = llDumpList2String(
520 llList2ListStrided( 521 llList2ListStrided(
521 llDeleteSubList( 522 llDeleteSubList(
522 wasCSVToList( 523 wasCSVToList(
523 wasURLUnescape( 524 wasURLUnescape(
524 wasKeyValueGet("data", body) 525 wasKeyValueGet("data", body)
525 ) 526 )
526 ), 527 ),
527 0, 528 0,
528 0 529 0
529 ), 530 ),
530 0, 531 0,
531 -1, 532 -1,
532 2 533 2
533 ), 534 ),
534 "," 535 ","
535 ); 536 );
536 if(data == "") { 537 if(data == "") {
537 data = "Sorry, the term was not found."; 538 data = "Sorry, the term was not found.";
538 state tell; 539 state tell;
539 } 540 }
540 state tell; 541 state tell;
541 } 542 }
542   543  
543 if(action == "get") { 544 if(action == "get") {
544 data = llDumpList2String( 545 data = llDumpList2String(
545 llDeleteSubList( 546 llDeleteSubList(
546 wasCSVToList( 547 wasCSVToList(
547 wasURLUnescape( 548 wasURLUnescape(
548 wasKeyValueGet("data", body) 549 wasKeyValueGet("data", body)
549 ) 550 )
550 ), 551 ),
551 0, 552 0,
552 0 553 0
553 ), 554 ),
554 "" 555 ""
555 ); 556 );
556 557
557 if(data == "") { 558 if(data == "") {
558 data = "Sorry, that path contains no data."; 559 data = "Sorry, that path contains no data.";
559 state tell; 560 state tell;
560 } 561 }
561 562
562 data = path + ": " + data; 563 data = path + ": " + data;
563 state tell; 564 state tell;
564 } 565 }
565 566
566 if(action == "dir") { 567 if(action == "dir") {
567 list paths = llList2ListStrided( 568 list paths = llList2ListStrided(
568 llDeleteSubList( 569 llDeleteSubList(
569 wasCSVToList( 570 wasCSVToList(
570 wasURLUnescape( 571 wasURLUnescape(
571 wasKeyValueGet("data", body) 572 wasKeyValueGet("data", body)
572 ) 573 )
573 ), 574 ),
574 0, 575 0,
575 0 576 0
576 ), 577 ),
577 0, 578 0,
578 -1, 579 -1,
579 2 580 2
580 ); 581 );
581 582
582 if(llGetListLength(paths) == 0) { 583 if(llGetListLength(paths) == 0) {
583 data = "Sorry, that path contains no sub-paths."; 584 data = "Sorry, that path contains no sub-paths.";
584 state tell; 585 state tell;
585 } 586 }
586 587
587 // Eliminate path component. 588 // Eliminate path component.
588 if(path == "/") 589 if(path == "/")
589 path = ""; 590 path = "";
590 591
591 list sibling = []; 592 list sibling = [];
592 do { 593 do {
593 // Get the path part. 594 // Get the path part.
594 string part = llList2String(paths, 0); 595 string part = llList2String(paths, 0);
595 596
596 // Remove the path component. 597 // Remove the path component.
597 string child = llStringTrim( 598 string child = llStringTrim(
598 llDumpList2String( 599 llDumpList2String(
599 llParseString2List( 600 llParseString2List(
600 part, 601 part,
601 [path, "/"], 602 [path, "/"],
602 [] 603 []
603 ), 604 ),
604 "/" 605 "/"
605 ), 606 ),
606 STRING_TRIM 607 STRING_TRIM
607 608
608 ); 609 );
609 610
610 integer i = llSubStringIndex(child, "/"); 611 integer i = llSubStringIndex(child, "/");
611 if(i == -1) { 612 if(i == -1) {
612 sibling += path + "/" + child; 613 sibling += path + "/" + child;
613 jump continue_dir; 614 jump continue_dir;
614 } 615 }
615 child = path + "/" + llDeleteSubString(child, i, -1) + "/"; 616 child = path + "/" + llDeleteSubString(child, i, -1) + "/";
616 if(llListFindList(sibling, (list)child) == -1) 617 if(llListFindList(sibling, (list)child) == -1)
617 sibling += child; 618 sibling += child;
618 @continue_dir; 619 @continue_dir;
619 paths = llDeleteSubList(paths, 0, 0); 620 paths = llDeleteSubList(paths, 0, 0);
620 } while(llGetListLength(paths) != 0); 621 } while(llGetListLength(paths) != 0);
621 622
622 data = llList2CSV(sibling); 623 data = llList2CSV(sibling);
623 // GC 624 // GC
624 sibling = []; 625 sibling = [];
625 626
626 state tell; 627 state tell;
627 } 628 }
628 629
629 // Don't announce creating table. 630 // Don't announce creating table.
630 if(action == "create") 631 if(action == "create")
631 state listen_group; 632 state listen_group;
632 633
633 // DEBUG 634 // DEBUG
634 llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); 635 llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
635 state listen_group; 636 state listen_group;
636 } 637 }
637 timer() { 638 timer() {
638 llReleaseURL(URL); 639 llReleaseURL(URL);
639 state listen_group; 640 state listen_group;
640 } 641 }
641 on_rez(integer num) { 642 on_rez(integer num) {
642 llResetScript(); 643 llResetScript();
643 } 644 }
644 changed(integer change) { 645 changed(integer change) {
645 if((change & CHANGED_INVENTORY) || 646 if((change & CHANGED_INVENTORY) ||
646 (change & CHANGED_REGION_START) || 647 (change & CHANGED_REGION_START) ||
647 (change & CHANGED_OWNER)) { 648 (change & CHANGED_OWNER)) {
648 llResetScript(); 649 llResetScript();
649 } 650 }
650 } 651 }
651 state_exit() { 652 state_exit() {
652 llSetTimerEvent(0); 653 llSetTimerEvent(0);
653 } 654 }
654 } 655 }
655   656  
656 state tell { 657 state tell {
657 state_entry() { 658 state_entry() {
658 // DEBUG 659 // DEBUG
659 llOwnerSay("[Wiki] Sending to group."); 660 llOwnerSay("[Wiki] Sending to group.");
660 llInstantMessage( 661 llInstantMessage(
661 wasKeyValueGet( 662 wasKeyValueGet(
662 "corrade", 663 "corrade",
663 configuration 664 configuration
664 ), 665 ),
665 wasKeyValueEncode( 666 wasKeyValueEncode(
666 [ 667 [
667 "command", "tell", 668 "command", "tell",
668 "group", wasURLEscape( 669 "group", wasURLEscape(
669 wasKeyValueGet( 670 wasKeyValueGet(
670 "group", 671 "group",
671 configuration 672 configuration
672 ) 673 )
673 ), 674 ),
674 "password", wasURLEscape( 675 "password", wasURLEscape(
675 wasKeyValueGet( 676 wasKeyValueGet(
676 "password", 677 "password",
677 configuration 678 configuration
678 ) 679 )
679 ), 680 ),
680 "entity", "group", 681 "entity", "group",
681 "message", wasURLEscape(data) 682 "message", wasURLEscape(data)
682 ] 683 ]
683 ) 684 )
684 ); 685 );
685 // GC 686 // GC
686 path = ""; 687 path = "";
687 data = ""; 688 data = "";
688 state listen_group; 689 state listen_group;
689 } 690 }
690 } 691 }
691   692