corrade-lsl-templates – Blame information for rev 42

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 makes Corrade sit on the ground.
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 // callback URL
64 string callback = "";
65  
66 // configuration data
67 string configuration = "";
68  
69 default {
70 state_entry() {
71 llSetTimerEvent(1);
72 }
73 link_message(integer sender, integer num, string message, key id) {
74 if(sender != 1 || id != "configuration") return;
75 configuration = message;
76 state off;
77 }
78 timer() {
79 llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY);
80 }
81 attach(key id) {
82 llResetScript();
83 }
84 on_rez(integer num) {
85 llResetScript();
86 }
87 changed(integer change) {
88 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
89 llResetScript();
90 }
91 }
92 state_exit() {
93 llSetTimerEvent(0);
94 }
95 }
96  
97 state off {
98 state_entry() {
99 llReleaseControls();
100 llSetColor(<.5,0,0>, ALL_SIDES);
101 }
102 touch_end(integer num) {
103 state on;
104 }
105 attach(key id) {
106 llResetScript();
107 }
108 on_rez(integer num) {
109 llResetScript();
110 }
111 changed(integer change) {
112 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
113 llResetScript();
114 }
115 }
116 }
117  
118 state on {
119 state_entry() {
120 llSetColor(<0,.5,0>, ALL_SIDES);
121 state url;
122 }
123 attach(key id) {
124 llResetScript();
125 }
126 on_rez(integer num) {
127 llResetScript();
128 }
129 changed(integer change) {
130 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
131 llResetScript();
132 }
133 }
134 }
135  
136 state url {
137 state_entry() {
138 // DEBUG
139 llOwnerSay("Requesting URL...");
140 llRequestURL();
141 }
142 touch_end(integer num) {
143 llSetColor(<.5,0,0>, ALL_SIDES);
144 llResetScript();
145 }
146 http_request(key id, string method, string body) {
147 if(method != URL_REQUEST_GRANTED) return;
148 callback = body;
149 // DEBUG
150 llOwnerSay("Got URL...");
151 state relax;
152 }
153 attach(key id) {
154 llResetScript();
155 }
156 on_rez(integer num) {
157 llResetScript();
158 }
159 changed(integer change) {
160 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
161 llResetScript();
162 }
163 }
164 }
165  
166 state relax {
167 state_entry() {
168 // DEBUG
169 llOwnerSay("Relaxing...");
170 llInstantMessage(
171 (key)wasKeyValueGet(
172 "corrade",
173 configuration
174 ),
175 wasKeyValueEncode(
176 [
177 "command", "relax",
178 "group", wasURLEscape(
179 wasKeyValueGet(
180 "group",
181 configuration
182 )
183 ),
184 "password", wasURLEscape(
185 wasKeyValueGet(
186 "password",
187 configuration
188 )
189 ),
190 "callback", wasURLEscape(callback)
191 ]
192 )
193 );
194 llSetTimerEvent(60);
195 }
196 timer() {
197 // DEBUG
198 llOwnerSay("Relax failed...");
199 llSetColor(<.5,0,0>, ALL_SIDES);
200 llResetScript();
201 }
202 touch_end(integer num) {
203 llSetColor(<.5,0,0>, ALL_SIDES);
204 llResetScript();
205 }
206 http_request(key id, string method, string body) {
207 llHTTPResponse(id, 200, "OK");
208 if(wasKeyValueGet("command", body) != "relax" ||
209 wasKeyValueGet("success", body) != "True") {
210 // DEBUG
211 llOwnerSay("Relax failed...");
212 llSetColor(<.5,0,0>, ALL_SIDES);
213 llResetScript();
214 }
215 // DEBUG
216 llOwnerSay("Relax succeeded...");
217 llSetColor(<.5,0,0>, ALL_SIDES);
218 llResetScript();
219 }
220 attach(key id) {
221 llResetScript();
222 }
223 on_rez(integer num) {
224 llResetScript();
225 }
226 changed(integer change) {
227 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
228 llResetScript();
229 }
230 }
231 state_exit() {
232 llSetTimerEvent(0);
233 }
234 }