eqemu-server/zone/gm_commands/suspendmulti.cpp
Alex King 2a6cf8c8e7
[Strings] Add more number formatters (#2873)
* [Strings] Add more number formatters

# Notes
- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* [Strings] Add more number formatters

- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* Rebase cleanup

* Changes/benchmarks/tests

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2023-03-04 17:01:19 -06:00

94 lines
2.0 KiB
C++
Executable File

#include "../client.h"
#include "../worldserver.h"
#include "../../common/repositories/account_repository.h"
extern WorldServer worldserver;
void command_suspendmulti(Client *c, const Seperator *sep)
{
auto arguments = sep->argnum;
if (arguments < 2 || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #suspendmulti [Character Name|Character Name Two|etc] [Days] [Reason]");
c->Message(Chat::White, "Note: Specify 0 days to lift a suspension");
return;
}
const auto& n = Strings::Split(sep->arg[1], "|");
std::vector<std::string> v;
for (const auto& c : n) {
v.push_back(fmt::format("'{}'", Strings::ToLower(c)));
}
auto days = Strings::ToUnsignedInt(sep->arg[2]);
const std::string reason = sep->arg[3] ? sep->argplus[3] : "";
auto l = AccountRepository::GetWhere(
database,
fmt::format(
"LOWER(charname) IN ({})",
Strings::Implode(", ", v)
)
);
if (l.empty()) {
c->Message(Chat::White, "No characters found.");
return;
}
for (auto a : l) {
a.status = -1;
a.suspendeduntil = std::time(nullptr) + (days * 86400);
a.suspend_reason = reason;
if (!AccountRepository::UpdateOne(database, a)) {
c->Message(
Chat::White,
fmt::format(
"Failed to suspend Account {} ({}).",
a.name,
a.id
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Account {} ({}) {}.",
a.name,
a.id,
(
days ?
fmt::format(
"has been temporarily suspended for {} day{}.",
days,
days != 1 ? "s" : ""
) :
"is no longer suspended"
)
).c_str()
);
auto *b = entity_list.GetClientByAccID(a.id);
if (b) {
b->WorldKick();
return;
}
auto pack = new ServerPacket(ServerOP_KickPlayer, sizeof(ServerKickPlayer_Struct));
auto *k = (ServerKickPlayer_Struct *) pack->pBuffer;
strn0cpy(k->adminname, c->GetName(), sizeof(k->adminname));
k->account_id = a.id;
k->adminrank = c->Admin();
worldserver.SendPacket(pack);
safe_delete(pack);
}
}