corrade-lsl-templates – Diff between revs 5 and 29
?pathlinks?
Rev 5 | Rev 29 | |||
---|---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 // |
|
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
3 | // Please see: https://creativecommons.org/licenses/by/2.0 for legal details, // |
|
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
|
5 | /////////////////////////////////////////////////////////////////////////// |
5 | /////////////////////////////////////////////////////////////////////////// |
|
6 | |
6 | |
|
7 | /////////////////////////////////////////////////////////////////////////// |
7 | /////////////////////////////////////////////////////////////////////////// |
|
8 | // CONFIGURATION // |
8 | // CONFIGURATION // |
|
9 | /////////////////////////////////////////////////////////////////////////// |
9 | /////////////////////////////////////////////////////////////////////////// |
|
10 | // The UUID / Key of the scripted agent. |
10 | // The UUID / Key of the scripted agent. |
|
11 | string CORRADE = "63c44c23-9f46-4f0d-b00a-5b0e3180a015"; |
11 | string CORRADE = "63c44c23-9f46-4f0d-b00a-5b0e3180a015"; |
|
12 | // The name of the group to invite to. |
12 | // The name of the group to invite to. |
|
13 | string GROUP = "My Group"; |
13 | string GROUP = "My Group"; |
|
14 | // The password for that group in Corrade.ini. |
14 | // The password for that group in Corrade.ini. |
|
15 | string PASSWORD = "mypassword"; |
15 | string PASSWORD = "mypassword"; |
|
16 | |
16 | |
|
17 | /////////////////////////////////////////////////////////////////////////// |
17 | /////////////////////////////////////////////////////////////////////////// |
|
18 | // END CONFIGURATION // |
18 | // END CONFIGURATION // |
|
19 | /////////////////////////////////////////////////////////////////////////// |
19 | /////////////////////////////////////////////////////////////////////////// |
|
20 | |
20 | |
|
21 | /////////////////////////////////////////////////////////////////////////// |
21 | /////////////////////////////////////////////////////////////////////////// |
|
22 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
22 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
|
23 | /////////////////////////////////////////////////////////////////////////// |
23 | /////////////////////////////////////////////////////////////////////////// |
|
24 | string wasKeyValueGet(string k, string data) { |
24 | string wasKeyValueGet(string k, string data) { |
|
25 | if(llStringLength(data) == 0) return ""; |
25 | if(llStringLength(data) == 0) return ""; |
|
26 | if(llStringLength(k) == 0) return ""; |
26 | if(llStringLength(k) == 0) return ""; |
|
27 | list a = llParseString2List(data, ["&", "="], []); |
27 | list a = llParseString2List(data, ["&", "="], []); |
|
28 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
28 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
|
29 | if(i != -1) return llList2String(a, 2*i+1); |
29 | if(i != -1) return llList2String(a, 2*i+1); |
|
30 | return ""; |
30 | return ""; |
|
31 | } |
31 | } |
|
32 | |
32 | |
|
33 | /////////////////////////////////////////////////////////////////////////// |
33 | /////////////////////////////////////////////////////////////////////////// |
|
34 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
34 | // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // |
|
35 | /////////////////////////////////////////////////////////////////////////// |
35 | /////////////////////////////////////////////////////////////////////////// |
|
36 | string wasKeyValueSet(string k, string v, string data) { |
36 | string wasKeyValueSet(string k, string v, string data) { |
|
37 | if(llStringLength(k) == 0) return ""; |
37 | if(llStringLength(k) == 0) return ""; |
|
38 | if(llStringLength(v) == 0) return ""; |
38 | if(llStringLength(v) == 0) return ""; |
|
39 | if(llStringLength(data) == 0) return k + "=" + v; |
39 | if(llStringLength(data) == 0) return k + "=" + v; |
|
40 | integer i = llListFindList( |
40 | integer i = llListFindList( |
|
41 | llList2ListStrided( |
41 | llList2ListStrided( |
|
42 | llParseString2List(data, ["&", "="], []), |
42 | llParseString2List(data, ["&", "="], []), |
|
43 | 0, -1, 2 |
43 | 0, -1, 2 |
|
44 | ), |
44 | ), |
|
45 | [ k ]); |
45 | [ k ]); |
|
46 | if(i != -1) return llDumpList2String( |
46 | if(i != -1) return llDumpList2String( |
|
47 | llListReplaceList( |
47 | llListReplaceList( |
|
48 | llParseString2List(data, ["&"], []), |
48 | llParseString2List(data, ["&"], []), |
|
49 | [ k + "=" + v ], |
49 | [ k + "=" + v ], |
|
50 | i, i), |
50 | i, i), |
|
51 | "&"); |
51 | "&"); |
|
52 | return data + "&" + k + "=" + v; |
52 | return data + "&" + k + "=" + v; |
|
53 | } |
53 | } |
|
54 | |
54 | |
|
55 | /////////////////////////////////////////////////////////////////////////// |
55 | /////////////////////////////////////////////////////////////////////////// |
|
56 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
56 | // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
|
57 | /////////////////////////////////////////////////////////////////////////// |
57 | /////////////////////////////////////////////////////////////////////////// |
|
58 | string wasKeyValueEncode(list data) { |
58 | string wasKeyValueEncode(list data) { |
|
59 | list k = llList2ListStrided(data, 0, -1, 2); |
59 | list k = llList2ListStrided(data, 0, -1, 2); |
|
60 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
60 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
|
61 | data = []; |
61 | data = []; |
|
62 | do { |
62 | do { |
|
63 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
63 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
|
64 | k = llDeleteSubList(k, 0, 0); |
64 | k = llDeleteSubList(k, 0, 0); |
|
65 | v = llDeleteSubList(v, 0, 0); |
65 | v = llDeleteSubList(v, 0, 0); |
|
66 | } while(llGetListLength(k) != 0); |
66 | } while(llGetListLength(k) != 0); |
|
67 | return llDumpList2String(data, "&"); |
67 | return llDumpList2String(data, "&"); |
|
68 | } |
68 | } |
|
69 | |
69 | |
|
70 | /////////////////////////////////////////////////////////////////////////// |
70 | /////////////////////////////////////////////////////////////////////////// |
|
71 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
71 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
|
72 | /////////////////////////////////////////////////////////////////////////// |
72 | /////////////////////////////////////////////////////////////////////////// |
|
73 | // escapes a string in conformance with RFC1738 |
73 | // escapes a string in conformance with RFC1738 |
|
74 | string wasURLEscape(string i) { |
74 | string wasURLEscape(string i) { |
|
75 | string o = ""; |
75 | string o = ""; |
|
76 | do { |
76 | do { |
|
77 | string c = llGetSubString(i, 0, 0); |
77 | string c = llGetSubString(i, 0, 0); |
|
78 | i = llDeleteSubString(i, 0, 0); |
78 | i = llDeleteSubString(i, 0, 0); |
|
79 | if(c == "") jump continue; |
79 | if(c == "") jump continue; |
|
80 | if(c == " ") { |
80 | if(c == " ") { |
|
81 | o += "+"; |
81 | o += "+"; |
|
82 | jump continue; |
82 | jump continue; |
|
83 | } |
83 | } |
|
84 | if(c == "\n") { |
84 | if(c == "\n") { |
|
85 | o += "%0D" + llEscapeURL(c); |
85 | o += "%0D" + llEscapeURL(c); |
|
86 | jump continue; |
86 | jump continue; |
|
87 | } |
87 | } |
|
88 | o += llEscapeURL(c); |
88 | o += llEscapeURL(c); |
|
89 | @continue; |
89 | @continue; |
|
90 | } while(i != ""); |
90 | } while(i != ""); |
|
91 | return o; |
91 | return o; |
|
92 | } |
92 | } |
|
93 | |
93 | |
|
94 | /////////////////////////////////////////////////////////////////////////// |
94 | /////////////////////////////////////////////////////////////////////////// |
|
95 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
95 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
|
96 | /////////////////////////////////////////////////////////////////////////// |
96 | /////////////////////////////////////////////////////////////////////////// |
|
97 | // unescapes a string in conformance with RFC1738 |
97 | // unescapes a string in conformance with RFC1738 |
|
98 | string wasURLUnescape(string i) { |
98 | string wasURLUnescape(string i) { |
|
99 | return llUnescapeURL( |
99 | return llUnescapeURL( |
|
100 | llDumpList2String( |
100 | llDumpList2String( |
|
101 | llParseString2List( |
101 | llParseString2List( |
|
102 | llDumpList2String( |
102 | llDumpList2String( |
|
103 | llParseString2List( |
103 | llParseString2List( |
|
104 | i, |
104 | i, |
|
105 | ["+"], |
105 | ["+"], |
|
106 | [] |
106 | [] |
|
107 | ), |
107 | ), |
|
108 | " " |
108 | " " |
|
109 | ), |
109 | ), |
|
110 | ["%0D%0A"], |
110 | ["%0D%0A"], |
|
111 | [] |
111 | [] |
|
112 | ), |
112 | ), |
|
113 | "\n" |
113 | "\n" |
|
114 | ) |
114 | ) |
|
115 | ); |
115 | ); |
|
116 | } |
116 | } |
|
117 | |
117 | |
|
118 | // Store the URL for the callback. |
118 | // Store the URL for the callback. |
|
119 | string callback = ""; |
119 | string callback = ""; |
|
120 | |
120 | |
|
121 | default { |
121 | default { |
|
122 | state_entry() { |
122 | state_entry() { |
|
123 | // DEBUG |
123 | // DEBUG |
|
124 | llOwnerSay("Requesting URL..."); |
124 | llOwnerSay("Requesting URL..."); |
|
125 | llRequestURL(); |
125 | llRequestURL(); |
|
126 | } |
126 | } |
|
127 | http_request(key id, string method, string body) { |
127 | http_request(key id, string method, string body) { |
|
128 | if(method != URL_REQUEST_GRANTED) return; |
128 | if(method != URL_REQUEST_GRANTED) return; |
|
129 | callback = body; |
129 | callback = body; |
|
130 | // DEBUG |
130 | // DEBUG |
|
131 | llOwnerSay("Got URL..."); |
131 | llOwnerSay("Got URL..."); |
|
132 | state sleep; |
132 | state sleep; |
|
133 | } |
133 | } |
|
134 | on_rez(integer num) { |
134 | on_rez(integer num) { |
|
135 | llResetScript(); |
135 | llResetScript(); |
|
136 | } |
136 | } |
|
137 | changed(integer change) { |
137 | changed(integer change) { |
|
138 | if(change & CHANGED_REGION_START) { |
138 | if(change & CHANGED_REGION_START) { |
|
139 | llResetScript(); |
139 | llResetScript(); |
|
140 | } |
140 | } |
|
141 | } |
141 | } |
|
142 | } |
142 | } |
|
143 | |
143 | |
|
144 | state sleep { |
144 | state sleep { |
|
145 | state_entry() { |
145 | state_entry() { |
|
146 | // DEBUG |
146 | // DEBUG |
|
147 | llOwnerSay("Waiting for linked-message..."); |
147 | llOwnerSay("Waiting for linked-message..."); |
|
148 | } |
148 | } |
|
149 | link_message(integer sender, integer num, string message, key id) { |
149 | link_message(integer sender, integer num, string message, key id) { |
|
150 | list data = llCSV2List(message); |
150 | list data = llCSV2List(message); |
|
151 | // Build a partial key-value pair string with the data we know. |
151 | // Build a partial key-value pair string with the data we know. |
|
152 | string kvp = wasKeyValueEncode( |
152 | string kvp = wasKeyValueEncode( |
|
153 | [ |
153 | [ |
|
154 | "command", "notice", |
154 | "command", "notice", |
|
155 | "group", wasURLEscape(GROUP), |
155 | "group", wasURLEscape(GROUP), |
|
156 | "password", wasURLEscape(PASSWORD), |
156 | "password", wasURLEscape(PASSWORD), |
|
157 | "callback", wasURLEscape(callback) |
157 | "callback", wasURLEscape(callback) |
|
158 | ] |
158 | ] |
|
159 | ); |
159 | ); |
|
160 | // Add the subject if there is one. |
160 | // Add the subject if there is one. |
|
161 | string subject = llList2String(data, 0); |
161 | string subject = llList2String(data, 0); |
|
162 | if(subject != "") kvp = wasKeyValueSet("subject", wasURLEscape(subject), kvp); |
162 | if(subject != "") kvp = wasKeyValueSet("subject", wasURLEscape(subject), kvp); |
|
163 | // Add the message if there is one. |
163 | // Add the message if there is one. |
|
164 | message = llList2String(data, 1); |
164 | message = llList2String(data, 1); |
|
165 | if(message != "") kvp = wasKeyValueSet("message", wasURLEscape(message), kvp); |
165 | if(message != "") kvp = wasKeyValueSet("message", wasURLEscape(message), kvp); |
|
166 | // Add the attachment if there is one. |
166 | // Add the attachment if there is one. |
|
167 | string item = llList2String(data, 2); |
167 | string item = llList2String(data, 2); |
|
168 | if(item != "") kvp = wasKeyValueSet("item", wasURLEscape(item), kvp); |
168 | if(item != "") kvp = wasKeyValueSet("item", wasURLEscape(item), kvp); |
|
169 | // Send off the notice to Corrade. |
169 | // Send off the notice to Corrade. |
|
170 | llInstantMessage(CORRADE, kvp); |
170 | llInstantMessage(CORRADE, kvp); |
|
171 | } |
171 | } |
|
172 | http_request(key id, string method, string body) { |
172 | http_request(key id, string method, string body) { |
|
173 | llHTTPResponse(id, 200, "OK"); |
173 | llHTTPResponse(id, 200, "OK"); |
|
174 | // If sending the notice succeeded, do not complain... |
174 | // If sending the notice succeeded, do not complain... |
|
175 | if(wasKeyValueGet("command", body) == "notice" && |
175 | if(wasKeyValueGet("command", body) == "notice" && |
|
176 | wasKeyValueGet("success", body) == "True") return; |
176 | wasKeyValueGet("success", body) == "True") return; |
|
177 | // Announce the owner that sending the notice failed |
177 | // Announce the owner that sending the notice failed |
|
178 | llInstantMessage(llGetOwner(), "Failed to send the notice: " + wasURLUnescape(wasKeyValueGet("error", body))); |
178 | llInstantMessage(llGetOwner(), "Failed to send the notice: " + wasURLUnescape(wasKeyValueGet("error", body))); |
|
179 | } |
179 | } |
|
180 | on_rez(integer num) { |
180 | on_rez(integer num) { |
|
181 | llResetScript(); |
181 | llResetScript(); |
|
182 | } |
182 | } |
|
183 | changed(integer change) { |
183 | changed(integer change) { |
|
184 | if(change & CHANGED_REGION_START) { |
184 | if(change & CHANGED_REGION_START) { |
|
185 | llResetScript(); |
185 | llResetScript(); |
|
186 | } |
186 | } |
|
187 | } |
187 | } |
|
188 | } |
188 | } |
|
189 | |
189 | |