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

88 lines
2.4 KiB
C++
Executable File

#include "../client.h"
#include "../worldserver.h"
extern WorldServer worldserver;
void command_flag(Client *c, const Seperator *sep)
{
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;
}
if (
!sep->IsNumber(1) ||
strlen(sep->arg[2]) == 0
) {
c->Message(Chat::White, "Usage: #flag [Status] [Account Name]");
return;
}
auto status = Strings::ToInt(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 (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(account_name, user, loginserver);
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);
}
}
}