corrade-lsl-templates – Diff between revs 5 and 29
?pathlinks?
Rev 5 | Rev 29 | |||
---|---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: CC BY 2.0 // |
|
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
3 | // Please see: https://creativecommons.org/licenses/by/2.0 for legal details, // |
|
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
|
5 | /////////////////////////////////////////////////////////////////////////// |
5 | /////////////////////////////////////////////////////////////////////////// |
|
6 | |
6 | |
|
7 | /////////////////////////////////////////////////////////////////////////// |
7 | /////////////////////////////////////////////////////////////////////////// |
|
8 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
8 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
|
9 | /////////////////////////////////////////////////////////////////////////// |
9 | /////////////////////////////////////////////////////////////////////////// |
|
10 | // escapes a string in conformance with RFC1738 |
10 | // escapes a string in conformance with RFC1738 |
|
11 | string wasURLEscape(string i) { |
11 | string wasURLEscape(string i) { |
|
12 | string o = ""; |
12 | string o = ""; |
|
13 | do { |
13 | do { |
|
14 | string c = llGetSubString(i, 0, 0); |
14 | string c = llGetSubString(i, 0, 0); |
|
15 | i = llDeleteSubString(i, 0, 0); |
15 | i = llDeleteSubString(i, 0, 0); |
|
16 | if(c == "") jump continue; |
16 | if(c == "") jump continue; |
|
17 | if(c == " ") { |
17 | if(c == " ") { |
|
18 | o += "+"; |
18 | o += "+"; |
|
19 | jump continue; |
19 | jump continue; |
|
20 | } |
20 | } |
|
21 | if(c == "\n") { |
21 | if(c == "\n") { |
|
22 | o += "%0D" + llEscapeURL(c); |
22 | o += "%0D" + llEscapeURL(c); |
|
23 | jump continue; |
23 | jump continue; |
|
24 | } |
24 | } |
|
25 | o += llEscapeURL(c); |
25 | o += llEscapeURL(c); |
|
26 | @continue; |
26 | @continue; |
|
27 | } while(i != ""); |
27 | } while(i != ""); |
|
28 | return o; |
28 | return o; |
|
29 | } |
29 | } |
|
30 | |
30 | |
|
31 | /////////////////////////////////////////////////////////////////////////// |
31 | /////////////////////////////////////////////////////////////////////////// |
|
32 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
32 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
|
33 | /////////////////////////////////////////////////////////////////////////// |
33 | /////////////////////////////////////////////////////////////////////////// |
|
34 | string wasKeyValueEncode(list data) { |
34 | string wasKeyValueEncode(list data) { |
|
35 | list k = llList2ListStrided(data, 0, -1, 2); |
35 | list k = llList2ListStrided(data, 0, -1, 2); |
|
36 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
36 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
|
37 | data = []; |
37 | data = []; |
|
38 | do { |
38 | do { |
|
39 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
39 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
|
40 | k = llDeleteSubList(k, 0, 0); |
40 | k = llDeleteSubList(k, 0, 0); |
|
41 | v = llDeleteSubList(v, 0, 0); |
41 | v = llDeleteSubList(v, 0, 0); |
|
42 | } while(llGetListLength(k) != 0); |
42 | } while(llGetListLength(k) != 0); |
|
43 | return llDumpList2String(data, "&"); |
43 | return llDumpList2String(data, "&"); |
|
44 | } |
44 | } |
|
45 | |
45 | |
|
46 | // Temporary storage for notecard lines. |
46 | // Temporary storage for notecard lines. |
|
47 | integer f; |
47 | integer f; |
|
48 | string say; |
48 | string say; |
|
49 | |
49 | |
|
50 | // Corrade data |
50 | // Corrade data |
|
51 | string CORRADE = ""; |
51 | string CORRADE = ""; |
|
52 | string GROUP = ""; |
52 | string GROUP = ""; |
|
53 | string PASSWORD = ""; |
53 | string PASSWORD = ""; |
|
54 | integer INTERVAL = 21600; |
54 | integer INTERVAL = 21600; |
|
55 | |
55 | |
|
56 | // For notecard reading |
56 | // For notecard reading |
|
57 | integer line = 0; |
57 | integer line = 0; |
|
58 | |
58 | |
|
59 | // Key-value data will be read into this list |
59 | // Key-value data will be read into this list |
|
60 | list tuples = []; |
60 | list tuples = []; |
|
61 | |
61 | |
|
62 | default { |
62 | default { |
|
63 | state_entry() { |
63 | state_entry() { |
|
64 | if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) { |
64 | if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) { |
|
65 | llOwnerSay("Sorry, could not find an inventory notecard."); |
65 | llOwnerSay("Sorry, could not find an inventory notecard."); |
|
66 | return; |
66 | return; |
|
67 | } |
67 | } |
|
68 | // DEBUG |
68 | // DEBUG |
|
69 | llOwnerSay("Reading configuration file..."); |
69 | llOwnerSay("Reading configuration file..."); |
|
70 | llGetNotecardLine("configuration", line); |
70 | llGetNotecardLine("configuration", line); |
|
71 | } |
71 | } |
|
72 | dataserver(key id, string data) { |
72 | dataserver(key id, string data) { |
|
73 | if(data == EOF) { |
73 | if(data == EOF) { |
|
74 | // invariant, length(tuples) % 2 == 0 |
74 | // invariant, length(tuples) % 2 == 0 |
|
75 | if(llGetListLength(tuples) % 2 != 0) { |
75 | if(llGetListLength(tuples) % 2 != 0) { |
|
76 | llOwnerSay("Error in configuration notecard."); |
76 | llOwnerSay("Error in configuration notecard."); |
|
77 | return; |
77 | return; |
|
78 | } |
78 | } |
|
79 | CORRADE = llList2String( |
79 | CORRADE = llList2String( |
|
80 | tuples, |
80 | tuples, |
|
81 | llListFindList( |
81 | llListFindList( |
|
82 | tuples, |
82 | tuples, |
|
83 | [ |
83 | [ |
|
84 | "corrade" |
84 | "corrade" |
|
85 | ] |
85 | ] |
|
86 | ) |
86 | ) |
|
87 | +1); |
87 | +1); |
|
88 | if(CORRADE == "") { |
88 | if(CORRADE == "") { |
|
89 | llOwnerSay("Error in configuration notecard: corrade"); |
89 | llOwnerSay("Error in configuration notecard: corrade"); |
|
90 | return; |
90 | return; |
|
91 | } |
91 | } |
|
92 | GROUP = llList2String( |
92 | GROUP = llList2String( |
|
93 | tuples, |
93 | tuples, |
|
94 | llListFindList( |
94 | llListFindList( |
|
95 | tuples, |
95 | tuples, |
|
96 | [ |
96 | [ |
|
97 | "group" |
97 | "group" |
|
98 | ] |
98 | ] |
|
99 | ) |
99 | ) |
|
100 | +1); |
100 | +1); |
|
101 | if(GROUP == "") { |
101 | if(GROUP == "") { |
|
102 | llOwnerSay("Error in configuration notecard: group"); |
102 | llOwnerSay("Error in configuration notecard: group"); |
|
103 | return; |
103 | return; |
|
104 | } |
104 | } |
|
105 | PASSWORD = llList2String( |
105 | PASSWORD = llList2String( |
|
106 | tuples, |
106 | tuples, |
|
107 | llListFindList( |
107 | llListFindList( |
|
108 | tuples, |
108 | tuples, |
|
109 | [ |
109 | [ |
|
110 | "password" |
110 | "password" |
|
111 | ] |
111 | ] |
|
112 | ) |
112 | ) |
|
113 | +1); |
113 | +1); |
|
114 | if(PASSWORD == "") { |
114 | if(PASSWORD == "") { |
|
115 | llOwnerSay("Error in configuration notecard: password"); |
115 | llOwnerSay("Error in configuration notecard: password"); |
|
116 | return; |
116 | return; |
|
117 | } |
117 | } |
|
118 | INTERVAL = llList2Integer( |
118 | INTERVAL = llList2Integer( |
|
119 | tuples, |
119 | tuples, |
|
120 | llListFindList( |
120 | llListFindList( |
|
121 | tuples, |
121 | tuples, |
|
122 | [ |
122 | [ |
|
123 | "interval" |
123 | "interval" |
|
124 | ] |
124 | ] |
|
125 | ) |
125 | ) |
|
126 | +1); |
126 | +1); |
|
127 | if(INTERVAL == 0) { |
127 | if(INTERVAL == 0) { |
|
128 | llOwnerSay("Error in configuration notecard: interval"); |
128 | llOwnerSay("Error in configuration notecard: interval"); |
|
129 | return; |
129 | return; |
|
130 | } |
130 | } |
|
131 | // DEBUG |
131 | // DEBUG |
|
132 | llOwnerSay("Read configuration file..."); |
132 | llOwnerSay("Read configuration file..."); |
|
133 | state fortune; |
133 | state fortune; |
|
134 | } |
134 | } |
|
135 | if(data == "") jump continue; |
135 | if(data == "") jump continue; |
|
136 | integer i = llSubStringIndex(data, "#"); |
136 | integer i = llSubStringIndex(data, "#"); |
|
137 | if(i != -1) data = llDeleteSubString(data, i, -1); |
137 | if(i != -1) data = llDeleteSubString(data, i, -1); |
|
138 | list o = llParseString2List(data, ["="], []); |
138 | list o = llParseString2List(data, ["="], []); |
|
139 | // get rid of starting and ending quotes |
139 | // get rid of starting and ending quotes |
|
140 | string k = llDumpList2String( |
140 | string k = llDumpList2String( |
|
141 | llParseString2List( |
141 | llParseString2List( |
|
142 | llStringTrim( |
142 | llStringTrim( |
|
143 | llList2String( |
143 | llList2String( |
|
144 | o, |
144 | o, |
|
145 | 0 |
145 | 0 |
|
146 | ), |
146 | ), |
|
147 | STRING_TRIM), |
147 | STRING_TRIM), |
|
148 | ["\""], [] |
148 | ["\""], [] |
|
149 | ), "\""); |
149 | ), "\""); |
|
150 | string v = llDumpList2String( |
150 | string v = llDumpList2String( |
|
151 | llParseString2List( |
151 | llParseString2List( |
|
152 | llStringTrim( |
152 | llStringTrim( |
|
153 | llList2String( |
153 | llList2String( |
|
154 | o, |
154 | o, |
|
155 | 1 |
155 | 1 |
|
156 | ), |
156 | ), |
|
157 | STRING_TRIM), |
157 | STRING_TRIM), |
|
158 | ["\""], [] |
158 | ["\""], [] |
|
159 | ), "\""); |
159 | ), "\""); |
|
160 | if(k == "" || v == "") jump continue; |
160 | if(k == "" || v == "") jump continue; |
|
161 | tuples += k; |
161 | tuples += k; |
|
162 | tuples += v; |
162 | tuples += v; |
|
163 | @continue; |
163 | @continue; |
|
164 | llGetNotecardLine("configuration", ++line); |
164 | llGetNotecardLine("configuration", ++line); |
|
165 | } |
165 | } |
|
166 | on_rez(integer num) { |
166 | on_rez(integer num) { |
|
167 | llResetScript(); |
167 | llResetScript(); |
|
168 | } |
168 | } |
|
169 | changed(integer change) { |
169 | changed(integer change) { |
|
170 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
170 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
|
171 | llResetScript(); |
171 | llResetScript(); |
|
172 | } |
172 | } |
|
173 | } |
173 | } |
|
174 | } |
174 | } |
|
175 | |
175 | |
|
176 | state fortune { |
176 | state fortune { |
|
177 | state_entry() { |
177 | state_entry() { |
|
178 | if(llGetInventoryType("Fortunes") == INVENTORY_NOTECARD) jump schedule; |
178 | if(llGetInventoryType("Fortunes") == INVENTORY_NOTECARD) jump schedule; |
|
179 | llSay(DEBUG_CHANNEL, "Fortunes notecard not found."); |
179 | llSay(DEBUG_CHANNEL, "Fortunes notecard not found."); |
|
180 | return; |
180 | return; |
|
181 | @schedule; |
181 | @schedule; |
|
182 | llGetNumberOfNotecardLines("Fortunes"); |
182 | llGetNumberOfNotecardLines("Fortunes"); |
|
183 | } |
183 | } |
|
184 | dataserver(key requested, string data) { |
184 | dataserver(key requested, string data) { |
|
185 | f=(integer)data; |
185 | f=(integer)data; |
|
186 | llOwnerSay("Ready, sleeping..."); |
186 | llOwnerSay("Ready, sleeping..."); |
|
187 | state quote; |
187 | state quote; |
|
188 | } |
188 | } |
|
189 | on_rez(integer num) { |
189 | on_rez(integer num) { |
|
190 | llResetScript(); |
190 | llResetScript(); |
|
191 | } |
191 | } |
|
192 | changed(integer change) { |
192 | changed(integer change) { |
|
193 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
193 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
|
194 | llResetScript(); |
194 | llResetScript(); |
|
195 | } |
195 | } |
|
196 | } |
196 | } |
|
197 | } |
197 | } |
|
198 | |
198 | |
|
199 | state quote { |
199 | state quote { |
|
200 | state_entry() { |
200 | state_entry() { |
|
201 | llGetNotecardLine("Fortunes", (integer)llFrand(f)); |
201 | llGetNotecardLine("Fortunes", (integer)llFrand(f)); |
|
202 | } |
202 | } |
|
203 | timer() { |
203 | timer() { |
|
204 | state speak; |
204 | state speak; |
|
205 | } |
205 | } |
|
206 | dataserver(key requested, string data) { |
206 | dataserver(key requested, string data) { |
|
207 | say = data; |
207 | say = data; |
|
208 | llSetTimerEvent(1 + llFrand(INTERVAL)); |
208 | llSetTimerEvent(1 + llFrand(INTERVAL)); |
|
209 | |
209 | |
|
210 | } |
210 | } |
|
211 | on_rez(integer num) { |
211 | on_rez(integer num) { |
|
212 | llResetScript(); |
212 | llResetScript(); |
|
213 | } |
213 | } |
|
214 | changed(integer change) { |
214 | changed(integer change) { |
|
215 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
215 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
|
216 | llResetScript(); |
216 | llResetScript(); |
|
217 | } |
217 | } |
|
218 | } |
218 | } |
|
219 | state_exit() { |
219 | state_exit() { |
|
220 | llSetTimerEvent(0); |
220 | llSetTimerEvent(0); |
|
221 | } |
221 | } |
|
222 | } |
222 | } |
|
223 | |
223 | |
|
224 | state speak { |
224 | state speak { |
|
225 | state_entry() { |
225 | state_entry() { |
|
226 | llInstantMessage(CORRADE, |
226 | llInstantMessage(CORRADE, |
|
227 | wasKeyValueEncode( |
227 | wasKeyValueEncode( |
|
228 | [ |
228 | [ |
|
229 | "command", "tell", |
229 | "command", "tell", |
|
230 | "group", wasURLEscape(GROUP), |
230 | "group", wasURLEscape(GROUP), |
|
231 | "password", wasURLEscape(PASSWORD), |
231 | "password", wasURLEscape(PASSWORD), |
|
232 | "entity", "group", |
232 | "entity", "group", |
|
233 | "message", wasURLEscape(say) |
233 | "message", wasURLEscape(say) |
|
234 | ] |
234 | ] |
|
235 | ) |
235 | ) |
|
236 | ); |
236 | ); |
|
237 | llSetTimerEvent(1); |
237 | llSetTimerEvent(1); |
|
238 | } |
238 | } |
|
239 | timer() { |
239 | timer() { |
|
240 | state quote; |
240 | state quote; |
|
241 | } |
241 | } |
|
242 | on_rez(integer num) { |
242 | on_rez(integer num) { |
|
243 | llResetScript(); |
243 | llResetScript(); |
|
244 | } |
244 | } |
|
245 | changed(integer change) { |
245 | changed(integer change) { |
|
246 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
246 | if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { |
|
247 | llResetScript(); |
247 | llResetScript(); |
|
248 | } |
248 | } |
|
249 | } |
249 | } |
|
250 | state_exit() { |
250 | state_exit() { |
|
251 | llSetTimerEvent(0); |
251 | llSetTimerEvent(0); |
|
252 | } |
252 | } |
|
253 | } |
253 | } |
|
254 | |
254 | |