corrade-lsl-templates – Blame information for rev 29

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 ///////////////////////////////////////////////////////////////////////////
29 office 2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
2 office 3 ///////////////////////////////////////////////////////////////////////////
4 //
5 // This button will send Corrade home to its set home location.
6 //
7 // For more information on Corrade, please see:
8 // http://grimore.org/secondlife/scripted_agents/corrade
9 //
10 ///////////////////////////////////////////////////////////////////////////
11  
12 ///////////////////////////////////////////////////////////////////////////
29 office 13 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 14 ///////////////////////////////////////////////////////////////////////////
15 string wasKeyValueGet(string k, string data) {
16 if(llStringLength(data) == 0) return "";
17 if(llStringLength(k) == 0) return "";
18 list a = llParseString2List(data, ["&", "="], []);
19 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
20 if(i != -1) return llList2String(a, 2*i+1);
21 return "";
22 }
23  
24 ///////////////////////////////////////////////////////////////////////////
29 office 25 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 26 ///////////////////////////////////////////////////////////////////////////
27 string wasKeyValueEncode(list data) {
28 list k = llList2ListStrided(data, 0, -1, 2);
29 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
30 data = [];
31 do {
32 data += llList2String(k, 0) + "=" + llList2String(v, 0);
33 k = llDeleteSubList(k, 0, 0);
34 v = llDeleteSubList(v, 0, 0);
35 } while(llGetListLength(k) != 0);
36 return llDumpList2String(data, "&");
37 }
38  
39 ///////////////////////////////////////////////////////////////////////////
29 office 40 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 41 ///////////////////////////////////////////////////////////////////////////
42 // escapes a string in conformance with RFC1738
43 string wasURLEscape(string i) {
44 string o = "";
45 do {
46 string c = llGetSubString(i, 0, 0);
47 i = llDeleteSubString(i, 0, 0);
48 if(c == "") jump continue;
49 if(c == " ") {
50 o += "+";
51 jump continue;
52 }
53 if(c == "\n") {
54 o += "%0D" + llEscapeURL(c);
55 jump continue;
56 }
57 o += llEscapeURL(c);
58 @continue;
59 } while(i != "");
60 return o;
61 }
62  
63 ///////////////////////////////////////////////////////////////////////////
29 office 64 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 65 ///////////////////////////////////////////////////////////////////////////
66 list wasCSVToList(string csv) {
67 list l = [];
68 list s = [];
69 string m = "";
70 do {
71 string a = llGetSubString(csv, 0, 0);
72 csv = llDeleteSubString(csv, 0, 0);
73 if(a == ",") {
74 if(llList2String(s, -1) != "\"") {
75 l += m;
76 m = "";
77 jump continue;
78 }
79 m += a;
80 jump continue;
81 }
82 if(a == "\"" && llGetSubString(csv, 0, 0) == a) {
83 m += a;
84 csv = llDeleteSubString(csv, 0, 0);
85 jump continue;
86 }
87 if(a == "\"") {
88 if(llList2String(s, -1) != a) {
89 s += a;
90 jump continue;
91 }
92 s = llDeleteSubList(s, -1, -1);
93 jump continue;
94 }
95 m += a;
96 @continue;
97 } while(csv != "");
98 // postcondition: length(s) = 0
99 return l + m;
100 }
101  
102 ///////////////////////////////////////////////////////////////////////////
29 office 103 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 104 ///////////////////////////////////////////////////////////////////////////
105 // unescapes a string in conformance with RFC1738
106 string wasURLUnescape(string i) {
107 return llUnescapeURL(
108 llDumpList2String(
109 llParseString2List(
110 llDumpList2String(
111 llParseString2List(
112 i,
113 ["+"],
114 []
115 ),
116 " "
117 ),
118 ["%0D%0A"],
119 []
120 ),
121 "\n"
122 )
123 );
124 }
125  
126 // callback URL
127 string callback = "";
128 // configuration data
129 string configuration = "";
130  
131 default {
132 state_entry() {
133 llSetTimerEvent(1);
134 }
135 link_message(integer sender, integer num, string message, key id) {
136 if(sender != 1 || id != "configuration") return;
137 configuration = message;
138 state off;
139 }
140 timer() {
141 llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY);
142 }
143 on_rez(integer num) {
144 llResetScript();
145 }
146 attach(key id) {
147 llResetScript();
148 }
149 changed(integer change) {
150 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
151 llResetScript();
152 }
153 }
154 state_exit() {
155 llSetTimerEvent(0);
156 }
157 }
158  
159 state off {
160 state_entry() {
161 llReleaseControls();
162 llSetColor(<.5,0,0>, ALL_SIDES);
163 }
164 touch_end(integer num) {
165 state on;
166 }
167 attach(key id) {
168 llResetScript();
169 }
170 on_rez(integer num) {
171 llResetScript();
172 }
173 changed(integer change) {
174 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
175 llResetScript();
176 }
177 }
178 }
179  
180 state on {
181 state_entry() {
182 llSetColor(<0,.5,0>, ALL_SIDES);
183 state url;
184 }
185 attach(key id) {
186 llResetScript();
187 }
188 on_rez(integer num) {
189 llResetScript();
190 }
191 changed(integer change) {
192 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
193 llResetScript();
194 }
195 }
196 }
197  
198 state url {
199 state_entry() {
200 // DEBUG
201 llOwnerSay("Requesting URL...");
202 llRequestURL();
203 }
204 touch_end(integer num) {
205 llSetColor(<.5,0,0>, ALL_SIDES);
206 llResetScript();
207 }
208 http_request(key id, string method, string body) {
209 if(method != URL_REQUEST_GRANTED) return;
210 callback = body;
211 // DEBUG
212 llOwnerSay("Got URL...");
213 state home;
214 }
215 attach(key id) {
216 llResetScript();
217 }
218 on_rez(integer num) {
219 llResetScript();
220 }
221 changed(integer change) {
222 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
223 llResetScript();
224 }
225 }
226 }
227  
228 state home {
229 state_entry() {
230 llInstantMessage(
231 wasKeyValueGet(
232 "corrade",
233 configuration
234 ),
235 wasKeyValueEncode(
236 [
237 "command", "gohome",
238 "group", wasURLEscape(
239 wasKeyValueGet(
240 "group",
241 configuration
242 )
243 ),
244 "password", wasURLEscape(
245 wasKeyValueGet(
246 "password",
247 configuration
248 )
249 ),
250 "callback", wasURLEscape(callback)
251 ]
252 )
253 );
254 }
255 http_request(key id, string method, string body) {
256 llHTTPResponse(id, 200, "OK");
257 if(wasKeyValueGet("command", body) != "gohome" ||
258 wasKeyValueGet("success", body) != "True") {
259 // DEBUG
260 llOwnerSay("Go home failed...");
261 llResetScript();
262 }
263 // DEBUG
264 llOwnerSay("Go home succeeded...");
265 llResetScript();
266 }
267 attach(key id) {
268 llResetScript();
269 }
270 on_rez(integer num) {
271 llResetScript();
272 }
273 changed(integer change) {
274 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
275 llResetScript();
276 }
277 }
278 }