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