mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
* [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>
99 lines
2.3 KiB
C++
Executable File
99 lines
2.3 KiB
C++
Executable File
#include "../client.h"
|
|
|
|
void command_findzone(Client *c, const Seperator *sep)
|
|
{
|
|
if (sep->arg[1][0] == 0) {
|
|
c->Message(Chat::White, "Usage: #findzone [search criteria]");
|
|
c->Message(Chat::White, "Usage: #findzone expansion [expansion number]");
|
|
return;
|
|
}
|
|
|
|
std::string query;
|
|
int id = Strings::ToInt((const char *) sep->arg[1]);
|
|
|
|
std::string arg1 = sep->arg[1];
|
|
|
|
if (arg1 == "expansion") {
|
|
query = fmt::format(
|
|
"SELECT zoneidnumber, short_name, long_name, version FROM zone WHERE expansion = {}",
|
|
sep->arg[2]
|
|
);
|
|
}
|
|
else {
|
|
|
|
/**
|
|
* If id evaluates to 0, then search as if user entered a string
|
|
*/
|
|
if (id == 0) {
|
|
query = fmt::format(
|
|
"SELECT zoneidnumber, short_name, long_name, version FROM zone WHERE long_name LIKE '%{}%' OR `short_name` LIKE '%{}%'",
|
|
Strings::Escape(sep->arg[1]),
|
|
Strings::Escape(sep->arg[1])
|
|
);
|
|
}
|
|
else {
|
|
query = fmt::format(
|
|
"SELECT zoneidnumber, short_name, long_name, version FROM zone WHERE zoneidnumber = {}",
|
|
id
|
|
);
|
|
}
|
|
}
|
|
|
|
auto results = content_db.QueryDatabase(query);
|
|
if (!results.Success()) {
|
|
c->Message(Chat::White, "Error querying database.");
|
|
c->Message(Chat::White, query.c_str());
|
|
return;
|
|
}
|
|
|
|
int count = 0;
|
|
const int maxrows = 100;
|
|
|
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
|
std::string zone_id = row[0];
|
|
std::string short_name = row[1];
|
|
std::string long_name = row[2];
|
|
int version = Strings::ToInt(row[3]);
|
|
|
|
if (++count > maxrows) {
|
|
c->Message(Chat::White, "%i zones shown. Too many results.", maxrows);
|
|
break;
|
|
}
|
|
|
|
std::string command_zone = Saylink::Silent("#zone " + short_name, "zone");
|
|
std::string command_gmzone = Saylink::Silent(
|
|
fmt::format(
|
|
"#gmzone {} {}",
|
|
short_name,
|
|
version
|
|
),
|
|
"gmzone"
|
|
);
|
|
|
|
c->Message(
|
|
Chat::White,
|
|
fmt::format(
|
|
"[{}] [{}] [{}] ID ({}) Version ({}) [{}]",
|
|
(version == 0 ? command_zone : "zone"),
|
|
command_gmzone,
|
|
short_name,
|
|
zone_id,
|
|
version,
|
|
long_name
|
|
).c_str()
|
|
);
|
|
}
|
|
|
|
if (count <= maxrows) {
|
|
c->Message(
|
|
Chat::White,
|
|
"Query complete. %i rows shown. %s",
|
|
count,
|
|
(arg1 == "expansion" ? "(expansion search)" : ""));
|
|
}
|
|
else if (count == 0) {
|
|
c->Message(Chat::White, "No matches found for %s.", sep->arg[1]);
|
|
}
|
|
}
|
|
|