mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 00:46:46 +00:00
[Commands] Cleanup #delacct Command. (#2567)
- Cleanup messages and logic. - Use repositories.
This commit is contained in:
@@ -1,21 +1,75 @@
|
||||
#include "../client.h"
|
||||
#include "../../common/repositories/account_repository.h"
|
||||
|
||||
void command_delacct(Client *c, const Seperator *sep)
|
||||
{
|
||||
if (sep->arg[1][0] == 0) {
|
||||
c->Message(Chat::White, "Format: #delacct accountname");
|
||||
auto arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "Format: #delacct [Account ID|Account Name]");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
std::string user;
|
||||
std::string loginserver;
|
||||
ParseAccountString(sep->arg[1], user, loginserver);
|
||||
|
||||
if (database.DeleteAccount(user.c_str(), loginserver.c_str())) {
|
||||
c->Message(Chat::White, "The account was deleted.");
|
||||
uint32 account_id = 0;
|
||||
std::string account_name;
|
||||
|
||||
if (sep->IsNumber(1)) {
|
||||
account_id = std::stoul(sep->arg[1]);
|
||||
auto a = AccountRepository::FindOne(content_db, account_id);
|
||||
if (!a.id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Account ID {} does not exist or is invalid.",
|
||||
account_id
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
c->Message(Chat::White, "Unable to delete account.");
|
||||
|
||||
account_name = a.name;
|
||||
} else {
|
||||
account_name = sep->arg[1];
|
||||
auto a = AccountRepository::GetWhere(
|
||||
content_db,
|
||||
fmt::format(
|
||||
"`name` = '{}'",
|
||||
account_name
|
||||
)
|
||||
);
|
||||
|
||||
if (a.empty() || !a[0].id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Account {} does not exist or is invalid.",
|
||||
account_name
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
account_id = a[0].id;
|
||||
}
|
||||
|
||||
if (!AccountRepository::DeleteOne(content_db, account_id)) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Failed to delete account {} ({}).",
|
||||
account_name,
|
||||
account_id
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Successfully deleted account {} ({}).",
|
||||
account_name,
|
||||
account_id
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user