myaac
myaac copied to clipboard
[Suggestion] Cancel Deletion
hello you can add support to cancel deletion of characters in account page
This is something I had started working on in my bootstrap theme but due to health I stopped on all of my projects. I'm slowly coming back now so will look at updating this into the Dev version when I get some more time.
I planned on shrinking it down and tidying it up more
@Leesneaks, do you still plan to continue this?
Yes mate. But I've just had a baby so ATM I'm not working on any projects. As soon as things settle I plan on getting back onto my work.
Players often delete character to unlock it's name. So 'delete' action should change name of character and 'undelete' should change it back.
// code from other AAC
Delete player code - allows anyone to delete character:
$i = 0;
$nameCheckPlayer = new Player();
$nameCheckPlayer->find($player->generateDeletedName($i));
while ($nameCheckPlayer->isLoaded()) {
$i++;
$nameCheckPlayer->find($player->generateDeletedName($i));
}
$player->setName($player->generateDeletedName($i));
Undelete code - allows undelete only if no one else is using character name already:
$undeletePlayerName = $player->generateUndeletedName();
$testUndeletePlayerName = new Player($undeletePlayerName, Player::LOADTYPE_NAME);
if ($testUndeletePlayerName->isLoaded()) {
echo Website::messageError('Cannot undelete <b>' . htmlspecialchars($player->getName()) . '</b>!<br />' .
'Player with name <b>' . htmlspecialchars($undeletePlayerName) . '</b> already exists.<br />' .
'It must be renamed or deleted before you can undelete this character.');
return;
}
player.php
class code to generate delete/undelete names: allows players to delete character with name X -> create new character with name X -> delete new character X -> create another character with name X and so on
(expects real delete from database to take 7+ days, but allows to use player name just after deletion; also expects no [
in normal character names):
public function generateDeletedName($i)
{
if (substr($this->getName(), 0, 3) === '[D]')
throw new RuntimeException('Cannot generate delete name for deleted character.');
return '[D][' . $i . ']' . $this->getName();
}
public function generateUndeletedName()
{
if (substr($this->getName(), 0, 3) !== '[D]' || stripos($this->getName(), ']', 3) === false)
throw new RuntimeException('Cannot generate undelete name for not deleted character.');
return substr($this->getName(), stripos($this->getName(), ']', 3) + 1);
}