Guest
Public paste!

Untitled

By: a guest | Mar 10th, 2010 | Syntax: PHP | Size: 26.44 KB | Hits: 197 | Expires: Never
Copy text to clipboard
  1. require('includes/global.php');
  2.  
  3. if (gethostbyaddr($_SERVER['REMOTE_ADDR']) == 'notify.paypal.com') {
  4.         $req = 'cmd=_notify-validate';
  5.         $email = 'mark.samman@gmail.com';
  6.  
  7.         foreach ($_POST as $k => $v) {
  8.                 $v = Tools::parseInputString($v, false, false);
  9.                 $req .= '&' . $k . '=' . urlencode($v);
  10.         }
  11.  
  12.         $opts = array(
  13.                 'http' => array(
  14.                         'method' => 'POST',
  15.                         'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
  16.                         'content' => $req
  17.                 )
  18.         );
  19.  
  20.         $ctx = stream_context_create($opts);
  21.  
  22.         $fp = fopen('http://www.paypal.com/cgi-bin/webscr', 'r', false, $ctx);
  23.         $result = stream_get_contents($fp);
  24.         fclose($fp);
  25.  
  26.         if ($result == 'VERIFIED' && $_POST['payment_status'] == 'Completed' && $_POST['mc_currency'] == 'EUR' && $_POST['receiver_email'] == $email && $_POST['item_name'] == $config['serverName'] . ' donation') {
  27.                 $row = $db->fetchRow('SELECT COUNT(*) as `count` FROM `tfscms_transactions` WHERE `api` = ' . API_PAYPAL . ' AND `tid` = ' . $db->escapeString($_POST['txn_id']) . ';');
  28.                 if ($row['count'] == 0) {
  29.                         $account = new Account(intval($_POST['custom']));
  30.                         if ($account->exists()) {
  31.                                 $account->set(array('points' => $account->get('points') + floor(intval($_POST['mc_gross'] * 10))));
  32.                                 $db->query('INSERT INTO `tfscms_transactions` (`api`, `tid`, `date`, `amount`, `account_id`) VALUES (' . API_PAYPAL . ', ' . $db->escapeString($_POST['txn_id']) . ', ' . time() . ', ' . doubleval(round($_POST['mc_gross'], 2)) . ', ' . $account->get('id') . ');');
  33.                         }
  34.                 }
  35.         }
  36.         exit();
  37. }
  38.  
  39. $subTopic = '';
  40. if (isset($_GET['subtopic']))
  41.         $subTopic = Tools::parseInputString($_GET['subtopic'], true);
  42.  
  43. $err = null;
  44. $success = null;
  45. if (isset($_POST['gift']) && Tools::isValidToken($_POST['securitytoken']) && $loggedIn) {
  46.         $character = Tools::parseInputString($_POST['character']);
  47.         if (in_array($character, $account->getCharacters())) {
  48.                 $player = new Player($character);
  49.  
  50.                 $gift = $config['donationGifts'][intval($_POST['gift']) - 1];
  51.                 if (isset($gift)) {
  52.                         if ($account->get('points') >= $gift['points']) {
  53.                                 if (!$player->isOnline()) {
  54.                                         $account->set(array('points' => $account->get('points') - $gift['points']));
  55.                                         switch ($gift['action']) {
  56.                                                 case GIFT_ITEM:
  57.                                                 {
  58.                                                         if (!$player->getItemFromSlot(SLOT_ARROW))
  59.                                                                 $player->addItemToSlot($gift['itemId'], $gift['itemCount'], SLOT_ARROW);
  60.                                                         else
  61.                                                                 $err = 'In order to receive this gift, your characters arrow slot has to be empty.';
  62.  
  63.                                                         break;
  64.                                                 }
  65.  
  66.                                                 case GIFT_RESET_FRAGS:
  67.                                                 {
  68.                                                         if ($player->getFragTime() != 0)
  69.                                                                 $player->resetFragTime();
  70.                                                         else
  71.                                                                 $err = 'In order to receive this gift, your character should have atleast one frag.';
  72.  
  73.                                                         break;
  74.                                                 }
  75.  
  76.                                                 case GIFT_CLEAR_DEATHLIST:
  77.                                                 {
  78.                                                         $deathList = new DeathList($player->getID(), 5);
  79.                                                         if (sizeof($deathList->getDeaths()) != 0)
  80.                                                                 $deathList->removeEntries();
  81.                                                         else
  82.                                                                 $err = 'In order to receive this gift, your character should have atleast one death entry.';
  83.  
  84.                                                         unset($deathList);
  85.                                                         break;
  86.                                                 }
  87.  
  88.                                                 case GIFT_CHANGE_SEX:
  89.                                                 {
  90.                                                         $player->setSex(intval(!$player->getSex()));
  91.                                                         break;
  92.                                                 }
  93.  
  94.                                                 case GIFT_UNBAN:
  95.                                                 {
  96.                                                         $row = $db->fetchRow('SELECT COUNT(*) AS `count` FROM `bans` WHERE `type` = 3 AND `account` = ' . $_SESSION['accountId'] . ' AND `time` > ' . time(NULL) . ';');
  97.                                                         if ($row['count'] != 0)
  98.                                                                 $db->query('UPDATE `bans` SET `time` = ' . time() . ' WHERE `type` = 3 AND `account` = ' . $_SESSION['accountId'] . ' AND `time` > ' . time(NULL) . ' LIMIT 1;');
  99.                                                         else
  100.                                                                 $err = 'Your account is not banished.';
  101.  
  102.                                                         break;
  103.                                                 }
  104.  
  105.                                                 case GIFT_UNDELETE:
  106.                                                 {
  107.                                                         $row = $db->fetchRow('SELECT COUNT(*) AS `count` FROM `bans` WHERE `type` = 5 AND `account` = ' . $_SESSION['accountId'] . ';');
  108.                                                         if ($row['count'] != 0)
  109.                                                                 $db->query('DELETE FROM `bans` WHERE `type` = 5 AND `account` = ' . $_SESSION['accountId'] . ' LIMIT 1;');
  110.                                                         else
  111.                                                                 $err = 'Your account is not deleted.';
  112.  
  113.                                                         break;
  114.                                                 }
  115.  
  116.                                                 case GIFT_RESET_WARNINGS:
  117.                                                 {
  118.                                                         if ($account->get('warnings') > 0)
  119.                                                                 $account->set(array('warnings' => 0));
  120.                                                         else
  121.                                                                 $err = 'Your account does not have any warnings.';
  122.  
  123.                                                         break;
  124.                                                 }
  125.  
  126.                                                 case GIFT_RESET_RECOVERYKEY:
  127.                                                 {
  128.                                                         if ($account->get('key') != '0')
  129.                                                                 $account->set(array('key' => '0'));
  130.                                                         else
  131.                                                                 $err = 'You have not taken any recovery key yet.';
  132.  
  133.                                                         break;
  134.                                                 }
  135.  
  136.                                                 case GIFT_CHANGE_NAME:
  137.                                                 {
  138.                                                         if ($player->isNamelocked())
  139.                                                                 $err = 'Your character is already namelocked.';
  140.                                                         else if ($player->getFormerNameTime() > time())
  141.                                                                 $err = 'You have already changed your name in the last two months.';
  142.                                                         else
  143.                                                                 $player->namelock();
  144.  
  145.                                                         break;
  146.                                                 }
  147.  
  148.                                                 default:
  149.                                                 {
  150.                                                         $err = 'Invalid gift action, contact the administrator.';
  151.                                                         break;
  152.                                                 }
  153.                                         }
  154.  
  155.                                         if (!isset($err))
  156.                                                 $success = intval($_POST['gift']) - 1;
  157.                                         else
  158.                                                 $account->set(array('points' => $account->get('points') + $gift['points']));
  159.                                 } else
  160.                                         $err = 'The character you accept the gift on has to be offline!';
  161.                         } else
  162.                                 $err = 'Insufficient points.';
  163.                 }
  164.                 unset($player);
  165.         }
  166. }
  167.  
  168. if ($subTopic == 'gifts') {
  169.         $userInterface = new UserInterface('Donations');
  170.         $userInterface->display();
  171.  
  172.         if ($loggedIn) {
  173.                 if ($_GET['paypal'] == 1)
  174.                         echo '<div class="successBox"><span class="b">Success!</span> Thanks for your donation, you should have your points within five minutes. If not, please contact a gamemaster.</div>';
  175.                 else if ($_GET['paypal'] == 2)
  176.                         echo '<div class="errorBox"><span class="b">Sorry!</span> It looks like you cancelled the payment. No points for you!</div>';
  177.                 else if (isset($err))
  178.                         echo '<div class="errorBox"><span class="b">Sorry!</span> ' . $err . '</div>';
  179.                 else if (isset($success))
  180.                         echo '<div class="successBox"><span class="b">Success!</span> You have received the gift: ' . strtolower($config['donationGifts'][$success]['name']) . '.</div>';
  181.  
  182.                 $characters = $account->getCharacters();
  183.         }
  184. ?>
  185. <table>
  186.         <tr class="tableHead">
  187.                 <td>Gift</td>
  188.                 <td style="width: 100px">Points</td>
  189. <?php
  190.         if ($loggedIn) {
  191. ?>
  192.                 <td style="width: 150px">Action</td>
  193. <?php
  194.         }
  195. ?>
  196.         </tr>
  197. <?php
  198.         foreach ($config['donationGifts'] as $gift) {
  199. ?>
  200.         <tr class="c<?php echo $i++ % 2; ?>">
  201.                 <td>
  202.                         <span class="giftHeader"><?php echo $gift['name']; ?></span>
  203. <?php
  204.                 if (strlen($gift['desc'])) {
  205. ?>
  206.                         <br /><span class="miniLeftText"><?php echo $gift['desc']; ?></span>
  207. <?php
  208.                 }
  209. ?>
  210.                 </td>
  211.                 <td><span class="miniLeftText"><?php echo $gift['points']; ?> point(s)</span></td>
  212. <?php
  213.                 if ($loggedIn) {
  214. ?>
  215.                 <td>
  216.                         <form method="post">
  217.                                 <select style="width: 100%" class="input" name="character">
  218. <?php
  219.                         foreach ($characters as $character) {
  220. ?>
  221.                                         <option><?php echo $character; ?></option>
  222. <?php
  223.                         }
  224. ?>
  225.                                 </select>
  226.                                 <input type="hidden" name="gift" value="<?php echo $i; ?>" />
  227.                                 <input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
  228.                                 <br />
  229.                                 <input class="submit" style="width: 100%; height: 24px" type="submit" value="Accept" />
  230.                         </form>
  231.                 </td>
  232. <?php
  233.                 }
  234. ?>
  235.         </tr>
  236. <?php
  237.         }
  238. ?>
  239. </table>
  240. <?php
  241. } else if ($subTopic == 'points') {
  242.         if ($loggedIn) {
  243.                 if ($config['reCAPTCHAEnabled'] == CONFIG_YES)
  244.                         require('lib/recaptchalib.php');
  245.  
  246.                 $error = null;
  247.                 $userInterface = new UserInterface('Donations');
  248.  
  249.                 if (Tools::isValidToken($_POST['securitytoken'])) {
  250.                         $userInterface->display();
  251.                         if ($config['reCAPTCHAEnabled'] == CONFIG_YES) {
  252.                                 if (!isset($_POST['recaptcha_response_field']))
  253.                                         $_POST['recaptcha_response_field'] = '';
  254.  
  255.                                 $resp = recaptcha_check_answer($config['reCAPTCHAPrivateKey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
  256.                                 if (!$resp->is_valid)
  257.                                         $error = $resp->error;
  258.                         }
  259.  
  260.                         if (is_null($error) && isset($_POST['pin'])) {
  261.                                 $success = null;
  262.                                 $pin = Tools::parseInputString($_POST['pin']);
  263.                                 $product = intval($_POST['product']);
  264.                                 if (isset($config['daoPayOptions'][$product])) {
  265.                                         $row = $db->fetchRow('SELECT COUNT(*) as `count` FROM `tfscms_transactions` WHERE `api` = ' . API_DAOPAY . ' AND `tid` = ' . $db->escapeString($pin) . ' AND `appcode` = ' . $config['daoPayOptions'][$product]['appCode'] . ' AND `subkey` = ' . $db->escapeString($config['daoPayOptions'][$product]['subKey']) . ';');
  266.                                         if ($row['count'] == 0) {
  267.                                                 $handle = fopen('http://daopay.com/svc/PINcheck?appcode=' . urlencode($config['daoPayOptions'][$product]['appCode']) . '&subkey=' . urlencode($config['daoPayOptions'][$product]['subKey']) . '&pin=' . urlencode($pin), 'r');
  268.                                                 if ($handle) {
  269.                                                         $content = stream_get_contents($handle);
  270.                                                         if (substr($content, 0, 2) == 'ok') {
  271.                                                                 $db->query('INSERT INTO `tfscms_transactions` (`api`, `tid`, `appcode`, `subkey`, `date`, `amount`, `account_id`) VALUES (' . API_DAOPAY . ', ' . $db->escapeString($pin) . ', ' . $config['daoPayOptions'][$product]['appCode'] . ', ' . $db->escapeString($config['daoPayOptions'][$product]['subKey']) . ', ' . time() . ', ' . intval($config['daoPayOptions'][$product]['price']) . ', ' . $_SESSION['accountId'] . ');');
  272.                                                                 $account->set(array('points' => $account->get('points') + $config['daoPayOptions'][$product]['points']));
  273.                                                                 $success = true;
  274.                                                         }
  275.  
  276.                                                         fclose($handle);
  277.                                                 } else
  278.                                                         $success = false;
  279.                                         }
  280.                                 }
  281.  
  282.                                 if (is_null($success)) {
  283. ?>
  284. <div class="errorBox"><span class="b">Sorry!</span> Incorrect PIN, or it has already been used.</div>
  285. <?php
  286.                                 } else if (!$success) {
  287. ?>
  288. <div class="errorBox"><span class="b">Sorry</span> Service is currently unavailable.</div>
  289. <?php
  290.                                 } else if ($success) {
  291. ?>
  292. <div class="successBox"><span class="b">Success!</span> <?php echo $config['daoPayOptions'][$product]['points']; ?> point(s) has been added to your account.</div>
  293. <?php
  294.                                 }
  295.                         }
  296.                 } else
  297.                         $userInterface->display();
  298. ?>
  299. <form method="post">
  300.         <input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
  301.         <table>
  302.                 <tr class="tableHead">
  303.                         <td colspan="2">Get your points!</td>
  304.                 </tr>
  305.                 <tr class="c0">
  306.                         <td>DaoPay PIN-code:</td>
  307.                         <td><input class="input" name="pin" type="text" /></td>
  308.                 </tr>
  309.                 <tr class="c1">
  310.                         <td>Product:</td>
  311.                         <td>
  312.                                 <select class="input" name="product">
  313. <?php
  314.                 foreach ($config['daoPayOptions'] as $option) {
  315. ?>
  316.                                         <option value="<?php echo $i++; ?>"><?php echo htmlspecialchars($option['points'] . ' points -  ' . $option['price'], ENT_QUOTES); ?></option>
  317. <?php
  318.                 }
  319. ?>
  320.                                 </select>
  321.                         </td>
  322.                 </tr>
  323. <?php
  324.                 $c = 0;
  325.                 if ($config['reCAPTCHAEnabled'] == CONFIG_YES) {
  326. ?>
  327.                 <tr class="c<?php echo $c; ?>">
  328.                         <td valign="top">Image Verification:</td>
  329.                         <td>
  330.                                 <script type="text/javascript">
  331.                                         <!--
  332.                                                 var RecaptchaOptions =
  333.                                                 {
  334.                                                         theme: '<?php echo $config['reCAPTCHAStyle']; ?>'
  335.                                                 }
  336.                                         -->
  337.                                 </script>
  338.                                 <?php echo recaptcha_get_html($config['reCAPTCHAPublicKey'], $error); ?>
  339.                         </td>
  340.                 </tr>
  341. <?php
  342.                         $c = 1;
  343.                 }
  344. ?>
  345.                 <tr class="c<?php echo $c; ?>">
  346.                         <td></td>
  347.                         <td><input class="submit" type="submit" value="Submit" /></td>
  348.                 </tr>
  349.         </table>
  350. </form>
  351. <?php
  352.         } else {
  353.                 $userInterface = new UserInterface('Donations');
  354.                 $userInterface->display();
  355.                 echo 'In order to receive your points, you have to be logged in.';
  356.         }
  357. } else if ($subTopic == 'donate') {
  358.         if (empty($config['donationAPI'])) {
  359.                 $userInterface = new UserInterface('Donations');
  360.                 $userInterface->display();
  361.                 echo 'We don\'t accept donations... yet ;).';
  362.                 exit();
  363.         }
  364.  
  365.         if (Tools::isValidToken($_POST['securitytoken']) && isset($_POST['agreed'])) {
  366.                 if( $_POST['agreed'] == 0) {
  367.                         header('Location: index.php');
  368.                         exit();
  369.                 } else {
  370.                         $userInterface = new UserInterface('Donations');
  371.                         $userInterface->display();
  372.  
  373.                         if (in_array('DaoPay', $config['donationAPI'])) {
  374. ?>
  375. <div style="float: left; width: <?php echo floor(100 / sizeof($config['donationAPI'])); ?>%">
  376.         <h2 style="text-align: center">DaoPay</h2>
  377.         <table>
  378.                 <tr class="tableHead">
  379.                         <td>#</td>
  380.                         <td>Donation amount</td>
  381.                         <td>Points</td>
  382.                 </tr>
  383. <?php
  384.                                 foreach ($config['daoPayOptions'] as $option) {
  385. ?>
  386.                 <tr class="c<?php echo $i++ % 2; ?>">
  387.                         <td><div style="background-image: url('http://daopay.com/logos/gif/daopay-s.gif'); width: 52px; height: 23px"></div></td>
  388.                         <td><a href="https://daopay.com/payment/?appcode=<?php echo urlencode($option['appCode']); ?>&prodcode=<?php echo urlencode($option['subKey']); ?>"><?php echo $option['price']; ?></a></td>
  389.                         <td><?php echo $option['points']; ?> point(s)</td>
  390.                 </tr>
  391. <?php
  392.                                 }
  393. ?>
  394.         </table>
  395. </div>
  396. <?php
  397.                         }
  398.  
  399.                         if (in_array('PayPal', $config['donationAPI'])) {
  400. ?>
  401. <div style="float: left; width: <?php echo floor(100 / sizeof($config['donationAPI'])); ?>%">
  402.         <h2 style="text-align: center">PayPal</h2>
  403. <?php
  404.                                 if ($loggedIn) {
  405. ?>
  406.         <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  407.                 <input type="hidden" name="cmd" value="_donations" />
  408.                 <input type="hidden" name="business" value="mark.samman@gmail.com" />
  409.                 <input type="hidden" name="currency_code" value="EUR" />
  410.                 <input type="hidden" name="item_name" value="<?php echo $config['serverName']; ?> donation" />
  411.                 <input type="hidden" name="return" value="http://<?php echo $config['host']; ?>/donate.php?subtopic=gifts&paypal=1" />
  412.                 <input type="hidden" name="cancel_ return" value="http://<?php echo $config['host']; ?>/donate.php?subtopic=gifts&paypal=2" />
  413.                 <input type="hidden" name="notify_url" value="http://<?php echo $config['host']; ?>/donate.php" />
  414.                 <input type="hidden" name="custom" value="<?php echo $_SESSION['accountId']; ?>" />
  415.                 <table>
  416.                         <tr class="tableHead">
  417.                                 <td colspan="2">Donate using PayPal</td>
  418.                         </tr>
  419.                         <tr class="c0">
  420.                                 <td>EUR:</td>
  421.                                 <td><input class="input" type="textbox" name="amount" id="amount" value="5.00" onkeydown="document.getElementById('points').value = Math.floor(this.value * 10);" onkeypress="document.getElementById('points').value = Math.floor(this.value * 10);" onkeyup="document.getElementById('points').value = Math.floor(this.value * 10); if(this.value.indexOf('.') + 3 < this.value.length) this.value = this.value.substring(0, this.value.indexOf('.') + 3);" maxlength="8" style="width: 96%; height: 15px" /></td>
  422.                         </tr>
  423.                         <tr class="c1">
  424.                                 <td>Points:</td>
  425.                                 <td><input class="input" type="textbox" id="points" value="50" style="width: 96%; height: 15px" readonly="readonly" /></td>
  426.                         </tr>
  427.                         <tr class="c0">
  428.                                 <td colspan="2" align="center" style="height: 53px"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /></td>
  429.                         </tr>
  430.                 </table>
  431.         </form>
  432. <?php
  433.                                 } else {
  434. ?>
  435.         <table>
  436.                 <tr class="tableHead">
  437.                         <td colspan="2">Donate using PayPal</td>
  438.                 </tr>
  439.                 <tr class="c0">
  440.                         <td colspan="2" class="b">Please login to donate using PayPal.</td>
  441.                 </tr>
  442.         </table>
  443. <?php
  444.                                 }
  445. ?>
  446. </div>
  447. <?php
  448.                         }
  449.                 }
  450.         } else {
  451.                 $userInterface = new UserInterface('Donations');
  452.                 $userInterface->display();
  453. ?>
  454. When you donate money to our project <?php echo $config['serverName']; ?>, you understand that a donation is a gift and that you cannot demand us to refund your money. The money we receive from donations will be used to improve our server.<br /><br />
  455. If you, for any reason, would refund your money, we reserve the rights to ban or delete your account without any further notice.<br /><br />
  456. Please save the PIN-code you receive after the transaction incase anything would go wrong when you pick a gift. Otherwise we can not really help you, the PIN-code is pretty much the only proof that you have donated money to our project.<br /><br />
  457. As a thanks for supporting our project <?php echo $config['serverName']; ?> with money, you may request a gift in our gameservers. Based upon how much you donate to us, you can request a better gift. The available gifts can be found <a href="?subtopic=gifts">here</a>.<br /><br />
  458. <form method="post">
  459.         <input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
  460.         <table>
  461.                 <tr class="tableHead">
  462.                         <td>Do you agree with our terms?</td>
  463.                 </tr>
  464.                 <tr class="c0">
  465.                         <td><input id="disagree" type="radio" name="agreed" value="0" checked="checked" /><label for="disagree"> I <span class="b">do NOT agree</span> with the terms stated above.</label></td>
  466.                 </tr>
  467.                 <tr class="c1">
  468.                         <td><input id="agree" type="radio" name="agreed" value="1" /><label for="agree"> I <span class="b">agree</span> with the terms stated above.</label></td>
  469.                 </tr>
  470.                 <tr class="c0">
  471.                         <td><input style="width: 100%" class="submit" type="submit" value="Proceed" /></td>
  472.                 </tr>
  473.         </table>
  474. </form>
  475. <?php
  476.         }
  477. } else {
  478.         $userInterface = new UserInterface('Donations');
  479.         $userInterface->display();
  480. ?>
  481. <div align="center" style="margin-top: 14px"><a href="?subtopic=donate"><img src="images/firstdonation.jpg" alt="First step: Make donation" border="0" /></a>
  482. <br /><br /><a href="?subtopic=points"><img src="images/seconddonation.jpg" alt="First step: Make donation" border="0" /><br /><br />
  483. <a href="?subtopic=gifts"><img src="images/thirddonation.jpg" alt="First step: Make donation" border="0" /></a></div><br />
  484. <?php
  485. }
  486. ?>