corrade-lsl-templates – Diff between revs 10 and 11

Subversion Repositories:
Rev:
Only display areas with differencesRegard whitespace
Rev 10 Rev 11
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 joke module for Corrade Eggdrop. 5 // A joke module for Corrade Eggdrop.
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: GNU GPLv3 //
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: 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 = [];
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: 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);
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: 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 = "";
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: 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 = [];
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: 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, ",");
138 } 138 }
139   139  
140 /////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////
141 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // 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 )
161 ); 161 );
162 } 162 }
163   163  
164 // configuration data 164 // configuration data
165 string configuration = ""; 165 string configuration = "";
166 // callback URL 166 // callback URL
167 string URL = ""; 167 string URL = "";
168 // store message over state. 168 // store message over state.
169 string data = ""; 169 string data = "";
170   170  
171 // Notecard reading. 171 // Notecard reading.
172 key nQuery = NULL_KEY; 172 key nQuery = NULL_KEY;
173 integer nLine = 0; 173 integer nLine = 0;
174 list nList = []; 174 list nList = [];
175   175  
176 default { 176 default {
177 state_entry() { 177 state_entry() {
178 llOwnerSay("[Joke] Starting module..."); 178 llOwnerSay("[Joke] Starting module...");
179 llSetTimerEvent(10); 179 llSetTimerEvent(10);
180 } 180 }
181 link_message(integer sender, integer num, string message, key id) { 181 link_message(integer sender, integer num, string message, key id) {
182 if(id != "configuration") return; 182 if(id != "configuration") return;
183 llOwnerSay("[Joke] Got configuration..."); 183 llOwnerSay("[Joke] Got configuration...");
184 configuration = message; 184 configuration = message;
185 state read_jokes; 185 state read_jokes;
186 } 186 }
187 timer() { 187 timer() {
188 llOwnerSay("[Joke] Requesting configuration..."); 188 llOwnerSay("[Joke] Requesting configuration...");
189 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 189 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
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() {
202 llSetTimerEvent(0); 202 llSetTimerEvent(0);
203 } 203 }
204 } 204 }
205   205  
206 state read_jokes { 206 state read_jokes {
207 state_entry() { 207 state_entry() {
208 // DEBUG 208 // DEBUG
209 llOwnerSay("[Joke] Reading jokes..."); 209 llOwnerSay("[Joke] Reading jokes...");
210 if(llGetInventoryType("Joke") != INVENTORY_NOTECARD) { 210 if(llGetInventoryType("Joke") != INVENTORY_NOTECARD) {
211 llOwnerSay("[Joke] Failed to find a notecard named Joke in the primitive's inventory."); 211 llOwnerSay("[Joke] Failed to find a notecard named Joke in the primitive's inventory.");
212 return; 212 return;
213 } 213 }
214 nQuery = llGetNotecardLine("Joke", nLine); 214 nQuery = llGetNotecardLine("Joke", nLine);
215 } 215 }
216 dataserver(key id, string data) { 216 dataserver(key id, string data) {
217 if(id != nQuery) return; 217 if(id != nQuery) return;
218 if(data == EOF) { 218 if(data == EOF) {
219 // DEBUG 219 // DEBUG
220 llOwnerSay("[Joke] Read jokes..."); 220 llOwnerSay("[Joke] Read jokes...");
221 state listen_group; 221 state listen_group;
222 } 222 }
223 if(data == "") jump continue; 223 if(data == "") jump continue;
224 nList += data; 224 nList += data;
225 @continue; 225 @continue;
226 nQuery = llGetNotecardLine("Joke", ++nLine); 226 nQuery = llGetNotecardLine("Joke", ++nLine);
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 }
239   239  
240 state listen_group { 240 state listen_group {
241 state_entry() { 241 state_entry() {
242 // DEBUG 242 // DEBUG
243 llOwnerSay("[Joke] Waiting for group messages..."); 243 llOwnerSay("[Joke] Waiting for group messages...");
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 return; 252 return;
253 253
254 // Get the sent message. 254 // Get the sent message.
255 data = wasURLUnescape( 255 data = wasURLUnescape(
256 wasKeyValueGet( 256 wasKeyValueGet(
257 "message", 257 "message",
258 message 258 message
259 ) 259 )
260 ); 260 );
-   261
261 262 // Check if this is an eggdrop command.
262 if(llGetSubString(data, 0, 0) != 263 if(llGetSubString(data, 0, 0) !=
263 wasKeyValueGet("command", configuration)) 264 wasKeyValueGet("command", configuration))
264 return; 265 return;
-   266
265 267 // Check if the command matches the current module.
266 list command = llParseString2List(data, 268 list command = llParseString2List(data,
267 [wasKeyValueGet("command", configuration), " "], []); 269 [wasKeyValueGet("command", configuration), " "], ["@"]);
268 if(llList2String(command, 0) != "joke") 270 if(llList2String(command, 0) != "joke")
269 return; 271 return;
270 272
271 list range = wasCSVToList( 273 list range = wasCSVToList(
272 wasKeyValueGet("roll range", configuration) 274 wasKeyValueGet("roll range", configuration)
273 ); 275 );
274 276
275 data = llList2String( 277 data = llList2String(
276 nList, 278 nList,
277 (integer) 279 (integer)
278 llFrand( 280 llFrand(
279 llGetListLength(nList) 281 llGetListLength(nList)
280 ) 282 )
281 ); 283 );
282 284
283 state tell; 285 state tell;
284 } 286 }
285 on_rez(integer num) { 287 on_rez(integer num) {
286 llResetScript(); 288 llResetScript();
287 } 289 }
288 changed(integer change) { 290 changed(integer change) {
289 if((change & CHANGED_INVENTORY) || 291 if((change & CHANGED_INVENTORY) ||
290 (change & CHANGED_REGION_START) || 292 (change & CHANGED_REGION_START) ||
291 (change & CHANGED_OWNER)) { 293 (change & CHANGED_OWNER)) {
292 llResetScript(); 294 llResetScript();
293 } 295 }
294 } 296 }
295 } 297 }
296   298  
297 state tell { 299 state tell {
298 state_entry() { 300 state_entry() {
299 // DEBUG 301 // DEBUG
300 llOwnerSay("[Joke] Sending to group."); 302 llOwnerSay("[Joke] Sending to group.");
301 llInstantMessage( 303 llInstantMessage(
302 wasKeyValueGet( 304 wasKeyValueGet(
303 "corrade", 305 "corrade",
304 configuration 306 configuration
305 ), 307 ),
306 wasKeyValueEncode( 308 wasKeyValueEncode(
307 [ 309 [
308 "command", "tell", 310 "command", "tell",
309 "group", wasURLEscape( 311 "group", wasURLEscape(
310 wasKeyValueGet( 312 wasKeyValueGet(
311 "group", 313 "group",
312 configuration 314 configuration
313 ) 315 )
314 ), 316 ),
315 "password", wasURLEscape( 317 "password", wasURLEscape(
316 wasKeyValueGet( 318 wasKeyValueGet(
317 "password", 319 "password",
318 configuration 320 configuration
319 ) 321 )
320 ), 322 ),
321 "entity", "group", 323 "entity", "group",
322 "message", wasURLEscape(data) 324 "message", wasURLEscape(data)
323 ] 325 ]
324 ) 326 )
325 ); 327 );
326 state listen_group; 328 state listen_group;
327 } 329 }
328 } 330 }
329   331