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