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