From b433615e683bb7ff8e004c2f28180878b5498a5a Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 22 Jul 2023 13:03:43 +0200 Subject: [PATCH] New setting: donate_column + move donate config to settings --- system/compat/config.php | 6 +- system/config.php | 8 --- system/pages/account/change_name.php | 10 ++-- system/pages/account/change_sex.php | 10 ++-- system/pages/account/manage.php | 2 +- system/pages/account/register_new.php | 16 +++--- system/settings.php | 55 +++++++++++++++++++ .../templates/account.change_name.html.twig | 2 +- system/templates/account.change_sex.html.twig | 4 +- ...ccount.generate_new_recovery_key.html.twig | 4 +- system/templates/account.management.html.twig | 8 +-- .../tibiacom/account.management.html.twig | 4 +- 12 files changed, 90 insertions(+), 39 deletions(-) diff --git a/system/compat/config.php b/system/compat/config.php index 4b9bedf0..ef329afa 100644 --- a/system/compat/config.php +++ b/system/compat/config.php @@ -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) { diff --git a/system/config.php b/system/config.php index 92b7c678..5fba18f4 100644 --- a/system/config.php +++ b/system/config.php @@ -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', diff --git a/system/pages/account/change_name.php b/system/pages/account/change_name.php index f6053733..ef82b9ad 100644 --- a/system/pages/account/change_name.php +++ b/system/pages/account/change_name.php @@ -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 '.$points.' 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 '.$points.' 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 ' . $old_name . ' to ' . $player->getName() . '.'); $twig->display('success.html.twig', array( 'title' => 'Character Name Changed', diff --git a/system/pages/account/change_sex.php b/system/pages/account/change_sex.php index 2f944564..7e43b6ff 100644 --- a/system/pages/account/change_sex.php +++ b/system/pages/account/change_sex.php @@ -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 '.$points.' 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 '.$points.' 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 ' . $player->getName() . ' from ' . $old_sex_str . ' to ' . $new_sex_str . '.'); $twig->display('success.html.twig', array( 'title' => 'Character Sex Changed', diff --git a/system/pages/account/manage.php b/system/pages/account/manage.php index 038bb15e..c4a8402a 100644 --- a/system/pages/account/manage.php +++ b/system/pages/account/manage.php @@ -35,7 +35,7 @@ if(empty($recovery_key)) $account_registered = 'No'; else { - if($config['generate_new_reckey'] && setting('core.mail_enabled')) + if(setting('core.account_generate_new_reckey') && setting('core.mail_enabled')) $account_registered = 'Yes ( Buy new Recovery Key )'; else $account_registered = 'Yes'; diff --git a/system/pages/account/register_new.php b/system/pages/account/register_new.php index 7a5b43dc..04e8bf33 100644 --- a/system/pages/account/register_new.php +++ b/system/pages/account/register_new.php @@ -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 = '
Your recovery key were send on email address '.$account_logged->getEMail().' 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 = '
Your recovery key were send on email address '.$account_logged->getEMail().' for '.setting('core.account_generate_new_reckey_price').' premium points.'; } else $message = '

An error occurred while sending email ( '.$account_logged->getEMail().' ) with recovery key! Recovery key not changed. Try again later. For Admin: More info can be found in system/logs/mailer-error.log

'; @@ -57,7 +57,7 @@ else )); } else - $errors[] = 'You need '.$config['generate_new_reckey_price'].' premium points to generate new recovery key. You have '.$points.' premium points.'; + $errors[] = 'You need ' . setting('core.account_generate_new_reckey_price') . ' premium points to generate new recovery key. You have '.$points.' premium points.'; } else $errors[] = 'Wrong password to account.'; diff --git a/system/settings.php b/system/settings.php index 96904363..04cea71f 100644 --- a/system/settings.php +++ b/system/settings.php @@ -1295,6 +1295,61 @@ Sent by MyAAC,
'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) { diff --git a/system/templates/account.change_name.html.twig b/system/templates/account.change_name.html.twig index bd1fa8f0..76c038d4 100644 --- a/system/templates/account.change_name.html.twig +++ b/system/templates/account.change_name.html.twig @@ -1,5 +1,5 @@ To change a name of character select player and choose a new name.
-Change name cost {{ config.account_change_character_name_points }} premium points. You have {{ points }} premium points.

+Change name cost {{ setting('core.account_change_character_name_price') }} premium points. You have {{ points }} premium points.

diff --git a/system/templates/account.change_sex.html.twig b/system/templates/account.change_sex.html.twig index 07ea83e9..24141f61 100644 --- a/system/templates/account.change_sex.html.twig +++ b/system/templates/account.change_sex.html.twig @@ -1,5 +1,5 @@ To change a sex of character select player and choose a new sex.
-Change sex cost {{ config.account_change_character_sex_points }} premium points. You have {{ points }} premium points.

+Change sex cost {{ setting('core.account_change_character_sex_price') }} premium points. You have {{ points }} premium points.

@@ -73,4 +73,4 @@ To change a sex of character select player and choose a new sex.
- \ No newline at end of file + diff --git a/system/templates/account.generate_new_recovery_key.html.twig b/system/templates/account.generate_new_recovery_key.html.twig index f1ec611b..6f3e5c50 100644 --- a/system/templates/account.generate_new_recovery_key.html.twig +++ b/system/templates/account.generate_new_recovery_key.html.twig @@ -1,5 +1,5 @@ To generate new recovery key for your account please enter your password.
-New recovery key cost {{ config.generate_new_reckey_price }} Premium Points. You have {{ points }} premium points. You will receive e-mail with this recovery key.
+New recovery key cost {{ setting('core.account_generate_new_reckey_price') }} Premium Points. You have {{ points }} premium points. You will receive e-mail with this recovery key.
@@ -56,4 +56,4 @@ To generate new recovery key for your account please enter your password.
- \ No newline at end of file + diff --git a/system/templates/account.management.html.twig b/system/templates/account.management.html.twig index 510c90a1..95fc0975 100644 --- a/system/templates/account.management.html.twig +++ b/system/templates/account.management.html.twig @@ -39,10 +39,10 @@ {% for name, link in menus %} {{ name }} {% endfor %} - {% if config.account_change_character_name %} + {% if setting('core.account_change_character_name') %} Change Name {% endif %} - {% if config.account_change_character_sex %} + {% if setting('core.account_change_character_sex') %} Change Sex {% endif %} Logout @@ -192,7 +192,7 @@ {% include('buttons.base.html.twig') %} - {% if config.account_change_character_name %} + {% if setting('core.account_change_character_name') %}
{% set button_name = 'Change Name' %} @@ -200,7 +200,7 @@
{% endif %} - {% if config.account_change_character_sex %} + {% if setting('core.account_change_character_sex') %}
{% set button_name = 'Change Sex' %} diff --git a/templates/tibiacom/account.management.html.twig b/templates/tibiacom/account.management.html.twig index 7c387c36..e1106e8c 100644 --- a/templates/tibiacom/account.management.html.twig +++ b/templates/tibiacom/account.management.html.twig @@ -470,7 +470,7 @@
- {% if config.account_change_character_name %} + {% if setting('core.account_change_character_name') %} @@ -483,7 +483,7 @@
{% endif %} - {% if config.account_change_character_sex %} + {% if setting('core.account_change_character_sex') %}