require('includes/global.php');
if (gethostbyaddr($_SERVER['REMOTE_ADDR']) == 'notify.paypal.com') {
$req = 'cmd=_notify-validate';
$email = 'mark.samman@gmail.com';
foreach ($_POST as $k => $v) {
$v = Tools::parseInputString($v, false, false);
$req .= '&' . $k . '=' . urlencode($v);
}
$opts = array(
'http' => array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'content' => $req
)
);
$ctx = stream_context_create($opts);
$fp = fopen('http://www.paypal.com/cgi-bin/webscr', 'r', false, $ctx);
$result = stream_get_contents($fp);
fclose($fp);
if ($result == 'VERIFIED' && $_POST['payment_status'] == 'Completed' && $_POST['mc_currency'] == 'EUR' && $_POST['receiver_email'] == $email && $_POST['item_name'] == $config['serverName'] . ' donation') {
$row = $db->fetchRow('SELECT COUNT(*) as `count` FROM `tfscms_transactions` WHERE `api` = ' . API_PAYPAL . ' AND `tid` = ' . $db->escapeString($_POST['txn_id']) . ';');
if ($row['count'] == 0) {
$account = new Account(intval($_POST['custom']));
if ($account->exists()) {
$account->set(array('points' => $account->get('points') + floor(intval($_POST['mc_gross'] * 10))));
$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') . ');');
}
}
}
exit();
}
$subTopic = '';
if (isset($_GET['subtopic']))
$subTopic = Tools::parseInputString($_GET['subtopic'], true);
$err = null;
$success = null;
if (isset($_POST['gift']) && Tools::isValidToken($_POST['securitytoken']) && $loggedIn) {
$character = Tools::parseInputString($_POST['character']);
if (in_array($character, $account->getCharacters())) {
$player = new Player($character);
$gift = $config['donationGifts'][intval($_POST['gift']) - 1];
if (isset($gift)) {
if ($account->get('points') >= $gift['points']) {
if (!$player->isOnline()) {
$account->set(array('points' => $account->get('points') - $gift['points']));
switch ($gift['action']) {
case GIFT_ITEM:
{
if (!$player->getItemFromSlot(SLOT_ARROW))
$player->addItemToSlot($gift['itemId'], $gift['itemCount'], SLOT_ARROW);
else
$err = 'In order to receive this gift, your characters arrow slot has to be empty.';
break;
}
case GIFT_RESET_FRAGS:
{
if ($player->getFragTime() != 0)
$player->resetFragTime();
else
$err = 'In order to receive this gift, your character should have atleast one frag.';
break;
}
case GIFT_CLEAR_DEATHLIST:
{
$deathList = new DeathList($player->getID(), 5);
if (sizeof($deathList->getDeaths()) != 0)
$deathList->removeEntries();
else
$err = 'In order to receive this gift, your character should have atleast one death entry.';
unset($deathList);
break;
}
case GIFT_CHANGE_SEX:
{
$player->setSex(intval(!$player->getSex()));
break;
}
case GIFT_UNBAN:
{
$row = $db->fetchRow('SELECT COUNT(*) AS `count` FROM `bans` WHERE `type` = 3 AND `account` = ' . $_SESSION['accountId'] . ' AND `time` > ' . time(NULL) . ';');
if ($row['count'] != 0)
$db->query('UPDATE `bans` SET `time` = ' . time() . ' WHERE `type` = 3 AND `account` = ' . $_SESSION['accountId'] . ' AND `time` > ' . time(NULL) . ' LIMIT 1;');
else
$err = 'Your account is not banished.';
break;
}
case GIFT_UNDELETE:
{
$row = $db->fetchRow('SELECT COUNT(*) AS `count` FROM `bans` WHERE `type` = 5 AND `account` = ' . $_SESSION['accountId'] . ';');
if ($row['count'] != 0)
$db->query('DELETE FROM `bans` WHERE `type` = 5 AND `account` = ' . $_SESSION['accountId'] . ' LIMIT 1;');
else
$err = 'Your account is not deleted.';
break;
}
case GIFT_RESET_WARNINGS:
{
if ($account->get('warnings') > 0)
$account->set(array('warnings' => 0));
else
$err = 'Your account does not have any warnings.';
break;
}
case GIFT_RESET_RECOVERYKEY:
{
if ($account->get('key') != '0')
$account->set(array('key' => '0'));
else
$err = 'You have not taken any recovery key yet.';
break;
}
case GIFT_CHANGE_NAME:
{
if ($player->isNamelocked())
$err = 'Your character is already namelocked.';
else if ($player->getFormerNameTime() > time())
$err = 'You have already changed your name in the last two months.';
else
$player->namelock();
break;
}
default:
{
$err = 'Invalid gift action, contact the administrator.';
break;
}
}
if (!isset($err))
$success = intval($_POST['gift']) - 1;
else
$account->set(array('points' => $account->get('points') + $gift['points']));
} else
$err = 'The character you accept the gift on has to be offline!';
} else
$err = 'Insufficient points.';
}
unset($player);
}
}
if ($subTopic == 'gifts') {
$userInterface = new UserInterface('Donations');
$userInterface->display();
if ($loggedIn) {
if ($_GET['paypal'] == 1)
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>';
else if ($_GET['paypal'] == 2)
echo '<div class="errorBox"><span class="b">Sorry!</span> It looks like you cancelled the payment. No points for you!</div>';
else if (isset($err))
echo '<div class="errorBox"><span class="b">Sorry!</span> ' . $err . '</div>';
else if (isset($success))
echo '<div class="successBox"><span class="b">Success!</span> You have received the gift: ' . strtolower($config['donationGifts'][$success]['name']) . '.</div>';
$characters = $account->getCharacters();
}
?>
<table>
<tr class="tableHead">
<td>Gift</td>
<td style="width: 100px">Points</td>
<?php
if ($loggedIn) {
?>
<td style="width: 150px">Action</td>
<?php
}
?>
</tr>
<?php
foreach ($config['donationGifts'] as $gift) {
?>
<tr class="c<?php echo $i++ % 2; ?>">
<td>
<span class="giftHeader"><?php echo $gift['name']; ?></span>
<?php
if (strlen($gift['desc'])) {
?>
<br /><span class="miniLeftText"><?php echo $gift['desc']; ?></span>
<?php
}
?>
</td>
<td><span class="miniLeftText"><?php echo $gift['points']; ?> point(s)</span></td>
<?php
if ($loggedIn) {
?>
<td>
<form method="post">
<select style="width: 100%" class="input" name="character">
<?php
foreach ($characters as $character) {
?>
<option><?php echo $character; ?></option>
<?php
}
?>
</select>
<input type="hidden" name="gift" value="<?php echo $i; ?>" />
<input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
<br />
<input class="submit" style="width: 100%; height: 24px" type="submit" value="Accept" />
</form>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
<?php
} else if ($subTopic == 'points') {
if ($loggedIn) {
if ($config['reCAPTCHAEnabled'] == CONFIG_YES)
require('lib/recaptchalib.php');
$error = null;
$userInterface = new UserInterface('Donations');
if (Tools::isValidToken($_POST['securitytoken'])) {
$userInterface->display();
if ($config['reCAPTCHAEnabled'] == CONFIG_YES) {
if (!isset($_POST['recaptcha_response_field']))
$_POST['recaptcha_response_field'] = '';
$resp = recaptcha_check_answer($config['reCAPTCHAPrivateKey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if (!$resp->is_valid)
$error = $resp->error;
}
if (is_null($error) && isset($_POST['pin'])) {
$success = null;
$pin = Tools::parseInputString($_POST['pin']);
$product = intval($_POST['product']);
if (isset($config['daoPayOptions'][$product])) {
$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']) . ';');
if ($row['count'] == 0) {
$handle = fopen('http://daopay.com/svc/PINcheck?appcode=' . urlencode($config['daoPayOptions'][$product]['appCode']) . '&subkey=' . urlencode($config['daoPayOptions'][$product]['subKey']) . '&pin=' . urlencode($pin), 'r');
if ($handle) {
$content = stream_get_contents($handle);
if (substr($content, 0, 2) == 'ok') {
$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'] . ');');
$account->set(array('points' => $account->get('points') + $config['daoPayOptions'][$product]['points']));
$success = true;
}
fclose($handle);
} else
$success = false;
}
}
if (is_null($success)) {
?>
<div class="errorBox"><span class="b">Sorry!</span> Incorrect PIN, or it has already been used.</div>
<?php
} else if (!$success) {
?>
<div class="errorBox"><span class="b">Sorry</span> Service is currently unavailable.</div>
<?php
} else if ($success) {
?>
<div class="successBox"><span class="b">Success!</span> <?php echo $config['daoPayOptions'][$product]['points']; ?> point(s) has been added to your account.</div>
<?php
}
}
} else
$userInterface->display();
?>
<form method="post">
<input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
<table>
<tr class="tableHead">
<td colspan="2">Get your points!</td>
</tr>
<tr class="c0">
<td>DaoPay PIN-code:</td>
<td><input class="input" name="pin" type="text" /></td>
</tr>
<tr class="c1">
<td>Product:</td>
<td>
<select class="input" name="product">
<?php
foreach ($config['daoPayOptions'] as $option) {
?>
<option value="<?php echo $i++; ?>"><?php echo htmlspecialchars($option['points'] . ' points - ' . $option['price'], ENT_QUOTES); ?></option>
<?php
}
?>
</select>
</td>
</tr>
<?php
$c = 0;
if ($config['reCAPTCHAEnabled'] == CONFIG_YES) {
?>
<tr class="c<?php echo $c; ?>">
<td valign="top">Image Verification:</td>
<td>
<script type="text/javascript">
<!--
var RecaptchaOptions =
{
theme: '<?php echo $config['reCAPTCHAStyle']; ?>'
}
-->
</script>
<?php echo recaptcha_get_html($config['reCAPTCHAPublicKey'], $error); ?>
</td>
</tr>
<?php
$c = 1;
}
?>
<tr class="c<?php echo $c; ?>">
<td></td>
<td><input class="submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
} else {
$userInterface = new UserInterface('Donations');
$userInterface->display();
echo 'In order to receive your points, you have to be logged in.';
}
} else if ($subTopic == 'donate') {
if (empty($config['donationAPI'])) {
$userInterface = new UserInterface('Donations');
$userInterface->display();
echo 'We don\'t accept donations... yet ;).';
exit();
}
if (Tools::isValidToken($_POST['securitytoken']) && isset($_POST['agreed'])) {
if( $_POST['agreed'] == 0) {
header('Location: index.php');
exit();
} else {
$userInterface = new UserInterface('Donations');
$userInterface->display();
if (in_array('DaoPay', $config['donationAPI'])) {
?>
<div style="float: left; width: <?php echo floor(100 / sizeof($config['donationAPI'])); ?>%">
<h2 style="text-align: center">DaoPay</h2>
<table>
<tr class="tableHead">
<td>#</td>
<td>Donation amount</td>
<td>Points</td>
</tr>
<?php
foreach ($config['daoPayOptions'] as $option) {
?>
<tr class="c<?php echo $i++ % 2; ?>">
<td><div style="background-image: url('http://daopay.com/logos/gif/daopay-s.gif'); width: 52px; height: 23px"></div></td>
<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>
<td><?php echo $option['points']; ?> point(s)</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
if (in_array('PayPal', $config['donationAPI'])) {
?>
<div style="float: left; width: <?php echo floor(100 / sizeof($config['donationAPI'])); ?>%">
<h2 style="text-align: center">PayPal</h2>
<?php
if ($loggedIn) {
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="business" value="mark.samman@gmail.com" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="item_name" value="<?php echo $config['serverName']; ?> donation" />
<input type="hidden" name="return" value="http://<?php echo $config['host']; ?>/donate.php?subtopic=gifts&paypal=1" />
<input type="hidden" name="cancel_ return" value="http://<?php echo $config['host']; ?>/donate.php?subtopic=gifts&paypal=2" />
<input type="hidden" name="notify_url" value="http://<?php echo $config['host']; ?>/donate.php" />
<input type="hidden" name="custom" value="<?php echo $_SESSION['accountId']; ?>" />
<table>
<tr class="tableHead">
<td colspan="2">Donate using PayPal</td>
</tr>
<tr class="c0">
<td>EUR:</td>
<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>
</tr>
<tr class="c1">
<td>Points:</td>
<td><input class="input" type="textbox" id="points" value="50" style="width: 96%; height: 15px" readonly="readonly" /></td>
</tr>
<tr class="c0">
<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>
</tr>
</table>
</form>
<?php
} else {
?>
<table>
<tr class="tableHead">
<td colspan="2">Donate using PayPal</td>
</tr>
<tr class="c0">
<td colspan="2" class="b">Please login to donate using PayPal.</td>
</tr>
</table>
<?php
}
?>
</div>
<?php
}
}
} else {
$userInterface = new UserInterface('Donations');
$userInterface->display();
?>
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 />
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 />
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 />
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 />
<form method="post">
<input type="hidden" name="securitytoken" value="<?php echo Tools::getSecurityToken(); ?>" />
<table>
<tr class="tableHead">
<td>Do you agree with our terms?</td>
</tr>
<tr class="c0">
<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>
</tr>
<tr class="c1">
<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>
</tr>
<tr class="c0">
<td><input style="width: 100%" class="submit" type="submit" value="Proceed" /></td>
</tr>
</table>
</form>
<?php
}
} else {
$userInterface = new UserInterface('Donations');
$userInterface->display();
?>
<div align="center" style="margin-top: 14px"><a href="?subtopic=donate"><img src="images/firstdonation.jpg" alt="First step: Make donation" border="0" /></a>
<br /><br /><a href="?subtopic=points"><img src="images/seconddonation.jpg" alt="First step: Make donation" border="0" /><br /><br />
<a href="?subtopic=gifts"><img src="images/thirddonation.jpg" alt="First step: Make donation" border="0" /></a></div><br />
<?php
}
?>