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