mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-20 12:33:27 +02:00
Refactor account routes into sub folders
This commit is contained in:
76
system/pages/account/characters/change-comment.php
Normal file
76
system/pages/account/characters/change-comment.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Change comment
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Gesior <jerzyskalski@wp.pl>
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
|
||||
use MyAAC\Models\Player;
|
||||
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$title = 'Change Comment';
|
||||
require PAGES . 'account/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player = null;
|
||||
$player_name = isset($_REQUEST['name']) ? stripslashes(urldecode($_REQUEST['name'])) : null;
|
||||
$new_comment = isset($_POST['comment']) ? htmlspecialchars(stripslashes(substr($_POST['comment'],0,2000))) : NULL;
|
||||
$new_hideacc = isset($_POST['accountvisible']) ? (int)$_POST['accountvisible'] : NULL;
|
||||
|
||||
if($player_name != null) {
|
||||
if (Validator::characterName($player_name)) {
|
||||
$player = Player::query()
|
||||
->where('name', $player_name)
|
||||
->where('account_id', $account_logged->getId())
|
||||
->first();
|
||||
|
||||
if ($player) {
|
||||
if ($player->is_deleted) {
|
||||
$errors[] = 'This character is deleted.';
|
||||
$player = null;
|
||||
}
|
||||
|
||||
if (isset($_POST['changecommentsave']) && $_POST['changecommentsave'] == 1) {
|
||||
if(empty($errors)) {
|
||||
$player->hide = $new_hideacc;
|
||||
$player->comment = $new_comment;
|
||||
$player->save();
|
||||
$account_logged->logAction('Changed comment for character <b>' . $player->name . '</b>.');
|
||||
$twig->display('success.html.twig', array(
|
||||
'title' => 'Character Information Changed',
|
||||
'description' => 'The character information has been changed.'
|
||||
));
|
||||
$show_form = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errors[] = "Error. Character with this name doesn't exist.";
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Error. Name contain illegal characters.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = 'Please enter character name.';
|
||||
}
|
||||
|
||||
if($show_form) {
|
||||
if(!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
if(isset($player) && $player) {
|
||||
$twig->display('account.characters.change-comment.html.twig', array(
|
||||
'player' => $player->toArray()
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
118
system/pages/account/characters/change-name.php
Normal file
118
system/pages/account/characters/change-name.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Change characters name
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Gesior <jerzyskalski@wp.pl>
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$title = 'Change Name';
|
||||
require PAGES . 'account/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL;
|
||||
$name = isset($_POST['name']) ? stripslashes(ucwords(strtolower($_POST['name']))) : NULL;
|
||||
if((!setting('core.account_change_character_name')))
|
||||
echo 'Changing character name for premium points is disabled on this server.';
|
||||
else
|
||||
{
|
||||
$points = $account_logged->getCustomField(setting('core.donate_column'));
|
||||
if(isset($_POST['changenamesave']) && $_POST['changenamesave'] == 1) {
|
||||
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');
|
||||
|
||||
if(empty($errors) && empty($name))
|
||||
$errors[] = 'Please enter a new name for your character!';
|
||||
else if(strlen($name) > $maxLength)
|
||||
$errors['name'] = 'Name is too long. Max. length <b>'.$maxLength.'</b> letters.';
|
||||
else if(strlen($name) < $minLength)
|
||||
$errors['name'] = 'Name is too short. Min. length <b>'.$minLength.'</b> letters.';
|
||||
|
||||
if(empty($errors))
|
||||
{
|
||||
if(!admin() && !Validator::newCharacterName($name))
|
||||
$errors[] = Validator::getLastError();
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
$player = new OTS_Player();
|
||||
$player->load($player_id);
|
||||
if($player->isLoaded()) {
|
||||
$player_account = $player->getAccount();
|
||||
if($account_logged->getId() == $player_account->getId()) {
|
||||
if ($player->isDeleted()) {
|
||||
$errors[] = 'This character is deleted.';
|
||||
}
|
||||
|
||||
if($player->isOnline()) {
|
||||
$errors[] = 'This character is online.';
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
$show_form = false;
|
||||
$old_name = $player->getName();
|
||||
$player->setName($name);
|
||||
$player->save();
|
||||
|
||||
if ($db->hasTable('player_deaths') &&
|
||||
$db->hasColumn('player_deaths', 'mostdamage_is_player') &&
|
||||
$db->hasColumn('player_deaths', 'killed_by')) {
|
||||
|
||||
$namesToChange = $db->query('SELECT `player_id`, `time`, `is_player`, `killed_by`, `mostdamage_is_player`, `mostdamage_by` FROM `player_deaths` WHERE (`is_player` = 1 AND `killed_by` = ' . $db->quote($old_name) . ') OR (`mostdamage_is_player` = 1 AND `mostdamage_by` = ' . $db->quote($old_name) . ');');
|
||||
|
||||
if ($namesToChange->rowCount() > 0) {
|
||||
foreach ($namesToChange->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$changeKey = '';
|
||||
if ($row['is_player'] == '1' && $row['killed_by'] == $old_name) {
|
||||
$changeKey = 'killed_by';
|
||||
} else if ($row['mostdamage_is_player'] == '1' && $row['mostdamage_by'] == $old_name) {
|
||||
$changeKey = 'mostdamage_by';
|
||||
}
|
||||
|
||||
if (!empty($changeKey)) {
|
||||
$db->update('player_deaths', [$changeKey => $name], ['player_id' => $row['player_id'], 'time' => $row['time']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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',
|
||||
'description' => 'The character <b>'.$old_name.'</b> name has been changed to <b>' . $player->getName() . '</b>.'
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = 'Character is not on your account.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = "Character with this name doesn't exist.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($show_form) {
|
||||
if(!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
$twig->display('account.characters.change-name.html.twig', array(
|
||||
'points' => $points,
|
||||
'errors' => $errors
|
||||
//'account_players' => $account_logged->getPlayersList()
|
||||
));
|
||||
}
|
||||
}
|
97
system/pages/account/characters/change-sex.php
Normal file
97
system/pages/account/characters/change-sex.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Change sex
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Gesior <jerzyskalski@wp.pl>
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$title = 'Change Sex';
|
||||
require PAGES . 'account/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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((!setting('core.account_change_character_sex')))
|
||||
echo 'You cant change your character sex';
|
||||
else
|
||||
{
|
||||
$points = $account_logged->getCustomField(setting('core.donate_column'));
|
||||
if(isset($_POST['changesexsave']) && $_POST['changesexsave'] == 1) {
|
||||
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.';
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
$player = new OTS_Player();
|
||||
$player->load($player_id);
|
||||
|
||||
if($player->isLoaded()) {
|
||||
$player_account = $player->getAccount();
|
||||
|
||||
if($account_logged->getId() == $player_account->getId()) {
|
||||
if ($player->isDeleted()) {
|
||||
$errors[] = 'This character is deleted.';
|
||||
}
|
||||
|
||||
if($player->isOnline()) {
|
||||
$errors[] = 'This character is online.';
|
||||
}
|
||||
|
||||
if(empty($errors) && $player->getSex() == $new_sex)
|
||||
$errors[] = 'Sex cannot be same';
|
||||
|
||||
if(empty($errors)) {
|
||||
$sex_changed = true;
|
||||
$old_sex = $player->getSex();
|
||||
$player->setSex($new_sex);
|
||||
|
||||
$old_sex_str = 'Unknown';
|
||||
if(isset($config['genders'][$old_sex]))
|
||||
$old_sex_str = $config['genders'][$old_sex];
|
||||
|
||||
$new_sex_str = 'Unknown';
|
||||
if(isset($config['genders'][$new_sex]))
|
||||
$new_sex_str = $config['genders'][$new_sex];
|
||||
|
||||
$player->save();
|
||||
$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',
|
||||
'description' => 'The character <b>' . $player->getName() . '</b> sex has been changed to <b>' . $new_sex_str . '</b>.'
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = 'Character is not on your account.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = "Character with this name doesn't exist.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$sex_changed) {
|
||||
if(!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
$twig->display('account.characters.change-sex.html.twig', array(
|
||||
'players' => $account_logged->getPlayersList(false),
|
||||
'player_sex' => isset($player) ? $player->getSex() : -1,
|
||||
'points' => $points
|
||||
));
|
||||
}
|
||||
}
|
54
system/pages/account/characters/create.php
Normal file
54
system/pages/account/characters/create.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Create character
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Gesior <jerzyskalski@wp.pl>
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
|
||||
use MyAAC\CreateCharacter;
|
||||
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$title = 'Create Character';
|
||||
require PAGES . 'account/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$character_name = isset($_POST['name']) ? stripslashes($_POST['name']) : null;
|
||||
$character_sex = isset($_POST['sex']) ? (int)$_POST['sex'] : null;
|
||||
$character_vocation = isset($_POST['vocation']) ? (int)$_POST['vocation'] : null;
|
||||
$character_town = isset($_POST['town']) ? (int)$_POST['town'] : null;
|
||||
|
||||
if (!admin() && !empty($character_name)) {
|
||||
$character_name = ucwords(strtolower($character_name));
|
||||
}
|
||||
|
||||
$character_created = false;
|
||||
$save = isset($_POST['save']) && $_POST['save'] == 1;
|
||||
$errors = array();
|
||||
if($save) {
|
||||
$createCharacter = new CreateCharacter();
|
||||
|
||||
$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors);
|
||||
}
|
||||
|
||||
if(count($errors) > 0) {
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
if(!$character_created) {
|
||||
$twig->display('account.characters.create.html.twig', array(
|
||||
'name' => $character_name,
|
||||
'sex' => $character_sex,
|
||||
'vocation' => $character_vocation,
|
||||
'town' => $character_town,
|
||||
'save' => $save,
|
||||
'errors' => $errors
|
||||
));
|
||||
}
|
97
system/pages/account/characters/delete.php
Normal file
97
system/pages/account/characters/delete.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Delete character
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Gesior <jerzyskalski@wp.pl>
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$title = 'Delete Character';
|
||||
require PAGES . 'account/base.php';
|
||||
|
||||
if(!$logged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player_name = isset($_POST['delete_name']) ? stripslashes($_POST['delete_name']) : null;
|
||||
$password_verify = isset($_POST['delete_password']) ? $_POST['delete_password'] : null;
|
||||
$password_verify = encrypt((USE_ACCOUNT_SALT ? $account_logged->getCustomField('salt') : '') . $password_verify);
|
||||
if(isset($_POST['deletecharactersave']) && $_POST['deletecharactersave'] == 1) {
|
||||
if(empty($player_name) || empty($password_verify)) {
|
||||
$errors[] = 'Character name or/and password is empty. Please fill in form.';
|
||||
}
|
||||
|
||||
if(empty($errors) && !Validator::characterName($player_name)) {
|
||||
$errors[] = 'Name contain illegal characters.';
|
||||
}
|
||||
|
||||
$player = new OTS_Player();
|
||||
$player->find($player_name);
|
||||
if(empty($errors) && !$player->isLoaded()) {
|
||||
$errors[] = 'Character with this name doesn\'t exist.';
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
$player_account = $player->getAccount();
|
||||
if($account_logged->getId() != $player_account->getId()) {
|
||||
$errors[] = 'Character <b>' . $player_name . '</b> is not on your account.';
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($errors) && $password_verify != $account_logged->getPassword()) {
|
||||
$errors[] = 'Wrong password to account.';
|
||||
}
|
||||
|
||||
if(empty($errors) && $player->isOnline()) {
|
||||
$errors[] = 'This character is online.';
|
||||
}
|
||||
|
||||
if(empty($errors) && $player->isDeleted()) {
|
||||
$errors[] = 'This player has been already deleted.';
|
||||
}
|
||||
|
||||
if(empty($errors) && $db->hasColumn('houses', 'id')) {
|
||||
$house = $db->query('SELECT `id` FROM `houses` WHERE `owner` = '.$player->getId());
|
||||
if($house->rowCount() > 0) {
|
||||
$errors[] = 'You cannot delete a character when they own a home.';
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
$ownerid = 'ownerid';
|
||||
if ($db->hasColumn('guilds', 'owner_id'))
|
||||
$ownerid = 'owner_id';
|
||||
$guild = $db->query('SELECT `name` FROM `guilds` WHERE `' . $ownerid . '` = ' . $player->getId());
|
||||
if ($guild->rowCount() > 0) {
|
||||
$errors[] = 'You cannot delete a character when they own a guild.';
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
// don't show table "delete character" again
|
||||
$show_form = false;
|
||||
/** @var OTS_DB_MySQL $db */
|
||||
if ($db->hasColumn('players', 'deletion'))
|
||||
$player->setCustomField('deletion', 1);
|
||||
else
|
||||
$player->setCustomField('deleted', 1);
|
||||
|
||||
$account_logged->logAction('Deleted character <b>' . $player->getName() . '</b>.');
|
||||
$twig->display('success.html.twig', [
|
||||
'title' => 'Character Deleted',
|
||||
'description' => 'The character <b>' . $player_name . '</b> has been deleted.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if($show_form) {
|
||||
if(!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
$twig->display('account.characters.delete.html.twig');
|
||||
}
|
Reference in New Issue
Block a user