New setting: donate_column + move donate config to settings

This commit is contained in:
slawkens 2023-07-22 13:03:43 +02:00
parent a2fcb21b4f
commit b433615e68
12 changed files with 90 additions and 39 deletions

View File

@ -51,7 +51,11 @@ $deprecatedConfig = [
'status_port',
'mail_enabled',
'account_mail_verify',
'account_create_character_create'
'account_create_character_create',
'account_change_character_name',
'account_change_character_name_points' => 'account_change_character_name_price',
'account_change_character_sex',
'account_change_character_sex_points' => 'account_change_character_name_price',
];
foreach ($deprecatedConfig as $key => $value) {

View File

@ -20,16 +20,8 @@
// this file will be deleted, once all migrated to settings
$config = array(
'account_mail_block_plus_sign' => true, // block email with '+' signs like test+box@gmail.com (help protect against spamming accounts)
'account_change_character_name' => false, // can user change their character name for premium points?
'account_change_character_name_points' => 30, // cost of name change
'account_change_character_sex' => false, // can user change their character sex for premium points?
'account_change_character_sex_points' => 30, // cost of sex change
'characters_per_account' => 10, // max. number of characters per account
//
'generate_new_reckey' => true, // let player generate new recovery key, he will receive e-mail with new rec key (not display on page, hacker can't generate rec key)
'generate_new_reckey_price' => 20, // price for new recovery key
// new character config
'character_samples' => array( // vocations, format: ID_of_vocation => 'Name of Character to copy'
//0 => 'Rook Sample',

View File

@ -19,14 +19,14 @@ if(!$logged) {
$player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL;
$name = isset($_POST['name']) ? stripslashes(ucwords(strtolower($_POST['name']))) : NULL;
if((!$config['account_change_character_name']))
if((!setting('core.account_change_character_name')))
echo 'Changing character name for premium points is disabled on this server.';
else
{
$points = $account_logged->getCustomField('premium_points');
$points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['changenamesave']) && $_POST['changenamesave'] == 1) {
if($points < $config['account_change_character_name_points'])
$errors[] = 'You need ' . $config['account_change_character_name_points'] . ' premium points to change name. You have <b>'.$points.'<b> premium points.';
if($points < setting('core.account_change_character_name_price'))
$errors[] = 'You need ' . setting('core.account_change_character_name_price') . ' premium points to change name. You have <b>'.$points.'<b> premium points.';
$minLength = setting('core.create_character_name_min_length');
$maxLength = setting('core.create_character_name_max_length');
@ -86,7 +86,7 @@ else
}
}
$account_logged->setCustomField("premium_points", $points - $config['account_change_character_name_points']);
$account_logged->setCustomField(setting('core.donate_column'), $points - setting('core.account_change_character_name_price'));
$account_logged->logAction('Changed name from <b>' . $old_name . '</b> to <b>' . $player->getName() . '</b>.');
$twig->display('success.html.twig', array(
'title' => 'Character Name Changed',

View File

@ -20,14 +20,14 @@ if(!$logged) {
$sex_changed = false;
$player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL;
$new_sex = isset($_POST['new_sex']) ? (int)$_POST['new_sex'] : NULL;
if((!$config['account_change_character_sex']))
if((!setting('core.account_change_character_sex')))
echo 'You cant change your character sex';
else
{
$points = $account_logged->getCustomField('premium_points');
$points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['changesexsave']) && $_POST['changesexsave'] == 1) {
if($points < $config['account_change_character_sex_points'])
$errors[] = 'You need ' . $config['account_change_character_sex_points'] . ' premium points to change sex. You have <b>'.$points.'</b> premium points.';
if($points < setting('core.account_change_character_sex_price'))
$errors[] = 'You need ' . setting('core.account_change_character_sex_price') . ' premium points to change sex. You have <b>'.$points.'</b> premium points.';
if(empty($errors) && !isset($config['genders'][$new_sex])) {
$errors[] = 'This sex is invalid.';
@ -66,7 +66,7 @@ else
$new_sex_str = $config['genders'][$new_sex];
$player->save();
$account_logged->setCustomField("premium_points", $points - $config['account_change_character_name_points']);
$account_logged->setCustomField(setting('core.donate_column'), $points - setting('core.account_change_character_name_price'));
$account_logged->logAction('Changed sex on character <b>' . $player->getName() . '</b> from <b>' . $old_sex_str . '</b> to <b>' . $new_sex_str . '</b>.');
$twig->display('success.html.twig', array(
'title' => 'Character Sex Changed',

View File

@ -35,7 +35,7 @@ if(empty($recovery_key))
$account_registered = '<b><span style="color: red">No</span></b>';
else
{
if($config['generate_new_reckey'] && setting('core.mail_enabled'))
if(setting('core.account_generate_new_reckey') && setting('core.mail_enabled'))
$account_registered = '<b><span style="color: green">Yes ( <a href="' . getLink('account/register/new') . '"> Buy new Recovery Key </a> )</span></b>';
else
$account_registered = '<b><span style="color: green">Yes</span></b>';

View File

@ -21,18 +21,18 @@ if(isset($_POST['reg_password']))
$reg_password = encrypt((USE_ACCOUNT_SALT ? $account_logged->getCustomField('salt') : '') . $_POST['reg_password']);
$reckey = $account_logged->getCustomField('key');
if((!$config['generate_new_reckey'] || !setting('core.mail_enabled')) || empty($reckey)) {
if((!setting('core.account_generate_new_reckey') || !setting('core.mail_enabled')) || empty($reckey)) {
$errors[] = 'You cant get new recovery key.';
$twig->display('error_box.html.twig', array('errors' => $errors));
}
else
{
$points = $account_logged->getCustomField('premium_points');
$points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['registeraccountsave']) && $_POST['registeraccountsave'] == '1')
{
if($reg_password == $account_logged->getPassword())
{
if($points >= $config['generate_new_reckey_price'])
if($points >= setting('core.account_generate_new_reckey_price'))
{
$show_form = false;
$new_rec_key = generateRandomString(10, false, true, true);
@ -43,10 +43,10 @@ else
if(_mail($account_logged->getEMail(), $config['lua']['serverName']." - new recovery key", $mailBody))
{
$account_logged->setCustomField("key", $new_rec_key);
$account_logged->setCustomField("premium_points", $account_logged->getCustomField("premium_points") - $config['generate_new_reckey_price']);
$account_logged->logAction('Generated new recovery key for ' . $config['generate_new_reckey_price'] . ' premium points.');
$message = '<br />Your recovery key were send on email address <b>'.$account_logged->getEMail().'</b> for '.$config['generate_new_reckey_price'].' premium points.';
$account_logged->setCustomField('key', $new_rec_key);
$account_logged->setCustomField(setting('core.donate_column'), $account_logged->getCustomField(setting('core.donate_column')) - setting('core.account_generate_new_reckey_price'));
$account_logged->logAction('Generated new recovery key for ' . setting('core.account_generate_new_reckey_price') . ' premium points.');
$message = '<br />Your recovery key were send on email address <b>'.$account_logged->getEMail().'</b> for '.setting('core.account_generate_new_reckey_price').' premium points.';
}
else
$message = '<br /><p class="error">An error occurred while sending email ( <b>'.$account_logged->getEMail().'</b> ) with recovery key! Recovery key not changed. Try again later. For Admin: More info can be found in system/logs/mailer-error.log</p>';
@ -57,7 +57,7 @@ else
));
}
else
$errors[] = 'You need '.$config['generate_new_reckey_price'].' premium points to generate new recovery key. You have <b>'.$points.'<b> premium points.';
$errors[] = 'You need ' . setting('core.account_generate_new_reckey_price') . ' premium points to generate new recovery key. You have <b>'.$points.'<b> premium points.';
}
else
$errors[] = 'Wrong password to account.';

View File

@ -1295,6 +1295,61 @@ Sent by MyAAC,<br/>
'type' => 'boolean',
'default' => false,
],
'donate_column' => [
'name' => 'Donate Column',
'type' => 'options',
'desc' => 'What to give to player after donation - what column in accounts table to use.',
'options' => ['premium_points' => 'Premium Points', 'coins' => 'Coins'],
'default' => 'premium_points',
],
'account_generate_new_reckey' => [
'name' => 'Allow Generate New Key',
'desc' => "Allow to generate new key for premium points. The player will receive e-mail with new rec key (not display on page, hacker can't generate rec key)",
'type' => 'boolean',
'default' => false,
],
'account_generate_new_reckey_price' => [
'name' => 'Generate New Key Price',
'type' => 'number',
'min' => 0,
'desc' => 'Price for new recovery key',
'default' => 20,
'show_if' => [
'account_generate_new_reckey', '=', 'true',
],
],
'account_change_character_name' => [
'name' => 'Allow Change Name',
'desc' => 'Can user change their character name for premium points?',
'type' => 'boolean',
'default' => false,
],
'account_change_character_name_price' => [
'name' => 'Change Name Price',
'type' => 'number',
'min' => 0,
'desc' => 'Cost of name change',
'default' => 30,
'show_if' => [
'account_change_character_name', '=', 'true',
],
],
'account_change_character_sex' => [
'name' => 'Allow Change Sex',
'desc' => 'Can user change their character sex for premium points?',
'type' => 'boolean',
'default' => false,
],
'account_change_character_sex_price' => [
'name' => 'Change Sex Price',
'type' => 'number',
'min' => 0,
'desc' => 'Cost of change sex',
'default' => 30,
'show_if' => [
'account_change_character_sex', '=', 'true',
],
],
],
'callbacks' => [
'beforeSave' => function(&$settings, &$values) {

View File

@ -1,5 +1,5 @@
To change a name of character select player and choose a new name.<br/>
<span style="color: red">Change name cost {{ config.account_change_character_name_points }} premium points. You have {{ points }} premium points.</span><br/><br/>
<span style="color: red">Change name cost {{ setting('core.account_change_character_name_price') }} premium points. You have {{ points }} premium points.</span><br/><br/>
<form action="{{ getLink('account/character/name') }}" method="post">
<input type="hidden" name="changenamesave" value="1">
<div class="TableContainer">

View File

@ -1,5 +1,5 @@
To change a sex of character select player and choose a new sex.<br/>
<span style="color: red">Change sex cost {{ config.account_change_character_sex_points }} premium points. You have {{ points }} premium points.</span><br/><br/>
<span style="color: red">Change sex cost {{ setting('core.account_change_character_sex_price') }} premium points. You have {{ points }} premium points.</span><br/><br/>
<form action="{{ getLink('account/character/sex') }}" method="post">
<input type="hidden" name="changesexsave" value="1"/>
<div class="TableContainer">
@ -73,4 +73,4 @@ To change a sex of character select player and choose a new sex.<br/>
</table>
</td>
</tr>
</table>
</table>

View File

@ -1,5 +1,5 @@
To generate new recovery key for your account please enter your password.<br/>
<span style="color: red"><b>New recovery key cost {{ config.generate_new_reckey_price }} Premium Points.</span> You have {{ points }} premium points. You will receive e-mail with this recovery key.</b><br/>
<span style="color: red"><b>New recovery key cost {{ setting('core.account_generate_new_reckey_price') }} Premium Points.</span> You have {{ points }} premium points. You will receive e-mail with this recovery key.</b><br/>
<form action="{{ getLink('account/register/new') }}" method="post">
<input type="hidden" name="registeraccountsave" value="1">
<div class="TableContainer" >
@ -56,4 +56,4 @@ To generate new recovery key for your account please enter your password.<br/>
</table>
</td>
</tr>
</table>
</table>

View File

@ -39,10 +39,10 @@
{% for name, link in menus %}
<a href="{{ getLink(link) }}">{{ name }}</a>
{% endfor %}
{% if config.account_change_character_name %}
{% if setting('core.account_change_character_name') %}
<a href="{{ getLink('account/character/name') }}">Change Name</a>
{% endif %}
{% if config.account_change_character_sex %}
{% if setting('core.account_change_character_sex') %}
<a href="{{ getLink('account/character/sex') }}">Change Sex</a>
{% endif %}
<a href="{{ getLink('account/logout') }}">Logout</a>
@ -192,7 +192,7 @@
{% include('buttons.base.html.twig') %}
</form>
</td>
{% if config.account_change_character_name %}
{% if setting('core.account_change_character_name') %}
<td>
<form action="{{ getLink('account/character/name') }}" method="post" >
{% set button_name = 'Change Name' %}
@ -200,7 +200,7 @@
</form>
</td>
{% endif %}
{% if config.account_change_character_sex %}
{% if setting('core.account_change_character_sex') %}
<td>
<form action="{{ getLink('account/character/sex') }}" method="post" >
{% set button_name = 'Change Sex' %}

View File

@ -470,7 +470,7 @@
</form>
</table>
</td>
{% if config.account_change_character_name %}
{% if setting('core.account_change_character_name') %}
<td>
<table border="0" cellspacing="0" cellpadding="0" >
<form action="{{ getLink('account/character/name') }}" method="post" >
@ -483,7 +483,7 @@
</table>
</td>
{% endif %}
{% if config.account_change_character_sex %}
{% if setting('core.account_change_character_sex') %}
<td>
<table border="0" cellspacing="0" cellpadding="0" >
<form action="{{ getLink('account/character/sex') }}" method="post" >