mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 20:51:29 +00:00
[Commands] Cleanup #suspend Command. (#2564)
- Cleanup messages and logic. - Use repositories.
This commit is contained in:
parent
0dfa067974
commit
3424fe78f5
@ -1,98 +1,89 @@
|
|||||||
#include "../client.h"
|
#include "../client.h"
|
||||||
#include "../worldserver.h"
|
#include "../worldserver.h"
|
||||||
|
#include "../../common/repositories/account_repository.h"
|
||||||
|
|
||||||
extern WorldServer worldserver;
|
extern WorldServer worldserver;
|
||||||
|
|
||||||
void command_suspend(Client *c, const Seperator *sep)
|
void command_suspend(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
if ((sep->arg[1][0] == 0) || (sep->arg[2][0] == 0)) {
|
auto arguments = sep->argnum;
|
||||||
|
if (arguments < 2 || !sep->IsNumber(2)) {
|
||||||
|
c->Message(Chat::White, "Usage: #suspend [Character Name] [Days] [Reason]");
|
||||||
|
c->Message(Chat::White, "Note: Specify 0 days to lift a suspension");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string character_name = sep->arg[1];
|
||||||
|
auto days = std::stoul(sep->arg[2]);
|
||||||
|
|
||||||
|
const std::string reason = sep->arg[3] ? sep->argplus[3] : "";
|
||||||
|
|
||||||
|
auto a = AccountRepository::GetWhere(
|
||||||
|
content_db,
|
||||||
|
fmt::format(
|
||||||
|
"charname = '{}'",
|
||||||
|
Strings::Escape(character_name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (a.empty() || !a[0].id) {
|
||||||
c->Message(
|
c->Message(
|
||||||
Chat::White,
|
Chat::White,
|
||||||
"Usage: #suspend <charname> <days> (Specify 0 days to lift the suspension immediately) <message>"
|
fmt::format(
|
||||||
|
"Character {} does not exist.",
|
||||||
|
character_name
|
||||||
|
).c_str()
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int duration = atoi(sep->arg[2]);
|
a[0].status = -1;
|
||||||
|
a[0].suspendeduntil = std::time(nullptr) + (days * 86400);
|
||||||
|
a[0].suspend_reason = reason;
|
||||||
|
|
||||||
if (duration < 0) {
|
if (!AccountRepository::UpdateOne(content_db, a[0])) {
|
||||||
duration = 0;
|
c->Message(
|
||||||
}
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
std::string message;
|
"Failed to suspend {}.",
|
||||||
|
character_name
|
||||||
if (duration > 0) {
|
).c_str()
|
||||||
int i = 3;
|
);
|
||||||
while (1) {
|
|
||||||
if (sep->arg[i][0] == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.length() > 0) {
|
|
||||||
message.push_back(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
message += sep->arg[i];
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.length() == 0) {
|
|
||||||
c->Message(
|
|
||||||
Chat::White,
|
|
||||||
"Usage: #suspend <charname> <days>(Specify 0 days to lift the suspension immediately) <message>"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto escName = new char[strlen(sep->arg[1]) * 2 + 1];
|
|
||||||
database.DoEscapeString(escName, sep->arg[1], strlen(sep->arg[1]));
|
|
||||||
int accountID = database.GetAccountIDByChar(escName);
|
|
||||||
safe_delete_array(escName);
|
|
||||||
|
|
||||||
if (accountID <= 0) {
|
|
||||||
c->Message(Chat::Red, "Character does not exist.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string query = StringFormat(
|
c->Message(
|
||||||
"UPDATE `account` SET `suspendeduntil` = DATE_ADD(NOW(), INTERVAL %i DAY), "
|
Chat::White,
|
||||||
"suspend_reason = '%s' WHERE `id` = %i",
|
fmt::format(
|
||||||
duration, Strings::Escape(message).c_str(), accountID
|
"Account {} ({}) with the character {} {}.",
|
||||||
|
a[0].name,
|
||||||
|
a[0].id,
|
||||||
|
character_name,
|
||||||
|
(
|
||||||
|
days ?
|
||||||
|
fmt::format(
|
||||||
|
"has been temporarily suspended for {} day{}.",
|
||||||
|
days,
|
||||||
|
days != 1 ? "s" : ""
|
||||||
|
) :
|
||||||
|
"is no longer suspended"
|
||||||
|
)
|
||||||
|
).c_str()
|
||||||
);
|
);
|
||||||
auto results = database.QueryDatabase(query);
|
|
||||||
|
|
||||||
if (duration) {
|
auto* b = entity_list.GetClientByName(character_name.c_str());
|
||||||
c->Message(
|
|
||||||
Chat::Red,
|
|
||||||
"Account number %i with the character %s has been temporarily suspended for %i day(s).",
|
|
||||||
accountID,
|
|
||||||
sep->arg[1],
|
|
||||||
duration
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
c->Message(
|
|
||||||
Chat::Red,
|
|
||||||
"Account number %i with the character %s is no longer suspended.",
|
|
||||||
accountID,
|
|
||||||
sep->arg[1]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Client *bannedClient = entity_list.GetClientByName(sep->arg[1]);
|
if (b) {
|
||||||
|
b->WorldKick();
|
||||||
if (bannedClient) {
|
|
||||||
bannedClient->WorldKick();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
|
||||||
ServerKickPlayer_Struct *sks = (ServerKickPlayer_Struct *) pack->pBuffer;
|
auto* k = (ServerKickPlayer_Struct *) pack->pBuffer;
|
||||||
|
|
||||||
strn0cpy(sks->adminname, c->GetName(), sizeof(sks->adminname));
|
strn0cpy(k->adminname, c->GetName(), sizeof(k->adminname));
|
||||||
strn0cpy(sks->name, sep->arg[1], sizeof(sks->name));
|
strn0cpy(k->name, character_name.c_str(), sizeof(k->name));
|
||||||
sks->adminrank = c->Admin();
|
k->adminrank = c->Admin();
|
||||||
|
|
||||||
worldserver.SendPacket(pack);
|
worldserver.SendPacket(pack);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user