corrade-lsl-templates – Diff between revs 5 and 29

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