-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrency.php
382 lines (339 loc) · 10.2 KB
/
currency.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* currency.php
*
* Provides web tools for OpenSim currencies
*
* Requires an OpenSimulator Money Server
* [DTL/NSL Money Server for OpenSim](http://www.nsl.tuis.ac.jp/xoops/modules/xpwiki/?OpenSim%2FMoneyServer)
* or [Gloebit module](http://dev.gloebit.com/opensim/configuration-instructions/)
*
* @package magicoli/opensim-helpers
* @author Gudule Lapointe <gudule@speculoos.world>
* @link https://github.com/magicoli/opensim-helpers
* @license AGPLv3
*
* Includes portions of code from
* Melanie Thielker and Teravus Ovares (http://opensimulator.org/)
* Fumi.Iseki for CMS/LMS '09 5/31
*/
// error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once 'includes/config.php';
require_once 'includes/economy.php';
//
// The XMLRPC server object
//
$xmlrpc_server = xmlrpc_server_create();
//
// Viewer retrieves currency buy quote
//
xmlrpc_server_register_method( $xmlrpc_server, 'getCurrencyQuote', 'currency_xmlrpc_quote' );
function currency_xmlrpc_quote( $method_name, $params, $app_data ) {
$req = $params[0];
$agentid = $req['agentId'];
$sessionid = $req['secureSessionId'];
$amount = $req['currencyBuy'];
$ipAddress = $_SERVER['REMOTE_ADDR'];
$ret = opensim_check_secure_session( $agentid, null, $sessionid );
if ( $ret ) {
$confirmvalue = currency_get_confirm_value( $ipAddress );
switch ( CURRENCY_PROVIDER ) {
case 'gloebit':
$cost = 1; // default cost if no table;
$conversion_table = GLOEBIT_CONVERSION_TABLE;
foreach ( $conversion_table as $key => $value ) {
$cost = $value;
if ( GLOEBIT_CONVERSION_THRESHOLD > 0 ) {
$threshold = GLOEBIT_CONVERSION_THRESHOLD;
} else {
$threshold = 1;
}
if ( $key >= $amount / $threshold ) {
break;
}
}
break;
default:
$cost = currency_virtual_to_real( $amount );
$realamount = $amount;
}
$currency = array(
'estimatedCost' => $cost,
'currencyBuy' => $realamount,
);
$response_xml = xmlrpc_encode(
array(
'success' => true,
'currency' => $currency,
'confirm' => $confirmvalue,
)
);
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => "Unable to Authenticate\n\nClick URL for more info.",
'errorURI' => '' . CURRENCY_HELPER_URL . '',
)
);
}
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
//
// Viewer buys currency
//
xmlrpc_server_register_method( $xmlrpc_server, 'buyCurrency', 'currency_xmlrpc_buy' );
function currency_xmlrpc_buy( $method_name, $params, $app_data ) {
$req = $params[0];
$agentid = $req['agentId'];
$sessionid = $req['secureSessionId'];
$amount = $req['currencyBuy'];
$confim = $req['confirm'];
$ipAddress = $_SERVER['REMOTE_ADDR'];
if ( $confim != currency_get_confirm_value( $ipAddress ) ) {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => "\n\nMissmatch Confirm Value!!",
'errorURI' => '' . CURRENCY_HELPER_URL . '',
)
);
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
$checkSecure = opensim_check_secure_session( $agentid, null, $sessionid );
if ( ! $checkSecure ) {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => "\n\nMissmatch Secure Session ID!!",
'errorURI' => '' . CURRENCY_HELPER_URL . '',
)
);
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
$ret = false;
$cost = currency_virtual_to_real( $amount );
$transactionPermit = currency_process_transaction( $agentid, $cost, $ipAddress );
if ( $transactionPermit ) {
$res = currency_add_money( $agentid, $amount, $sessionid );
if ( $res['success'] ) {
$ret = true;
}
}
if ( $ret ) {
$response_xml = xmlrpc_encode( array( 'success' => true ) );
} else {
switch ( CURRENCY_PROVIDER ) {
case 'podex':
$errorURI = null; // opensim_format_tp(PODEX_REDIRECT_URL, TPLINK_HOP);
$errorMessage = PODEX_ERROR_MESSAGE . ' ' . PODEX_REDIRECT_URL;
break;
case 'gloebit':
if ( defined( GLOEBIT_SANDBOX ) && GLOEBIT_SANDBOX ) {
$baseurl = 'https://sandbox.gloebit.com/purchase';
} else {
$baseurl = 'https://www.gloebit.com/purchase';
}
$server_info = opensim_get_server_info( $agentid );
$serverip = $server_info['serverIP'];
$httpport = $server_info['serverHttpPort'];
$informurl = "http://${serverip}:${httpport}/gloebit/buy_complete?agentId=${agentid}";
$errorURI = "${baseurl}?reset&r=&inform=$informurl";
$errorMessage = 'Click OK to finish the transaction on Gloebit website.';
break;
default:
$errorMessage = 'Unable to process the transaction. The gateway denied your charge. Open help page?';
$errorURI = empty( W4OS_GRID_INFO['help'] ) ? CURRENCY_HELPER_URL : W4OS_GRID_INFO['help'];
}
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => $errorMessage,
'errorURI' => $errorURI,
)
);
}
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
//
// Region requests account balance
//
xmlrpc_server_register_method( $xmlrpc_server, 'simulatorUserBalanceRequest', 'currency_xmlrpc_balance' );
function currency_xmlrpc_balance( $method_name, $params, $app_data ) {
$req = $params[0];
$agentid = $req['agentId'];
$sessionid = $req['secureSessionId'];
$balance = currency_get_balance( $agentid, $sessionid );
if ( $balance >= 0 ) {
$response_xml = xmlrpc_encode(
array(
'success' => true,
'agentId' => $agentid,
'funds' => $balance,
)
);
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'Could not authenticate your avatar. Money operations may be unavailable',
'errorURI' => ' ',
)
);
}
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
//
// Region initiates money transfer (Direct DB Operation for security)
//
xmlrpc_server_register_method( $xmlrpc_server, 'regionMoveMoney', 'currency_xmlrpc_regionMoveMoney' );
function currency_xmlrpc_regionMoveMoney( $method_name, $params, $app_data ) {
$req = $params[0];
$agentid = $req['agentId'];
$destid = $req['destId'];
$sessionid = $req['secureSessionId'];
$regionid = $req['regionId'];
$secret = $req['secret'];
$currencySecret = $req['currencySecret'];
$cash = $req['cash'];
$aggregatePermInventory = $req['aggregatePermInventory'];
$aggregatePermNextOwner = $req['aggregatePermNextOwner'];
$flags = $req['flags'];
$transactiontype = $req['transactionType'];
$description = $req['description'];
$ipAddress = $_SERVER['REMOTE_ADDR'];
$ret = opensim_check_region_secret( $regionid, $secret );
if ( $ret ) {
$ret = opensim_check_secure_session( $agentid, $regionid, $sessionid );
if ( $ret ) {
$balance = currency_get_balance( $agentid, $sessionid );
if ( $balance >= $cash ) {
currency_move_money(
$agentid,
$destid,
$cash,
$transactiontype,
$flags,
$description,
$aggregatePermInventory,
$aggregatePermNextOwner,
$ipAddress
);
$sbalance = currency_get_balance( $agentid, $sessionid );
$dbalance = currency_get_balance( $destid );
$response_xml = xmlrpc_encode(
array(
'success' => true,
'agentId' => $agentid,
'funds' => $balance,
'funds2' => $balance,
'currencySecret' => ' ',
)
);
currency_update_simulator_balance( $agentid, $sbalance, $sessionid );
currency_update_simulator_balance( $destid, $dbalance );
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'You do not have sufficient funds for this purchase',
'errorURI' => ' ',
)
);
}
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'Unable to authenticate avatar. Money operations may be unavailable',
'errorURI' => ' ',
)
);
}
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'This region is not authorized to manage your money.',
'errorURI' => ' ',
)
);
}
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
//
// Region claims user
//
xmlrpc_server_register_method( $xmlrpc_server, 'simulatorClaimUserRequest', 'currency_xmlrpc_claimUserRequest' );
function currency_xmlrpc_claimUserRequest( $method_name, $params, $app_data ) {
$req = $params[0];
$agentid = $req['agentId'];
$sessionid = $req['secureSessionId'];
$regionid = $req['regionId'];
$secret = $req['secret'];
$ret = opensim_check_region_secret( $regionid, $secret );
if ( $ret ) {
$ret = opensim_check_secure_session( $agentid, null, $sessionid );
if ( $ret ) {
$ret = opensim_set_current_region( $agentid, $regionid );
if ( $ret ) {
$balance = currency_get_balance( $agentid, $sessionid );
$response_xml = xmlrpc_encode(
array(
'success' => true,
'agentId' => $agentid,
'funds' => $balance,
'currencySecret' => ' ',
)
);
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'Error occurred, when DB was updated.',
'errorURI' => ' ',
)
);
}
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'Unable to authenticate avatar. Money operations may be unavailable.',
'errorURI' => ' ',
)
);
}
} else {
$response_xml = xmlrpc_encode(
array(
'success' => false,
'errorMessage' => 'This region is not authorized to manage your money.',
'errorURI' => ' ',
)
);
}
header( 'Content-type: text/xml' );
echo $response_xml;
return '';
}
//
// Process the request
//
$request_xml = file_get_contents( 'php://input' );
// error_log(__FILE__ . ' '. $request_xml);
xmlrpc_server_call_method( $xmlrpc_server, $request_xml, '' );
xmlrpc_server_destroy( $xmlrpc_server );
die();