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

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