corrade-lsl-templates – Blame information for rev 42
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
15 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
42 | office | 2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
15 | office | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // |
||
5 | // A module that sends the current Corrade version to group chat. |
||
6 | // |
||
7 | /////////////////////////////////////////////////////////////////////////// |
||
8 | |||
9 | /////////////////////////////////////////////////////////////////////////// |
||
41 | office | 10 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
15 | office | 11 | /////////////////////////////////////////////////////////////////////////// |
12 | string wasKeyValueGet(string k, string data) { |
||
13 | if(llStringLength(data) == 0) return ""; |
||
14 | if(llStringLength(k) == 0) return ""; |
||
41 | office | 15 | list a = llParseStringKeepNulls(data, ["&", "="], []); |
16 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
||
17 | if(i != -1) return llList2String(a, 2*i+1); |
||
15 | office | 18 | return ""; |
19 | } |
||
42 | office | 20 | |
15 | office | 21 | /////////////////////////////////////////////////////////////////////////// |
42 | office | 22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 23 | /////////////////////////////////////////////////////////////////////////// |
24 | string wasKeyValueEncode(list data) { |
||
25 | list k = llList2ListStrided(data, 0, -1, 2); |
||
26 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
||
27 | data = []; |
||
28 | do { |
||
29 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
||
30 | k = llDeleteSubList(k, 0, 0); |
||
31 | v = llDeleteSubList(v, 0, 0); |
||
32 | } while(llGetListLength(k) != 0); |
||
33 | return llDumpList2String(data, "&"); |
||
34 | } |
||
35 | |||
36 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 38 | /////////////////////////////////////////////////////////////////////////// |
39 | // http://was.fm/secondlife/wanderer |
||
40 | vector wasCirclePoint(float radius) { |
||
41 | float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
||
42 | float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
||
43 | if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) |
||
44 | return <x, y, 0>; |
||
45 | return wasCirclePoint(radius); |
||
46 | } |
||
47 | |||
48 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 50 | /////////////////////////////////////////////////////////////////////////// |
51 | // escapes a string in conformance with RFC1738 |
||
52 | string wasURLEscape(string i) { |
||
53 | string o = ""; |
||
54 | do { |
||
55 | string c = llGetSubString(i, 0, 0); |
||
56 | i = llDeleteSubString(i, 0, 0); |
||
57 | if(c == "") jump continue; |
||
58 | if(c == " ") { |
||
59 | o += "+"; |
||
60 | jump continue; |
||
61 | } |
||
62 | if(c == "\n") { |
||
63 | o += "%0D" + llEscapeURL(c); |
||
64 | jump continue; |
||
65 | } |
||
66 | o += llEscapeURL(c); |
||
67 | @continue; |
||
68 | } while(i != ""); |
||
69 | return o; |
||
70 | } |
||
71 | |||
72 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 74 | /////////////////////////////////////////////////////////////////////////// |
75 | list wasCSVToList(string csv) { |
||
76 | list l = []; |
||
77 | list s = []; |
||
78 | string m = ""; |
||
79 | do { |
||
80 | string a = llGetSubString(csv, 0, 0); |
||
81 | csv = llDeleteSubString(csv, 0, 0); |
||
82 | if(a == ",") { |
||
83 | if(llList2String(s, -1) != "\"") { |
||
84 | l += m; |
||
85 | m = ""; |
||
86 | jump continue; |
||
87 | } |
||
88 | m += a; |
||
89 | jump continue; |
||
90 | } |
||
91 | if(a == "\"" && llGetSubString(csv, 0, 0) == a) { |
||
92 | m += a; |
||
93 | csv = llDeleteSubString(csv, 0, 0); |
||
94 | jump continue; |
||
95 | } |
||
96 | if(a == "\"") { |
||
97 | if(llList2String(s, -1) != a) { |
||
98 | s += a; |
||
99 | jump continue; |
||
100 | } |
||
101 | s = llDeleteSubList(s, -1, -1); |
||
102 | jump continue; |
||
103 | } |
||
104 | m += a; |
||
105 | @continue; |
||
106 | } while(csv != ""); |
||
107 | // postcondition: length(s) = 0 |
||
108 | return l + m; |
||
109 | } |
||
110 | |||
111 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 113 | /////////////////////////////////////////////////////////////////////////// |
114 | string wasListToCSV(list l) { |
||
115 | list v = []; |
||
116 | do { |
||
117 | string a = llDumpList2String( |
||
118 | llParseStringKeepNulls( |
||
119 | llList2String( |
||
42 | office | 120 | l, |
15 | office | 121 | |
42 | office | 122 | ), |
123 | ["\""], |
||
15 | office | 124 | [] |
125 | ), |
||
126 | "\"\"" |
||
127 | ); |
||
128 | if(llParseStringKeepNulls( |
||
42 | office | 129 | a, |
15 | office | 130 | [" ", ",", "\n", "\""], [] |
42 | office | 131 | ) != |
15 | office | 132 | (list) a |
133 | ) a = "\"" + a + "\""; |
||
134 | v += a; |
||
135 | l = llDeleteSubList(l, 0, 0); |
||
136 | } while(l != []); |
||
137 | return llDumpList2String(v, ","); |
||
138 | } |
||
139 | |||
140 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 142 | /////////////////////////////////////////////////////////////////////////// |
143 | // unescapes a string in conformance with RFC1738 |
||
144 | string wasURLUnescape(string i) { |
||
145 | return llUnescapeURL( |
||
146 | llDumpList2String( |
||
147 | llParseString2List( |
||
148 | llDumpList2String( |
||
149 | llParseString2List( |
||
42 | office | 150 | i, |
151 | ["+"], |
||
15 | office | 152 | [] |
42 | office | 153 | ), |
15 | office | 154 | " " |
42 | office | 155 | ), |
156 | ["%0D%0A"], |
||
15 | office | 157 | [] |
42 | office | 158 | ), |
15 | office | 159 | "\n" |
160 | ) |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | /////////////////////////////////////////////////////////////////////////// |
||
42 | office | 165 | // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 // |
15 | office | 166 | /////////////////////////////////////////////////////////////////////////// |
167 | list wasSetIntersect(list a, list b) { |
||
168 | if(llGetListLength(a) == 0) return []; |
||
169 | string i = llList2String(a, 0); |
||
170 | a = llDeleteSubList(a, 0, 0); |
||
171 | if(llListFindList(b, (list)i) == -1) |
||
172 | return wasSetIntersect(a, b); |
||
173 | return i + wasSetIntersect(a, b); |
||
174 | } |
||
175 | |||
176 | // configuration data |
||
177 | string configuration = ""; |
||
178 | // store message over state. |
||
179 | string data = ""; |
||
180 | |||
181 | default { |
||
182 | state_entry() { |
||
183 | llOwnerSay("[Version] Starting..."); |
||
184 | llSetTimerEvent(10); |
||
185 | } |
||
186 | link_message(integer sender, integer num, string message, key id) { |
||
187 | if(id != "configuration") return; |
||
188 | llOwnerSay("[Version] Got configuration..."); |
||
189 | configuration = message; |
||
190 | state listen_group; |
||
191 | } |
||
192 | timer() { |
||
193 | llOwnerSay("[Version] Requesting configuration..."); |
||
194 | llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); |
||
195 | } |
||
196 | on_rez(integer num) { |
||
197 | llResetScript(); |
||
198 | } |
||
199 | changed(integer change) { |
||
42 | office | 200 | if((change & CHANGED_INVENTORY) || |
201 | (change & CHANGED_REGION_START) || |
||
15 | office | 202 | (change & CHANGED_OWNER)) { |
203 | llResetScript(); |
||
204 | } |
||
205 | } |
||
206 | state_exit() { |
||
207 | llSetTimerEvent(0); |
||
208 | } |
||
209 | } |
||
210 | |||
211 | state listen_group { |
||
212 | state_entry() { |
||
213 | // DEBUG |
||
214 | llOwnerSay("[Version] Waiting for group messages..."); |
||
215 | } |
||
216 | link_message(integer sender, integer num, string message, key id) { |
||
217 | // We only care about notifications now. |
||
218 | if(id != "notification") |
||
219 | return; |
||
42 | office | 220 | |
15 | office | 221 | // This script only processes group notifications. |
42 | office | 222 | if(wasKeyValueGet("type", message) != "group" || |
223 | (wasKeyValueGet("type", message) == "group" && |
||
224 | wasURLUnescape(wasKeyValueGet("group", message)) != |
||
225 | wasKeyValueGet("group", configuration))) |
||
15 | office | 226 | return; |
42 | office | 227 | |
15 | office | 228 | // Get the sent message. |
229 | data = wasURLUnescape( |
||
230 | wasKeyValueGet( |
||
42 | office | 231 | "message", |
15 | office | 232 | message |
233 | ) |
||
234 | ); |
||
42 | office | 235 | |
15 | office | 236 | // Check if this is an eggdrop command. |
42 | office | 237 | if(llGetSubString(data, 0, 0) != |
15 | office | 238 | wasKeyValueGet("command", configuration)) |
239 | return; |
||
42 | office | 240 | |
15 | office | 241 | // Check if the command matches the current module. |
242 | list command = llParseString2List(data, [" "], []); |
||
42 | office | 243 | if(llList2String(command, 0) != |
15 | office | 244 | wasKeyValueGet("command", configuration) + "version") |
245 | return; |
||
42 | office | 246 | |
15 | office | 247 | // Remove command. |
248 | command = llDeleteSubList(command, 0, 0); |
||
249 | |||
42 | office | 250 | // Get version. |
15 | office | 251 | state version; |
252 | } |
||
253 | on_rez(integer num) { |
||
254 | llResetScript(); |
||
255 | } |
||
256 | changed(integer change) { |
||
42 | office | 257 | if((change & CHANGED_INVENTORY) || |
258 | (change & CHANGED_REGION_START) || |
||
15 | office | 259 | (change & CHANGED_OWNER)) { |
260 | llResetScript(); |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | |||
265 | state version { |
||
266 | state_entry() { |
||
267 | // DEBUG |
||
268 | llOwnerSay("[Version] Getting version..."); |
||
269 | llInstantMessage( |
||
270 | wasKeyValueGet( |
||
42 | office | 271 | "corrade", |
15 | office | 272 | configuration |
42 | office | 273 | ), |
15 | office | 274 | wasKeyValueEncode( |
275 | [ |
||
276 | "command", "version", |
||
277 | "group", wasURLEscape( |
||
278 | wasKeyValueGet( |
||
42 | office | 279 | "group", |
15 | office | 280 | configuration |
281 | ) |
||
282 | ), |
||
283 | "password", wasURLEscape( |
||
284 | wasKeyValueGet( |
||
42 | office | 285 | "password", |
15 | office | 286 | configuration |
287 | ) |
||
288 | ), |
||
42 | office | 289 | "callback", wasURLEscape( |
290 | wasKeyValueGet( |
||
291 | "URL", |
||
292 | configuration |
||
293 | ) |
||
294 | ) |
||
15 | office | 295 | ] |
296 | ) |
||
297 | ); |
||
298 | llSetTimerEvent(60); |
||
299 | } |
||
42 | office | 300 | link_message(integer sender, integer num, string body, key id) { |
301 | // Only process callbacks for the database command. |
||
302 | if(id != "callback" || wasKeyValueGet("command", body) != "version") |
||
303 | return; |
||
304 | |||
305 | if(wasKeyValueGet("success", body) != "True") { |
||
15 | office | 306 | // DEBUG |
42 | office | 307 | llOwnerSay("[Version] Unable to get version: " + |
15 | office | 308 | wasURLUnescape( |
309 | wasKeyValueGet("error", body) |
||
310 | ) |
||
311 | ); |
||
312 | state listen_group; |
||
313 | } |
||
42 | office | 314 | |
15 | office | 315 | data = "I'm a " + wasKeyValueGet("data", body); |
42 | office | 316 | |
15 | office | 317 | state tell; |
318 | } |
||
319 | timer() { |
||
320 | state listen_group; |
||
321 | } |
||
322 | on_rez(integer num) { |
||
323 | llResetScript(); |
||
324 | } |
||
325 | changed(integer change) { |
||
42 | office | 326 | if((change & CHANGED_INVENTORY) || |
327 | (change & CHANGED_REGION_START) || |
||
15 | office | 328 | (change & CHANGED_OWNER)) { |
329 | llResetScript(); |
||
330 | } |
||
331 | } |
||
332 | state_exit() { |
||
333 | llSetTimerEvent(0); |
||
334 | } |
||
335 | } |
||
336 | |||
337 | state tell { |
||
338 | state_entry() { |
||
339 | // DEBUG |
||
340 | llOwnerSay("[Version] Sending to group."); |
||
341 | llInstantMessage( |
||
342 | wasKeyValueGet( |
||
42 | office | 343 | "corrade", |
15 | office | 344 | configuration |
42 | office | 345 | ), |
15 | office | 346 | wasKeyValueEncode( |
347 | [ |
||
348 | "command", "tell", |
||
349 | "group", wasURLEscape( |
||
350 | wasKeyValueGet( |
||
42 | office | 351 | "group", |
15 | office | 352 | configuration |
353 | ) |
||
354 | ), |
||
355 | "password", wasURLEscape( |
||
356 | wasKeyValueGet( |
||
42 | office | 357 | "password", |
15 | office | 358 | configuration |
359 | ) |
||
360 | ), |
||
361 | "entity", "group", |
||
362 | "message", wasURLEscape(data) |
||
363 | ] |
||
364 | ) |
||
365 | ); |
||
366 | state listen_group; |
||
367 | } |
||
368 | } |