[Commands] Cleanup #ban, #ipban, #flag, #kick, #setlsinfo, and #setpass Commands. (#2104)

* [Commands] Cleanup #ban, #ipban, #flag, and #kick Commands.
- Cleanup messages and logic.
- Add ServerFlagUpdate_Struct for flag updates.

* Add #setlsinfo and #setpass to cleanup.

* Update setlsinfo.cpp

* Update database.cpp

* Update database.cpp

* Update command.cpp
This commit is contained in:
Kinglykrab
2022-05-07 23:28:45 -04:00
committed by GitHub
parent 07b46ed445
commit d9c41526e8
13 changed files with 312 additions and 227 deletions
+62 -28
View File
@@ -5,47 +5,81 @@ extern WorldServer worldserver;
void command_flag(Client *c, const Seperator *sep)
{
if (sep->arg[2][0] == 0) {
if (!c->GetTarget() || (c->GetTarget() && c->GetTarget() == c)) {
c->UpdateAdmin();
c->Message(Chat::White, "Refreshed your admin flag from DB.");
}
else if (c->GetTarget() && c->GetTarget() != c && c->GetTarget()->IsClient()) {
c->GetTarget()->CastToClient()->UpdateAdmin();
c->Message(Chat::White, "%s's admin flag has been refreshed.", c->GetTarget()->GetName());
c->GetTarget()->Message(Chat::White, "%s refreshed your admin flag.", c->GetName());
int arguments = sep->argnum;
if (!arguments) {
auto target = c->GetTarget() && c->GetTarget()->IsClient() ? c->GetTarget()->CastToClient() : c;
if (target != c) {
c->Message(
Chat::White,
fmt::format(
"Status level has been refreshed for {}.",
target->GetCleanName()
).c_str()
);
target->Message(
Chat::White,
fmt::format(
"Your status level has been refreshed by {}.",
c->GetCleanName()
).c_str()
);
} else {
c->Message(Chat::White, "Your status level has been refreshed.");
}
target->UpdateAdmin();
return;
}
else if (!sep->IsNumber(1) || atoi(sep->arg[1]) < -2 || atoi(sep->arg[1]) > 255 || strlen(sep->arg[2]) == 0) {
c->Message(Chat::White, "Usage: #flag [status] [acctname]");
if (
!sep->IsNumber(1) ||
strlen(sep->arg[2]) == 0
) {
c->Message(Chat::White, "Usage: #flag [Status] [Account Name]");
return;
}
else if (c->Admin() < commandChangeFlags) {
//this check makes banning players by less than this level
//impossible, but i'll leave it in anyways
auto status = std::stoi(sep->arg[1]);
if (status < -2 || status > 255) {
c->Message(Chat::White, "The lowest a status level can go is -2 and the highest a status level can go is 255.");
return;
}
std::string account_name = sep->argplus[2];
auto account_id = database.GetAccountIDByChar(account_name.c_str());
if (c->Admin() < commandChangeFlags) { //this check makes banning players by less than this level impossible, but i'll leave it in anyways
c->Message(Chat::White, "You may only refresh your own flag, doing so now.");
c->UpdateAdmin();
}
else {
if (atoi(sep->arg[1]) > c->Admin()) {
c->Message(Chat::White, "You cannot set people's status to higher than your own");
}
else if (atoi(sep->arg[1]) < 0 && c->Admin() < commandBanPlayers) {
c->Message(Chat::White, "You have too low of status to suspend/ban");
}
else if (!database.SetAccountStatus(sep->argplus[2], atoi(sep->arg[1]))) {
c->Message(Chat::White, "Unable to set GM Flag.");
} else {
if (status > c->Admin()) {
c->Message(
Chat::White,
fmt::format(
"You cannot set someone's status level to {} because your status level is only {}.",
status,
c->Admin()
).c_str()
);
} else if (status < 0 && c->Admin() < commandBanPlayers) {
c->Message(Chat::White, "Your status level is not high enough to ban or suspend.");
} else if (!database.SetAccountStatus(account_name, status)) {
c->Message(Chat::White, "Failed to set status level.");
}
else {
c->Message(Chat::White, "Set GM Flag on account.");
std::string user;
std::string loginserver;
ParseAccountString(sep->argplus[2], user, loginserver);
ParseAccountString(account_name, user, loginserver);
ServerPacket pack(ServerOP_FlagUpdate, 6);
*((uint32 *) pack.pBuffer) = database.GetAccountIDByName(user.c_str(), loginserver.c_str());
*((int16 *) &pack.pBuffer[4]) = atoi(sep->arg[1]);
account_id = database.GetAccountIDByName(account_name, loginserver);
ServerPacket pack(ServerOP_FlagUpdate, sizeof(ServerFlagUpdate_Struct));
ServerFlagUpdate_Struct *sfus = (ServerFlagUpdate_Struct *) pack.pBuffer;
sfus->account_id = account_id;
sfus->admin = status;
worldserver.SendPacket(&pack);
}
}