clockwerk-www – Blame information for rev 5
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
5 | vero | 1 | <?php |
2 | # |
||
3 | # Copyright (c)Melanie Thielker and Teravus Ovares (http://opensimulator.org/) |
||
4 | # |
||
5 | # Redistribution and use in source and binary forms, with or without |
||
6 | # modification, are permitted provided that the following conditions are met: |
||
7 | # * Redistributions of source code must retain the above copyright |
||
8 | # notice, this list of conditions and the following disclaimer. |
||
9 | # * Redistributions in binary form must reproduce the above copyright |
||
10 | # notice, this list of conditions and the following disclaimer in the |
||
11 | # documentation and/or other materials provided with the distribution. |
||
12 | # * Neither the name of the OpenSim Project nor the |
||
13 | # names of its contributors may be used to endorse or promote products |
||
14 | # derived FROM this software without specific prior written permission. |
||
15 | # |
||
16 | # THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | # DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | # |
||
27 | |||
28 | ######################################################################## |
||
29 | # This file enables buying currency in the client. |
||
30 | # |
||
31 | # For this to work, the all clients using currency need to add |
||
32 | # |
||
33 | # -helperURI <WebpathToThisDirectory> |
||
34 | # |
||
35 | # to the commandline parameters when starting the client! |
||
36 | # |
||
37 | # Example: |
||
38 | # client.exe -loginuri http://foo.com:8002/ -helperuri http://foo.com/ |
||
39 | # |
||
40 | # Don't forget to change the currency conversion value in the wi_economy_money |
||
41 | # table! |
||
42 | # |
||
43 | # This requires PHP curl, XMLRPC, and MySQL extensions. |
||
44 | # |
||
45 | # If placed in the opensimwiredux web directory, it will share the db module |
||
46 | # |
||
47 | |||
48 | |||
49 | ######################################################################## |
||
50 | # |
||
51 | #ĦĦModified by Fumi.Iseki for XoopenSim/Modlos |
||
52 | # |
||
53 | |||
54 | require_once('../include/env_interface.php'); |
||
55 | require_once('./helpers.php'); |
||
56 | |||
57 | |||
58 | # |
||
59 | # The XMLRPC server object |
||
60 | # |
||
61 | |||
62 | $xmlrpc_server = xmlrpc_server_create(); |
||
63 | |||
64 | |||
65 | |||
66 | # |
||
67 | # Viewer retrieves currency buy quote |
||
68 | # |
||
69 | |||
70 | xmlrpc_server_register_method($xmlrpc_server, "getCurrencyQuote", "get_currency_quote"); |
||
71 | |||
72 | function get_currency_quote($method_name, $params, $app_data) |
||
73 | { |
||
74 | $req = $params[0]; |
||
75 | $agentid = $req['agentId']; |
||
76 | $sessionid = $req['secureSessionId']; |
||
77 | $amount = $req['currencyBuy']; |
||
78 | $ipAddress = $_SERVER['REMOTE_ADDR']; |
||
79 | |||
80 | $ret = opensim_check_secure_session($agentid, null, $sessionid); |
||
81 | |||
82 | if ($ret) { |
||
83 | $confirmvalue = get_confirm_value($ipAddress); |
||
84 | $cost = convert_to_real($amount); |
||
85 | $currency = array('estimatedCost'=> $cost, 'currencyBuy'=> $amount); |
||
86 | $response_xml = xmlrpc_encode(array('success' => True, |
||
87 | 'currency' => $currency, |
||
88 | 'confirm' => $confirmvalue)); |
||
89 | } |
||
90 | else { |
||
91 | $response_xml = xmlrpc_encode(array('success' => False, |
||
92 | 'errorMessage'=> "Unable to Authenticate\n\nClick URL for more info.", |
||
93 | 'errorURI' => "".SYSURL."")); |
||
94 | } |
||
95 | |||
96 | header("Content-type: text/xml"); |
||
97 | echo $response_xml; |
||
98 | |||
99 | return ""; |
||
100 | } |
||
101 | |||
102 | |||
103 | |||
104 | # |
||
105 | # Viewer buys currency |
||
106 | # |
||
107 | xmlrpc_server_register_method($xmlrpc_server, "buyCurrency", "buy_currency"); |
||
108 | |||
109 | function buy_currency($method_name, $params, $app_data) |
||
110 | { |
||
111 | $req = $params[0]; |
||
112 | $agentid = $req['agentId']; |
||
113 | $sessionid = $req['secureSessionId']; |
||
114 | $amount = $req['currencyBuy']; |
||
115 | $confim = $req['confirm']; |
||
116 | $ipAddress = $_SERVER['REMOTE_ADDR']; |
||
117 | |||
118 | // |
||
119 | if ($confim!=get_confirm_value($ipAddress)) { |
||
120 | $response_xml = xmlrpc_encode(array('success' => False, |
||
121 | 'errorMessage'=> "\n\nMissmatch Confirm Value!!", |
||
122 | 'errorURI' => "".SYSURL."")); |
||
123 | header("Content-type: text/xml"); |
||
124 | echo $response_xml; |
||
125 | return ""; |
||
126 | } |
||
127 | |||
128 | $checkSecure = opensim_check_secure_session($agentid, null, $sessionid); |
||
129 | if (!$checkSecure) { |
||
130 | $response_xml = xmlrpc_encode(array('success' => False, |
||
131 | 'errorMessage'=> "\n\nMissmatch Secure Session ID!!", |
||
132 | 'errorURI' => "".SYSURL."")); |
||
133 | header("Content-type: text/xml"); |
||
134 | echo $response_xml; |
||
135 | return ""; |
||
136 | } |
||
137 | |||
138 | $ret = false; |
||
139 | $cost = convert_to_real($amount); |
||
140 | $transactionPermit = process_transaction($agentid, $cost, $ipAddress); |
||
141 | |||
142 | if ($transactionPermit) { |
||
143 | $res = add_money($agentid, $amount, $sessionid); |
||
144 | if ($res["success"]) $ret = true; |
||
145 | } |
||
146 | |||
147 | if ($ret) { |
||
148 | $response_xml = xmlrpc_encode(array('success' => True)); |
||
149 | } |
||
150 | else { |
||
151 | $response_xml = xmlrpc_encode(array('success' => False, |
||
152 | 'errorMessage'=> "\n\nUnable to process the transaction. The gateway denied your charge", |
||
153 | 'errorURI' => "".SYSURL."")); |
||
154 | } |
||
155 | |||
156 | header("Content-type: text/xml"); |
||
157 | echo $response_xml; |
||
158 | |||
159 | return ""; |
||
160 | } |
||
161 | |||
162 | |||
163 | |||
164 | # |
||
165 | # Region requests account balance |
||
166 | # |
||
167 | |||
168 | xmlrpc_server_register_method($xmlrpc_server, "simulatorUserBalanceRequest", "balance_request"); |
||
169 | |||
170 | function balance_request($method_name, $params, $app_data) |
||
171 | { |
||
172 | $req = $params[0]; |
||
173 | $agentid = $req['agentId']; |
||
174 | $sessionid = $req['secureSessionId']; |
||
175 | |||
176 | $balance = get_balance($agentid, $sessionid); |
||
177 | |||
178 | if ($balance>=0) { |
||
179 | $response_xml = xmlrpc_encode(array('success' => True, |
||
180 | 'agentId' => $agentid, |
||
181 | 'funds' => $balance)); |
||
182 | } |
||
183 | else { |
||
184 | $response_xml = xmlrpc_encode(array('success' => False, |
||
185 | 'errorMessage'=> "Could not authenticate your avatar. Money operations may be unavailable", |
||
186 | 'errorURI' => " ")); |
||
187 | } |
||
188 | |||
189 | header("Content-type: text/xml"); |
||
190 | echo $response_xml; |
||
191 | |||
192 | return ""; |
||
193 | } |
||
194 | |||
195 | |||
196 | |||
197 | # |
||
198 | # Region initiates money transfer (Direct DB Operation for security) |
||
199 | # |
||
200 | |||
201 | xmlrpc_server_register_method($xmlrpc_server, "regionMoveMoney", "region_move_money"); |
||
202 | |||
203 | function region_move_money($method_name, $params, $app_data) |
||
204 | { |
||
205 | $req = $params[0]; |
||
206 | $agentid = $req['agentId']; |
||
207 | $destid = $req['destId']; |
||
208 | $sessionid = $req['secureSessionId']; |
||
209 | $regionid = $req['regionId']; |
||
210 | $secret = $req['secret']; |
||
211 | $currencySecret = $req['currencySecret']; |
||
212 | $cash = $req['cash']; |
||
213 | $aggregatePermInventory = $req['aggregatePermInventory']; |
||
214 | $aggregatePermNextOwner = $req['aggregatePermNextOwner']; |
||
215 | $flags = $req['flags']; |
||
216 | $transactiontype = $req['transactionType']; |
||
217 | $description = $req['description']; |
||
218 | $ipAddress = $_SERVER['REMOTE_ADDR']; |
||
219 | |||
220 | $ret = opensim_check_region_secret($regionid, $secret); |
||
221 | |||
222 | if ($ret) { |
||
223 | $ret = opensim_check_secure_session($agentid, $regionid, $sessionid); |
||
224 | |||
225 | if ($ret) { |
||
226 | $balance = get_balance($agentid, $sessionid); |
||
227 | if ($balance >= $cash) { |
||
228 | move_money($agentid, $destid, $cash, $transactiontype, $flags, $description, |
||
229 | $aggregatePermInventory, $aggregatePermNextOwner, $ipAddress); |
||
230 | $sbalance = get_balance($agentid, $sessionid); |
||
231 | $dbalance = get_balance($destid); |
||
232 | |||
233 | $response_xml = xmlrpc_encode(array('success' => True, |
||
234 | 'agentId' => $agentid, |
||
235 | 'funds' => $balance, |
||
236 | 'funds2' => $balance, |
||
237 | 'currencySecret'=> " ")); |
||
238 | |||
239 | update_simulator_balance($agentid, $sbalance, $sessionid); |
||
240 | update_simulator_balance($destid, $dbalance); |
||
241 | } |
||
242 | else { |
||
243 | $response_xml = xmlrpc_encode(array('success' => False, |
||
244 | 'errorMessage'=> "You do not have sufficient funds for this purchase", |
||
245 | 'errorURI' => " ")); |
||
246 | } |
||
247 | } |
||
248 | else { |
||
249 | $response_xml = xmlrpc_encode(array('success' => False, |
||
250 | 'errorMessage'=> "Unable to authenticate avatar. Money operations may be unavailable", |
||
251 | 'errorURI' => " ")); |
||
252 | } |
||
253 | } |
||
254 | else { |
||
255 | $response_xml = xmlrpc_encode(array('success' => False, |
||
256 | 'errorMessage'=> "This region is not authorized to manage your money.", |
||
257 | 'errorURI' => " ")); |
||
258 | } |
||
259 | |||
260 | header("Content-type: text/xml"); |
||
261 | echo $response_xml; |
||
262 | |||
263 | return ""; |
||
264 | } |
||
265 | |||
266 | |||
267 | |||
268 | # |
||
269 | # Region claims user |
||
270 | # |
||
271 | |||
272 | xmlrpc_server_register_method($xmlrpc_server, "simulatorClaimUserRequest", "claimUser_func"); |
||
273 | |||
274 | function claimUser_func($method_name, $params, $app_data) |
||
275 | { |
||
276 | $req = $params[0]; |
||
277 | $agentid = $req['agentId']; |
||
278 | $sessionid = $req['secureSessionId']; |
||
279 | $regionid = $req['regionId']; |
||
280 | $secret = $req['secret']; |
||
281 | |||
282 | $ret = opensim_check_region_secret($regionid, $secret); |
||
283 | |||
284 | if ($ret) { |
||
285 | $ret = opensim_check_secure_session($agentid, null, $sessionid); |
||
286 | |||
287 | if ($ret) { |
||
288 | $ret = opensim_set_current_region($agentid, $regionid); |
||
289 | |||
290 | if ($ret) { |
||
291 | $balance = get_balance($agentid, $sessionid); |
||
292 | $response_xml = xmlrpc_encode(array('success' => True, |
||
293 | 'agentId' => $agentid, |
||
294 | 'funds' => $balance, |
||
295 | 'currencySecret'=> " ")); |
||
296 | } |
||
297 | else { |
||
298 | $response_xml = xmlrpc_encode(array('success' => False, |
||
299 | 'errorMessage'=> "Error occurred, when DB was updated.", |
||
300 | 'errorURI' => " ")); |
||
301 | } |
||
302 | } |
||
303 | else { |
||
304 | $response_xml = xmlrpc_encode(array('success' => False, |
||
305 | 'errorMessage'=> "Unable to authenticate avatar. Money operations may be unavailable.", |
||
306 | 'errorURI' => " ")); |
||
307 | } |
||
308 | } |
||
309 | else { |
||
310 | $response_xml = xmlrpc_encode(array('success' => False, |
||
311 | 'errorMessage'=> "This region is not authorized to manage your money.", |
||
312 | 'errorURI' => " ")); |
||
313 | } |
||
314 | |||
315 | header("Content-type: text/xml"); |
||
316 | echo $response_xml; |
||
317 | |||
318 | return ""; |
||
319 | } |
||
320 | |||
321 | |||
322 | |||
323 | |||
324 | # |
||
325 | # Process the request |
||
326 | # |
||
327 | |||
328 | $request_xml = $HTTP_RAW_POST_DATA; |
||
329 | //error_log("currency.php: ".$request_xml); |
||
330 | |||
331 | xmlrpc_server_call_method($xmlrpc_server, $request_xml, ''); |
||
332 | xmlrpc_server_destroy($xmlrpc_server); |
||
333 | |||
334 | ?> |