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 fortune module for Corrade Eggdrop. 5 // A fortune module 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 190... Line 190...
190 } 190 }
191 on_rez(integer num) { 191 on_rez(integer num) {
192 llResetScript(); 192 llResetScript();
193 } 193 }
194 changed(integer change) { 194 changed(integer change) {
195 if((change & CHANGED_INVENTORY) || 195 if((change & CHANGED_INVENTORY) ||
196 (change & CHANGED_REGION_START) || 196 (change & CHANGED_REGION_START) ||
197 (change & CHANGED_OWNER)) { 197 (change & CHANGED_OWNER)) {
198 llResetScript(); 198 llResetScript();
199 } 199 }
200 } 200 }
201 state_exit() { 201 state_exit() {
Line 227... Line 227...
227 } 227 }
228 on_rez(integer num) { 228 on_rez(integer num) {
229 llResetScript(); 229 llResetScript();
230 } 230 }
231 changed(integer change) { 231 changed(integer change) {
232 if((change & CHANGED_INVENTORY) || 232 if((change & CHANGED_INVENTORY) ||
233 (change & CHANGED_REGION_START) || 233 (change & CHANGED_REGION_START) ||
234 (change & CHANGED_OWNER)) { 234 (change & CHANGED_OWNER)) {
235 llResetScript(); 235 llResetScript();
236 } 236 }
237 } 237 }
238 } 238 }
Line 244... Line 244...
244 } 244 }
245 link_message(integer sender, integer num, string message, key id) { 245 link_message(integer sender, integer num, string message, key id) {
246 // We only care about notifications now. 246 // We only care about notifications now.
247 if(id != "notification") 247 if(id != "notification")
248 return; 248 return;
249 249  
250 // This script only processes group notifications. 250 // This script only processes group notifications.
251 if(wasKeyValueGet("type", message) != "group") 251 if(wasKeyValueGet("type", message) != "group" ||
-   252 (wasKeyValueGet("type", message) == "group" &&
-   253 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   254 wasKeyValueGet("group", configuration)))
252 return; 255 return;
253 256  
254 // Get the sent message. 257 // Get the sent message.
255 data = wasURLUnescape( 258 data = wasURLUnescape(
256 wasKeyValueGet( 259 wasKeyValueGet(
257 "message", 260 "message",
258 message 261 message
259 ) 262 )
260 ); 263 );
261 264  
262 // Check if this is an eggdrop command. 265 // Check if this is an eggdrop command.
263 if(llGetSubString(data, 0, 0) != 266 if(llGetSubString(data, 0, 0) !=
264 wasKeyValueGet("command", configuration)) 267 wasKeyValueGet("command", configuration))
265 return; 268 return;
266 269  
267 // Check if the command matches the current module. 270 // Check if the command matches the current module.
268 list command = llParseString2List(data, [" "], []); 271 list command = llParseString2List(data, [" "], []);
269 if(llList2String(command, 0) != 272 if(llList2String(command, 0) !=
270 wasKeyValueGet("command", configuration) + "fortune") 273 wasKeyValueGet("command", configuration) + "fortune")
271 return; 274 return;
272 275  
273 // Remove command. 276 // Remove command.
274 command = llDeleteSubList(command, 0, 0); 277 command = llDeleteSubList(command, 0, 0);
275 278  
276 data = llList2String( 279 data = llList2String(
277 nList, 280 nList,
278 (integer) 281 (integer)
279 llFrand( 282 llFrand(
280 llGetListLength(nList) 283 llGetListLength(nList)
281 ) 284 )
282 ); 285 );
283 286  
284 state tell; 287 state tell;
285 } 288 }
286 on_rez(integer num) { 289 on_rez(integer num) {
287 llResetScript(); 290 llResetScript();
288 } 291 }
289 changed(integer change) { 292 changed(integer change) {
290 if((change & CHANGED_INVENTORY) || 293 if((change & CHANGED_INVENTORY) ||
291 (change & CHANGED_REGION_START) || 294 (change & CHANGED_REGION_START) ||
292 (change & CHANGED_OWNER)) { 295 (change & CHANGED_OWNER)) {
293 llResetScript(); 296 llResetScript();
294 } 297 }
295 } 298 }
296 } 299 }
Line 299... Line 302...
299 state_entry() { 302 state_entry() {
300 // DEBUG 303 // DEBUG
301 llOwnerSay("[Fortune] Sending to group."); 304 llOwnerSay("[Fortune] Sending to group.");
302 llInstantMessage( 305 llInstantMessage(
303 wasKeyValueGet( 306 wasKeyValueGet(
304 "corrade", 307 "corrade",
305 configuration 308 configuration
306 ), 309 ),
307 wasKeyValueEncode( 310 wasKeyValueEncode(
308 [ 311 [
309 "command", "tell", 312 "command", "tell",
310 "group", wasURLEscape( 313 "group", wasURLEscape(
311 wasKeyValueGet( 314 wasKeyValueGet(
312 "group", 315 "group",
313 configuration 316 configuration
314 ) 317 )
315 ), 318 ),
316 "password", wasURLEscape( 319 "password", wasURLEscape(
317 wasKeyValueGet( 320 wasKeyValueGet(
318 "password", 321 "password",
319 configuration 322 configuration
320 ) 323 )
321 ), 324 ),
322 "entity", "group", 325 "entity", "group",
323 "message", wasURLEscape(data) 326 "message", wasURLEscape(data)