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

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 41 Rev 42
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // 4 //
5 // A module that evaluates a mathematical expression for Corrade Eggdrop. 5 // A module that evaluates a mathematical expression for Corrade Eggdrop.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
Line 15... Line 15...
15 list a = llParseStringKeepNulls(data, ["&", "="], []); 15 list a = llParseStringKeepNulls(data, ["&", "="], []);
16 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); 16 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
17 if(i != -1) return llList2String(a, 2*i+1); 17 if(i != -1) return llList2String(a, 2*i+1);
18 return ""; 18 return "";
19 } 19 }
20 20  
21 /////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////
22 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // 22 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
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 = [];
Line 32... Line 32...
32 } while(llGetListLength(k) != 0); 32 } while(llGetListLength(k) != 0);
33 return llDumpList2String(data, "&"); 33 return llDumpList2String(data, "&");
34 } 34 }
Line 35... Line 35...
35   35  
36 /////////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////////
37 // Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 // 37 // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 //
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);
Line 44... Line 44...
44 return <x, y, 0>; 44 return <x, y, 0>;
45 return wasCirclePoint(radius); 45 return wasCirclePoint(radius);
46 } 46 }
Line 47... Line 47...
47   47  
48 /////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////
49 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 49 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
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 = "";
Line 68... Line 68...
68 } while(i != ""); 68 } while(i != "");
69 return o; 69 return o;
70 } 70 }
Line 71... Line 71...
71   71  
72 /////////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////////
73 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 73 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
74 /////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////
75 list wasCSVToList(string csv) { 75 list wasCSVToList(string csv) {
76 list l = []; 76 list l = [];
77 list s = []; 77 list s = [];
Line 107... Line 107...
107 // postcondition: length(s) = 0 107 // postcondition: length(s) = 0
108 return l + m; 108 return l + m;
109 } 109 }
Line 110... Line 110...
110   110  
111 /////////////////////////////////////////////////////////////////////////// 111 ///////////////////////////////////////////////////////////////////////////
112 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 112 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
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, ",");
Line 138... Line 138...
138 } 138 }
139   139  
140 /////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////
141 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 141 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
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 )
Line 166... Line 166...
166 ////////////////////////////////////////////////////////// 166 //////////////////////////////////////////////////////////
167 list wasListReverse(list lst) { 167 list wasListReverse(list lst) {
168 if(llGetListLength(lst)<=1) return lst; 168 if(llGetListLength(lst)<=1) return lst;
169 return wasListReverse(llList2List(lst, 1, llGetListLength(lst))) + llList2List(lst,0,0); 169 return wasListReverse(llList2List(lst, 1, llGetListLength(lst))) + llList2List(lst,0,0);
170 } 170 }
171 171  
172 ////////////////////////////////////////////////////////// 172 //////////////////////////////////////////////////////////
173 // Deletes elements delete from list input. 173 // Deletes elements delete from list input.
174 ////////////////////////////////////////////////////////// 174 //////////////////////////////////////////////////////////
175 list wasSubtractSubList(list input, list delete) { 175 list wasSubtractSubList(list input, list delete) {
176 do { 176 do {
Line 183... Line 183...
183 } 183 }
184 } while(clean = llDeleteSubList(clean, 0, 0)); 184 } while(clean = llDeleteSubList(clean, 0, 0));
185 } while(delete = llDeleteSubList(delete, 0, 0)); 185 } while(delete = llDeleteSubList(delete, 0, 0));
186 return input; 186 return input;
187 } 187 }
188 188  
189 ////////////////////////////////////////////////////////// 189 //////////////////////////////////////////////////////////
190 // Returns a list of operators and operands. 190 // Returns a list of operators and operands.
191 ////////////////////////////////////////////////////////// 191 //////////////////////////////////////////////////////////
192 list wasInfixTokenize(string input) { 192 list wasInfixTokenize(string input) {
193 list op = [ "+", "-", "(", ")", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ]; 193 list op = [ "+", "-", "(", ")", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ];
194 list result = llParseString2List(input, [], op); 194 list result = llParseString2List(input, [], op);
195 return wasSubtractSubList(result, [" "]); 195 return wasSubtractSubList(result, [" "]);
196 } 196 }
197 197  
198 ////////////////////////////////////////////////////////// 198 //////////////////////////////////////////////////////////
199 // Transforms an infix expression to a postfix expression. 199 // Transforms an infix expression to a postfix expression.
200 ////////////////////////////////////////////////////////// 200 //////////////////////////////////////////////////////////
201 list wasInfixToPostfix(list infix) { 201 list wasInfixToPostfix(list infix) {
202 list op = [ "+", "-", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ]; 202 list op = [ "+", "-", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ];
Line 233... Line 233...
233 } 233 }
234 opStack += t; 234 opStack += t;
235 @continue; 235 @continue;
236 } while(llGetListLength(infix) != 0); 236 } while(llGetListLength(infix) != 0);
237 result += wasListReverse(opStack); 237 result += wasListReverse(opStack);
238 return result; 238 return result;
239 } 239 }
240 240  
241 ////////////////////////////////////////////////////////// 241 //////////////////////////////////////////////////////////
242 // Evaluate a postfix expression. 242 // Evaluate a postfix expression.
243 ////////////////////////////////////////////////////////// 243 //////////////////////////////////////////////////////////
244 float wasPostfixEval(list postfix) { 244 float wasPostfixEval(list postfix) {
245 list op = [ "+", "-", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ]; 245 list op = [ "+", "-", "%", "*", "/", "^", "sin", "asin", "cos", "acos", "tan", "sqrt", "ln" ];
Line 324... Line 324...
324 return llList2Float(orStack, 0); 324 return llList2Float(orStack, 0);
325 } 325 }
Line 326... Line 326...
326   326  
327 // configuration data 327 // configuration data
328 string configuration = ""; -  
329 // callback URL -  
330 string URL = ""; 328 string configuration = "";
331 // store message over state. 329 // store message over state.
Line 332... Line 330...
332 string data = ""; 330 string data = "";
333   331  
Line 353... Line 351...
353 } 351 }
354 on_rez(integer num) { 352 on_rez(integer num) {
355 llResetScript(); 353 llResetScript();
356 } 354 }
357 changed(integer change) { 355 changed(integer change) {
358 if((change & CHANGED_INVENTORY) || 356 if((change & CHANGED_INVENTORY) ||
359 (change & CHANGED_REGION_START) || 357 (change & CHANGED_REGION_START) ||
360 (change & CHANGED_OWNER)) { 358 (change & CHANGED_OWNER)) {
361 llResetScript(); 359 llResetScript();
362 } 360 }
363 } 361 }
364 state_exit() { 362 state_exit() {
Line 373... Line 371...
373 } 371 }
374 link_message(integer sender, integer num, string message, key id) { 372 link_message(integer sender, integer num, string message, key id) {
375 // We only care about notifications now. 373 // We only care about notifications now.
376 if(id != "notification") 374 if(id != "notification")
377 return; 375 return;
378 376  
379 // This script only processes group notifications. 377 // This script only processes group notifications.
380 if(wasKeyValueGet("type", message) != "group") 378 if(wasKeyValueGet("type", message) != "group" ||
-   379 (wasKeyValueGet("type", message) == "group" &&
-   380 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   381 wasKeyValueGet("group", configuration)))
381 return; 382 return;
382 383  
383 // Get the sent message. 384 // Get the sent message.
384 data = wasURLUnescape( 385 data = wasURLUnescape(
385 wasKeyValueGet( 386 wasKeyValueGet(
386 "message", 387 "message",
387 message 388 message
388 ) 389 )
389 ); 390 );
390 391  
391 // Check if this is an eggdrop command. 392 // Check if this is an eggdrop command.
392 if(llGetSubString(data, 0, 0) != 393 if(llGetSubString(data, 0, 0) !=
393 wasKeyValueGet("command", configuration)) 394 wasKeyValueGet("command", configuration))
394 return; 395 return;
395 396  
396 // Check if the command matches the current module. 397 // Check if the command matches the current module.
397 list command = llParseString2List(data, [" "], []); 398 list command = llParseString2List(data, [" "], []);
398 if(llList2String(command, 0) != 399 if(llList2String(command, 0) !=
399 wasKeyValueGet("command", configuration) + "eval") 400 wasKeyValueGet("command", configuration) + "eval")
400 return; 401 return;
401 402  
402 // Remove command. 403 // Remove command.
403 command = llDeleteSubList(command, 0, 0); 404 command = llDeleteSubList(command, 0, 0);
404 405  
405 // Dump the rest of the message. 406 // Dump the rest of the message.
406 data = (string)wasPostfixEval( 407 data = (string)wasPostfixEval(
407 wasInfixToPostfix( 408 wasInfixToPostfix(
408 wasInfixTokenize( 409 wasInfixTokenize(
409 llDumpList2String( 410 llDumpList2String(
Line 411... Line 412...
411 " " 412 " "
412 ) 413 )
413 ) 414 )
414 ) 415 )
415 ); 416 );
416 417  
417 state tell; 418 state tell;
418 } 419 }
419 on_rez(integer num) { 420 on_rez(integer num) {
420 llResetScript(); 421 llResetScript();
421 } 422 }
422 changed(integer change) { 423 changed(integer change) {
423 if((change & CHANGED_INVENTORY) || 424 if((change & CHANGED_INVENTORY) ||
424 (change & CHANGED_REGION_START) || 425 (change & CHANGED_REGION_START) ||
425 (change & CHANGED_OWNER)) { 426 (change & CHANGED_OWNER)) {
426 llResetScript(); 427 llResetScript();
427 } 428 }
428 } 429 }
429 } 430 }
Line 432... Line 433...
432 state_entry() { 433 state_entry() {
433 // DEBUG 434 // DEBUG
434 llOwnerSay("[Eval] Sending to group."); 435 llOwnerSay("[Eval] Sending to group.");
435 llInstantMessage( 436 llInstantMessage(
436 wasKeyValueGet( 437 wasKeyValueGet(
437 "corrade", 438 "corrade",
438 configuration 439 configuration
439 ), 440 ),
440 wasKeyValueEncode( 441 wasKeyValueEncode(
441 [ 442 [
442 "command", "tell", 443 "command", "tell",
443 "group", wasURLEscape( 444 "group", wasURLEscape(
444 wasKeyValueGet( 445 wasKeyValueGet(
445 "group", 446 "group",
446 configuration 447 configuration
447 ) 448 )
448 ), 449 ),
449 "password", wasURLEscape( 450 "password", wasURLEscape(
450 wasKeyValueGet( 451 wasKeyValueGet(
451 "password", 452 "password",
452 configuration 453 configuration
453 ) 454 )
454 ), 455 ),
455 "entity", "group", 456 "entity", "group",
456 "message", wasURLEscape(data) 457 "message", wasURLEscape(data)