corrade-lsl-templates – Blame information for rev 31

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