diff --git a/zone/command.cpp b/zone/command.cpp index d5faf314e..7ed7b5e70 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -147,6 +147,7 @@ int command_init(void) command_add("size", "Change your targets size (alias of #feature size)", AccountStatus::QuestTroupe, command_feature) || command_add("findaa", "[Search Criteria] - Search for an AA", AccountStatus::Guide, command_findaa) || command_add("findaliases", "[Search Criteria]- Searches for available command aliases, by alias or command", AccountStatus::Player, command_findaliases) || + command_add("findcharacter", "[Search Criteria] - Search for a character", AccountStatus::Guide, command_findcharacter) || command_add("findclass", "[Search Criteria] - Search for a class", AccountStatus::Guide, command_findclass) || command_add("findfaction", "[Search Criteria] - Search for a faction", AccountStatus::Guide, command_findfaction) || command_add("findnpctype", "[Search Criteria] - Search database NPC types", AccountStatus::GMAdmin, command_findnpctype) || @@ -983,6 +984,7 @@ void command_bot(Client *c, const Seperator *sep) #include "gm_commands/faction.cpp" #include "gm_commands/feature.cpp" #include "gm_commands/findaa.cpp" +#include "gm_commands/findcharacter.cpp" #include "gm_commands/findclass.cpp" #include "gm_commands/findfaction.cpp" #include "gm_commands/findnpctype.cpp" diff --git a/zone/command.h b/zone/command.h index 3ab4153bd..663b7bc4f 100644 --- a/zone/command.h +++ b/zone/command.h @@ -88,6 +88,7 @@ void command_faction_association(Client *c, const Seperator *sep); void command_feature(Client *c, const Seperator *sep); void command_findaa(Client *c, const Seperator *sep); void command_findaliases(Client *c, const Seperator *sep); +void command_findcharacter(Client *c, const Seperator *sep); void command_findclass(Client *c, const Seperator *sep); void command_findfaction(Client *c, const Seperator *sep); void command_findnpctype(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/findcharacter.cpp b/zone/gm_commands/findcharacter.cpp new file mode 100755 index 000000000..811978af5 --- /dev/null +++ b/zone/gm_commands/findcharacter.cpp @@ -0,0 +1,93 @@ +#include "../client.h" +#include "../../common/repositories/character_data_repository.h" + +void command_findcharacter(Client *c, const Seperator *sep) +{ + const auto arguments = sep->argnum; + if (!arguments) { + c->Message(Chat::White, "Usage: #findcharacter [Search Criteria]"); + return; + } + + if (sep->IsNumber(1)) { + const auto character_id = std::stoul(sep->arg[1]); + + const auto& e = CharacterDataRepository::FindOne(content_db, character_id); + if (!e.id) { + c->Message( + Chat::White, + fmt::format( + "Character ID {} does not exist or is invalid.", + character_id + ).c_str() + ); + return; + } + + c->Message( + Chat::White, + fmt::format( + "Character ID {} | {}", + character_id, + e.name + ).c_str() + ); + } else { + const auto search_criteria = Strings::ToLower(sep->argplus[1]); + const auto& l = CharacterDataRepository::GetWhere( + content_db, + fmt::format( + "LOWER(`name`) LIKE '%%{}%%'", + search_criteria + ).c_str() + ); + if (l.empty()) { + c->Message( + Chat::White, + fmt::format( + "No characters found matching '{}'.", + sep->argplus[1] + ).c_str() + ); + } + + auto found_count = 0; + for (const auto& e : l) { + c->Message( + Chat::White, + fmt::format( + "Character ID {} | {}", + e.id, + e.name + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Characters found matching '{}', max reached.", + sep->argplus[1] + ).c_str() + ); + } else { + c->Message( + Chat::White, + fmt::format( + "{} Character{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[1] + ).c_str() + ); + } + } +} +