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

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 41 Rev 42
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 dice roll with a configurable range. 5 // A dice roll with a configurable range.
6 // 6 //
7 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
8   8  
9 /////////////////////////////////////////////////////////////////////////// 9 ///////////////////////////////////////////////////////////////////////////
10 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // 10 // Copyright (C) 2015 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 = 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 = [];
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: 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);
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: 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 = "";
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: 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 = [];
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: 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, ",");
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 )
161 ); 161 );
162 } 162 }
163   163  
164 // configuration data 164 // configuration data
165 string configuration = ""; 165 string configuration = "";
166 // callback URL -  
167 string URL = ""; -  
168 // store message over state. 166 // store message over state.
169 string data = ""; 167 string data = "";
170   168  
171 default { 169 default {
172 state_entry() { 170 state_entry() {
173 llOwnerSay("[Dice] Starting module..."); 171 llOwnerSay("[Dice] Starting module...");
174 llSetTimerEvent(10); 172 llSetTimerEvent(10);
175 } 173 }
176 link_message(integer sender, integer num, string message, key id) { 174 link_message(integer sender, integer num, string message, key id) {
177 if(id != "configuration") return; 175 if(id != "configuration") return;
178 llOwnerSay("[Dice] Got configuration..."); 176 llOwnerSay("[Dice] Got configuration...");
179 configuration = message; 177 configuration = message;
180 state listen_group; 178 state listen_group;
181 } 179 }
182 timer() { 180 timer() {
183 llOwnerSay("[Dice] Requesting configuration..."); 181 llOwnerSay("[Dice] Requesting configuration...");
184 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); 182 llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY);
185 } 183 }
186 on_rez(integer num) { 184 on_rez(integer num) {
187 llResetScript(); 185 llResetScript();
188 } 186 }
189 changed(integer change) { 187 changed(integer change) {
190 if((change & CHANGED_INVENTORY) || 188 if((change & CHANGED_INVENTORY) ||
191 (change & CHANGED_REGION_START) || 189 (change & CHANGED_REGION_START) ||
192 (change & CHANGED_OWNER)) { 190 (change & CHANGED_OWNER)) {
193 llResetScript(); 191 llResetScript();
194 } 192 }
195 } 193 }
196 state_exit() { 194 state_exit() {
197 llSetTimerEvent(0); 195 llSetTimerEvent(0);
198 } 196 }
199 } 197 }
200   198  
201 state listen_group { 199 state listen_group {
202 state_entry() { 200 state_entry() {
203 // DEBUG 201 // DEBUG
204 llOwnerSay("[Dice] Waiting for group messages..."); 202 llOwnerSay("[Dice] Waiting for group messages...");
205 } 203 }
206 link_message(integer sender, integer num, string message, key id) { 204 link_message(integer sender, integer num, string message, key id) {
207 // We only care about notifications now. 205 // We only care about notifications now.
208 if(id != "notification") 206 if(id != "notification")
209 return; 207 return;
210 208  
211 // This script only processes group notifications. 209 // This script only processes group notifications.
212 if(wasKeyValueGet("type", message) != "group") 210 if(wasKeyValueGet("type", message) != "group" ||
-   211 (wasKeyValueGet("type", message) == "group" &&
-   212 wasURLUnescape(wasKeyValueGet("group", message)) !=
-   213 wasKeyValueGet("group", configuration)))
213 return; 214 return;
214 215  
215 // Get the sent message. 216 // Get the sent message.
216 data = wasURLUnescape( 217 data = wasURLUnescape(
217 wasKeyValueGet( 218 wasKeyValueGet(
218 "message", 219 "message",
219 message 220 message
220 ) 221 )
221 ); 222 );
222 223  
223 // Check if this is an eggdrop command. 224 // Check if this is an eggdrop command.
224 if(llGetSubString(data, 0, 0) != 225 if(llGetSubString(data, 0, 0) !=
225 wasKeyValueGet("command", configuration)) 226 wasKeyValueGet("command", configuration))
226 return; 227 return;
227 228  
228 // Check if the command matches the current module. 229 // Check if the command matches the current module.
229 list command = llParseString2List(data, [" "], []); 230 list command = llParseString2List(data, [" "], []);
230 if(llList2String(command, 0) != 231 if(llList2String(command, 0) !=
231 wasKeyValueGet("command", configuration) + "roll") 232 wasKeyValueGet("command", configuration) + "roll")
232 return; 233 return;
233 234  
234 // Remove command. 235 // Remove command.
235 command = llDeleteSubList(command, 0, 0); 236 command = llDeleteSubList(command, 0, 0);
236 237  
237 list range = wasCSVToList( 238 list range = wasCSVToList(
238 wasKeyValueGet("roll range", configuration) 239 wasKeyValueGet("roll range", configuration)
239 ); 240 );
240 241  
241 integer roll = llList2Integer(command, 0); 242 integer roll = llList2Integer(command, 0);
242 if(roll < llList2Integer(range, 0) || roll > llList2Integer(range, 1)) { 243 if(roll < llList2Integer(range, 0) || roll > llList2Integer(range, 1)) {
243 data = "Value should be within bounds [" + 244 data = "Value should be within bounds [" +
244 llList2String(range, 0) + 245 llList2String(range, 0) +
245 "," + 246 "," +
246 llList2String(range, 1) + 247 llList2String(range, 1) +
247 "]."; 248 "].";
248 state tell; 249 state tell;
249 } 250 }
250 251  
251 data = wasKeyValueGet( 252 data = wasKeyValueGet(
252 "firstname", 253 "firstname",
253 message 254 message
254 ) + 255 ) +
255 " " + 256 " " +
256 wasKeyValueGet( 257 wasKeyValueGet(
257 "lastname", 258 "lastname",
258 message 259 message
259 ) + " rolls a " + 260 ) + " rolls a " +
260 (string)((integer)(llFrand(roll + 1))); 261 (string)((integer)(llFrand(roll + 1)));
261 262  
262 state tell; 263 state tell;
263 } 264 }
264 on_rez(integer num) { 265 on_rez(integer num) {
265 llResetScript(); 266 llResetScript();
266 } 267 }
267 changed(integer change) { 268 changed(integer change) {
268 if((change & CHANGED_INVENTORY) || 269 if((change & CHANGED_INVENTORY) ||
269 (change & CHANGED_REGION_START) || 270 (change & CHANGED_REGION_START) ||
270 (change & CHANGED_OWNER)) { 271 (change & CHANGED_OWNER)) {
271 llResetScript(); 272 llResetScript();
272 } 273 }
273 } 274 }
274 } 275 }
275   276  
276 state tell { 277 state tell {
277 state_entry() { 278 state_entry() {
278 // DEBUG 279 // DEBUG
279 llOwnerSay("[Dice] Sending to group."); 280 llOwnerSay("[Dice] Sending to group.");
280 llInstantMessage( 281 llInstantMessage(
281 wasKeyValueGet( 282 wasKeyValueGet(
282 "corrade", 283 "corrade",
283 configuration 284 configuration
284 ), 285 ),
285 wasKeyValueEncode( 286 wasKeyValueEncode(
286 [ 287 [
287 "command", "tell", 288 "command", "tell",
288 "group", wasURLEscape( 289 "group", wasURLEscape(
289 wasKeyValueGet( 290 wasKeyValueGet(
290 "group", 291 "group",
291 configuration 292 configuration
292 ) 293 )
293 ), 294 ),
294 "password", wasURLEscape( 295 "password", wasURLEscape(
295 wasKeyValueGet( 296 wasKeyValueGet(
296 "password", 297 "password",
297 configuration 298 configuration
298 ) 299 )
299 ), 300 ),
300 "entity", "group", 301 "entity", "group",
301 "message", wasURLEscape(data) 302 "message", wasURLEscape(data)
302 ] 303 ]
303 ) 304 )
304 ); 305 );
305 state listen_group; 306 state listen_group;
306 } 307 }
307 } 308 }
308   309