mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-09 12:23:53 +00:00
[Bug Fix] Find Zone - Expansion Settings (#4692)
* Bug Fix Find Zone - Expansion Settings #fz expansion 30 Would crash your zone since the expansions don't go up that high. This Adds a check for range out of bounds and provides an exception to expansion 99 since those are test/dev zones. * Update zone.cpp * Update zone.cpp * Update zone.cpp --------- Co-authored-by: Kinglykrab <kinglykrab@gmail.com>
This commit is contained in:
parent
55155ff800
commit
8315240b17
@ -1,35 +1,51 @@
|
||||
#include "../../client.h"
|
||||
#include "../../common/content/world_content_service.h"
|
||||
|
||||
void FindZone(Client *c, const Seperator *sep)
|
||||
void FindZone(Client* c, const Seperator* sep)
|
||||
{
|
||||
std::string query = "SELECT zoneidnumber, short_name, long_name, version FROM zone WHERE ";
|
||||
std::string where_filter = std::string();
|
||||
|
||||
const auto is_expansion_search = !strcasecmp(sep->arg[2], "expansion");
|
||||
const auto is_id_search = Strings::IsNumber(sep->arg[2]);
|
||||
const auto is_short_name_search = !is_expansion_search && !is_id_search;
|
||||
const bool is_expansion_search = !strcasecmp(sep->arg[2], "expansion");
|
||||
const bool is_id_search = Strings::IsNumber(sep->arg[2]);
|
||||
const bool is_short_name_search = !is_expansion_search && !is_id_search;
|
||||
|
||||
std::string search_string;
|
||||
std::string search_type;
|
||||
|
||||
if (is_expansion_search) {
|
||||
query += fmt::format(
|
||||
"expansion = {}",
|
||||
Strings::ToInt(sep->arg[3])
|
||||
);
|
||||
int expansion_id = Strings::ToInt(sep->arg[3]);
|
||||
|
||||
search_string = Expansion::ExpansionName[Strings::ToInt(sep->arg[3])];
|
||||
search_type = "expansion";
|
||||
if (
|
||||
!EQ::ValueWithin(expansion_id, Expansion::Classic, Expansion::MaxId - 1) &&
|
||||
expansion_id != Expansion::EXPANSION_FILTER_MAX
|
||||
) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Invalid expansion ID: {}. Please enter a value between 0 and {}, or 99.",
|
||||
expansion_id,
|
||||
Expansion::MaxId - 1
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
where_filter = fmt::format("expansion = {}", expansion_id);
|
||||
|
||||
if (expansion_id == Expansion::EXPANSION_FILTER_MAX) {
|
||||
search_string = "Test Zones";
|
||||
} else {
|
||||
search_string = Expansion::ExpansionName[expansion_id];
|
||||
}
|
||||
|
||||
search_type = "expansion";
|
||||
} else if (is_id_search) {
|
||||
query += fmt::format(
|
||||
"zoneidnumber = {}",
|
||||
Strings::ToUnsignedInt(sep->arg[2])
|
||||
);
|
||||
where_filter = fmt::format("zoneidnumber = {}", Strings::ToUnsignedInt(sep->arg[2]));
|
||||
|
||||
search_string = sep->arg[2];
|
||||
search_type = "ID";
|
||||
} else if (is_short_name_search) {
|
||||
query += fmt::format(
|
||||
where_filter = fmt::format(
|
||||
"LOWER(`long_name`) LIKE '%%{}%%' OR LOWER(`short_name`) LIKE '%%{}%%'",
|
||||
Strings::Escape(Strings::ToLower(sep->argplus[2])),
|
||||
Strings::Escape(Strings::ToLower(sep->argplus[2]))
|
||||
@ -39,35 +55,30 @@ void FindZone(Client *c, const Seperator *sep)
|
||||
search_type = "name";
|
||||
}
|
||||
|
||||
query += " ORDER BY `zoneidnumber` ASC LIMIT 50";
|
||||
where_filter += " ORDER BY `zoneidnumber` ASC LIMIT 50";
|
||||
|
||||
auto results = content_db.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
const auto& l = ZoneRepository::GetWhere(content_db, where_filter);
|
||||
|
||||
if (l.empty()) {
|
||||
c->Message(Chat::White, "No zones were found matching your search criteria.");
|
||||
c->Message(Chat::White, query.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto found_count = 0;
|
||||
|
||||
for (auto row : results) {
|
||||
const auto zone_id = Strings::ToUnsignedInt(row[0]);
|
||||
const std::string& short_name = row[1];
|
||||
const std::string& long_name = row[2];
|
||||
const auto version = Strings::ToInt(row[3]);
|
||||
uint32 found_count = 0;
|
||||
|
||||
for (const auto& e : l) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"{}{} {} ({}) (ID {}){}",
|
||||
(
|
||||
version == 0 ?
|
||||
e.version == 0 ?
|
||||
fmt::format(
|
||||
"{} | ",
|
||||
Saylink::Silent(
|
||||
fmt::format(
|
||||
"#zone {}",
|
||||
short_name
|
||||
e.short_name
|
||||
),
|
||||
"Zone"
|
||||
)
|
||||
@ -79,20 +90,20 @@ void FindZone(Client *c, const Seperator *sep)
|
||||
Saylink::Silent(
|
||||
fmt::format(
|
||||
"#gmzone {} {}",
|
||||
short_name,
|
||||
version
|
||||
e.short_name,
|
||||
e.version
|
||||
),
|
||||
"GM Zone"
|
||||
)
|
||||
),
|
||||
long_name,
|
||||
short_name,
|
||||
zone_id,
|
||||
e.long_name,
|
||||
e.short_name,
|
||||
e.zoneidnumber,
|
||||
(
|
||||
version != 0 ?
|
||||
e.version != 0 ?
|
||||
fmt::format(
|
||||
" (Version {})",
|
||||
version
|
||||
e.version
|
||||
) :
|
||||
""
|
||||
)
|
||||
@ -110,7 +121,7 @@ void FindZone(Client *c, const Seperator *sep)
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"50 Zones found matching '{}' of '{}'.",
|
||||
"50 Zones found matching '{}' of '{}', max reached.",
|
||||
search_type,
|
||||
search_string
|
||||
).c_str()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user