eqemu-server/zone/gm_commands/setlanguage.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

58 lines
1.5 KiB
C++
Executable File

#include "../client.h"
#include "../../common/languages.h"
#include "../../common/data_verification.h"
void command_setlanguage(Client *c, const Seperator *sep)
{
auto target = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient();
}
auto language_id = sep->IsNumber(1) ? Strings::ToInt(sep->arg[1]) : -1;
auto language_value = sep->IsNumber(2) ? Strings::ToInt(sep->arg[2]) : -1;
if (!strcasecmp(sep->arg[1], "list")) {
for (const auto& language : EQ::constants::GetLanguageMap()) {
c->Message(
Chat::White,
fmt::format(
"Language {}: {}",
language.first,
language.second
).c_str()
);
}
} else if (
!EQ::ValueWithin(language_id, LANG_COMMON_TONGUE, LANG_UNKNOWN) ||
!EQ::ValueWithin(language_value, 0, 100)
) {
c->Message(Chat::White, "Usage: #setlanguage [Language ID] [Language Value]");
c->Message(Chat::White, "Usage: #setlanguage [List]");
c->Message(Chat::White, "Language ID = 0 to 27");
c->Message(Chat::White, "Language Value = 0 to 100");
} else {
LogInfo(
"Set language request from [{}], Target: [{}] Language ID: [{}] Language Value: [{}]",
c->GetCleanName(),
c->GetTargetDescription(target),
language_id,
language_value
);
target->SetLanguageSkill(language_id, language_value);
if (c != target) {
c->Message(
Chat::White,
fmt::format(
"Set {} ({}) to {} for {}.",
EQ::constants::GetLanguageName(language_id),
language_id,
language_value,
c->GetTargetDescription(target)
).c_str()
);
}
}
}