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