corrade-lsl-templates – Diff between revs 12 and 13

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