From 42a2e19e73e3dbd9fc3b2ea362a8a978cd5d1e87 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:53:20 -0400 Subject: [PATCH] [Commands] Consolidate #findX commands to a singular #find Command (#3452) * Push up example for Kingly * Update aa.cpp * Update find.cpp * Bulk push. * Update aa.cpp * Cleanup * Repository method. * Static aliasing * Aliases * Fix alias error. * Update zone.cpp * Update command.cpp * Update find.cpp --------- Co-authored-by: Akkadius --- .../repositories/base/base_items_repository.h | 24 ++-- common/repositories/items_repository.h | 28 ++++ .../generators/repository-generator.pl | 3 +- zone/command.cpp | 90 +++++++----- zone/command.h | 17 +-- zone/gm_commands/find.cpp | 97 +++++++++++++ zone/gm_commands/find/aa.cpp | 88 ++++++++++++ zone/gm_commands/find/character.cpp | 95 ++++++++++++ zone/gm_commands/find/class.cpp | 80 +++++++++++ zone/gm_commands/find/currency.cpp | 131 +++++++++++++++++ zone/gm_commands/find/deity.cpp | 69 +++++++++ zone/gm_commands/find/faction.cpp | 84 +++++++++++ zone/gm_commands/find/item.cpp | 135 ++++++++++++++++++ zone/gm_commands/find/language.cpp | 64 +++++++++ zone/gm_commands/find/npctype.cpp | 94 ++++++++++++ zone/gm_commands/find/race.cpp | 96 +++++++++++++ zone/gm_commands/find/recipe.cpp | 130 +++++++++++++++++ zone/gm_commands/find/skill.cpp | 83 +++++++++++ zone/gm_commands/find/spell.cpp | 104 ++++++++++++++ zone/gm_commands/find/task.cpp | 109 ++++++++++++++ zone/gm_commands/find/zone.cpp | 132 +++++++++++++++++ zone/gm_commands/findaa.cpp | 100 ------------- zone/gm_commands/findcharacter.cpp | 93 ------------ zone/gm_commands/findclass.cpp | 92 ------------ zone/gm_commands/findcurrency.cpp | 134 ----------------- zone/gm_commands/finddeity.cpp | 73 ---------- zone/gm_commands/findfaction.cpp | 89 ------------ zone/gm_commands/findlanguage.cpp | 77 ---------- zone/gm_commands/findnpctype.cpp | 77 ---------- zone/gm_commands/findrace.cpp | 94 ------------ zone/gm_commands/findrecipe.cpp | 96 ------------- zone/gm_commands/findskill.cpp | 90 ------------ zone/gm_commands/findspell.cpp | 90 ------------ zone/gm_commands/findtask.cpp | 90 ------------ zone/gm_commands/findzone.cpp | 98 ------------- zone/gm_commands/itemsearch.cpp | 121 ---------------- 36 files changed, 1688 insertions(+), 1479 deletions(-) create mode 100644 zone/gm_commands/find.cpp create mode 100644 zone/gm_commands/find/aa.cpp create mode 100644 zone/gm_commands/find/character.cpp create mode 100644 zone/gm_commands/find/class.cpp create mode 100644 zone/gm_commands/find/currency.cpp create mode 100644 zone/gm_commands/find/deity.cpp create mode 100644 zone/gm_commands/find/faction.cpp create mode 100644 zone/gm_commands/find/item.cpp create mode 100644 zone/gm_commands/find/language.cpp create mode 100644 zone/gm_commands/find/npctype.cpp create mode 100644 zone/gm_commands/find/race.cpp create mode 100644 zone/gm_commands/find/recipe.cpp create mode 100644 zone/gm_commands/find/skill.cpp create mode 100644 zone/gm_commands/find/spell.cpp create mode 100644 zone/gm_commands/find/task.cpp create mode 100644 zone/gm_commands/find/zone.cpp delete mode 100755 zone/gm_commands/findaa.cpp delete mode 100755 zone/gm_commands/findcharacter.cpp delete mode 100755 zone/gm_commands/findclass.cpp delete mode 100755 zone/gm_commands/findcurrency.cpp delete mode 100755 zone/gm_commands/finddeity.cpp delete mode 100755 zone/gm_commands/findfaction.cpp delete mode 100755 zone/gm_commands/findlanguage.cpp delete mode 100755 zone/gm_commands/findnpctype.cpp delete mode 100755 zone/gm_commands/findrace.cpp delete mode 100755 zone/gm_commands/findrecipe.cpp delete mode 100755 zone/gm_commands/findskill.cpp delete mode 100755 zone/gm_commands/findspell.cpp delete mode 100755 zone/gm_commands/findtask.cpp delete mode 100755 zone/gm_commands/findzone.cpp delete mode 100755 zone/gm_commands/itemsearch.cpp diff --git a/common/repositories/base/base_items_repository.h b/common/repositories/base/base_items_repository.h index ef908262e..06d91ade0 100644 --- a/common/repositories/base/base_items_repository.h +++ b/common/repositories/base/base_items_repository.h @@ -16,6 +16,7 @@ #include "../../strings.h" #include + class BaseItemsRepository { public: struct Items { @@ -122,7 +123,7 @@ public: int32_t pr; int32_t procrate; int32_t races; - int32_t range; + int32_t range_; int32_t reclevel; int32_t recskill; int32_t reqlevel; @@ -417,7 +418,7 @@ public: "pr", "procrate", "races", - "range", + "`range`", "reclevel", "recskill", "reqlevel", @@ -708,7 +709,7 @@ public: "pr", "procrate", "races", - "range", + "`range`", "reclevel", "recskill", "reqlevel", @@ -1033,7 +1034,7 @@ public: e.pr = 0; e.procrate = 0; e.races = 0; - e.range = 0; + e.range_ = 0; e.reclevel = 0; e.recskill = 0; e.reqlevel = 0; @@ -1240,8 +1241,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), items_id ) ); @@ -1353,7 +1355,7 @@ public: e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); - e.range = static_cast(atoi(row[103])); + e.range_ = static_cast(atoi(row[103])); e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); @@ -1671,7 +1673,7 @@ public: v.push_back(columns[100] + " = " + std::to_string(e.pr)); v.push_back(columns[101] + " = " + std::to_string(e.procrate)); v.push_back(columns[102] + " = " + std::to_string(e.races)); - v.push_back(columns[103] + " = " + std::to_string(e.range)); + v.push_back(columns[103] + " = " + std::to_string(e.range_)); v.push_back(columns[104] + " = " + std::to_string(e.reclevel)); v.push_back(columns[105] + " = " + std::to_string(e.recskill)); v.push_back(columns[106] + " = " + std::to_string(e.reqlevel)); @@ -1977,7 +1979,7 @@ public: v.push_back(std::to_string(e.pr)); v.push_back(std::to_string(e.procrate)); v.push_back(std::to_string(e.races)); - v.push_back(std::to_string(e.range)); + v.push_back(std::to_string(e.range_)); v.push_back(std::to_string(e.reclevel)); v.push_back(std::to_string(e.recskill)); v.push_back(std::to_string(e.reqlevel)); @@ -2291,7 +2293,7 @@ public: v.push_back(std::to_string(e.pr)); v.push_back(std::to_string(e.procrate)); v.push_back(std::to_string(e.races)); - v.push_back(std::to_string(e.range)); + v.push_back(std::to_string(e.range_)); v.push_back(std::to_string(e.reclevel)); v.push_back(std::to_string(e.recskill)); v.push_back(std::to_string(e.reqlevel)); @@ -2609,7 +2611,7 @@ public: e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); - e.range = static_cast(atoi(row[103])); + e.range_ = static_cast(atoi(row[103])); e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); @@ -2918,7 +2920,7 @@ public: e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); - e.range = static_cast(atoi(row[103])); + e.range_ = static_cast(atoi(row[103])); e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); diff --git a/common/repositories/items_repository.h b/common/repositories/items_repository.h index aac7d3697..d2c2cbc3a 100644 --- a/common/repositories/items_repository.h +++ b/common/repositories/items_repository.h @@ -44,7 +44,35 @@ public: */ // Custom extended repository methods here + static std::vector GetItemIDsBySearchCriteria( + Database& db, + std::string search_string, + int query_limit = 0 + ) + { + auto query = fmt::format( + "SELECT `id` FROM {} WHERE LOWER(`name`) LIKE '%%{}%%' ORDER BY id ASC", + TableName(), + search_string + ); + if (query_limit >= 1) { + query += fmt::format(" LIMIT {}", query_limit); + } + + std::vector item_id_list; + + auto results = db.QueryDatabase(query); + if (!results.Success() || !results.RowCount()) { + return item_id_list; + } + + for (auto row : results) { + item_id_list.emplace_back(Strings::ToInt(row[0])); + } + + return item_id_list; + } }; #endif //EQEMU_ITEMS_REPOSITORY_H diff --git a/utils/scripts/generators/repository-generator.pl b/utils/scripts/generators/repository-generator.pl index a943613ba..507a3e05a 100644 --- a/utils/scripts/generators/repository-generator.pl +++ b/utils/scripts/generators/repository-generator.pl @@ -586,7 +586,8 @@ sub get_reserved_cpp_variable_names { return ( "class", "int", - "key" + "key", + "range" ); } diff --git a/zone/command.cpp b/zone/command.cpp index 210a67ed8..d804cfd96 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -137,21 +137,7 @@ int command_init(void) command_add("factionassociation", "[factionid] [amount] - triggers a faction hits via association", AccountStatus::GMLeadAdmin, command_faction_association) || command_add("feature", "Change your or your target's feature's temporarily", AccountStatus::QuestTroupe, command_feature) || 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("findcurrency", "[Search Criteria] - Search for an alternate currency", AccountStatus::Guide, command_findcurrency) || - command_add("finddeity", "[Search Criteria] - Search for a deity", AccountStatus::Guide, command_finddeity) || - command_add("findfaction", "[Search Criteria] - Search for a faction", AccountStatus::Guide, command_findfaction) || - command_add("findlanguage", "[Search Criteria] - Search for a language", AccountStatus::Guide, command_findlanguage) || - command_add("findnpctype", "[Search Criteria] - Search database NPC types", AccountStatus::GMAdmin, command_findnpctype) || - command_add("findrace", "[Search Criteria] - Search for a race", AccountStatus::Guide, command_findrace) || - command_add("findrecipe", "[Search Criteria] - Search for a recipe", AccountStatus::Guide, command_findrecipe) || - command_add("findskill", "[Search Criteria] - Search for a skill", AccountStatus::Guide, command_findskill) || - command_add("findspell", "[Search Criteria] - Search for a spell", AccountStatus::Guide, command_findspell) || - command_add("findtask", "[Search Criteria] - Search for a task", AccountStatus::Guide, command_findtask) || - command_add("findzone", "[Search Criteria] - Search database zones", AccountStatus::GMAdmin, command_findzone) || + command_add("find", "Search command used to find various things", AccountStatus::Guide, command_find) || command_add("fixmob", "[race|gender|texture|helm|face|hair|haircolor|beard|beardcolor|heritage|tattoo|detail] [next|prev] - Manipulate appearance of your target", AccountStatus::QuestTroupe, command_fixmob) || command_add("flag", "[Status] [Account Name] - Refresh your admin status, or set an account's Admin status if arguments provided", AccountStatus::Player, command_flag) || command_add("flagedit", "Edit zone flags on your target. Use #flagedit help for more info.", AccountStatus::GMAdmin, command_flagedit) || @@ -191,7 +177,6 @@ int command_init(void) command_add("invul", "[On|Off]] - Turn player target's or your invulnerable flag on or off", AccountStatus::QuestTroupe, command_invul) || command_add("ipban", "[IP] - Ban IP", AccountStatus::GMMgmt, command_ipban) || command_add("iplookup", "[charname] - Look up IP address of charname", AccountStatus::GMMgmt, command_iplookup) || - command_add("itemsearch", "[Search Criteria] - Search for an item", AccountStatus::Steward, command_itemsearch) || command_add("kick", "[Character Name] - Disconnect a player by name", AccountStatus::GMLeadAdmin, command_kick) || command_add("kill", "Kill your target", AccountStatus::GMAdmin, command_kill) || command_add("killallnpcs", "[npc_name] - Kills all npcs by search name, leave blank for all attackable NPC's", AccountStatus::GMMgmt, command_killallnpcs) || @@ -376,6 +361,51 @@ int command_init(void) std::vector> injected_command_settings; std::vector orphaned_command_settings; + // static aliases + struct StaticAlias { + std::string command; + std::vector aliases; + }; + + std::vector static_aliases = { + { + .command = "find", + .aliases = { + "fi", + "fn", + "fs", + "fz", + "findaa", + "findcharacter", + "findclass", + "findcurrency", + "finddeity", + "findfaction", + "finditem", + "findlanguage", + "findnpc", + "findnpctype", + "findrace", + "findrecipe", + "findskill", + "findspell", + "findtask", + "findzone", + } + }, + }; + + // inject static aliases + for (auto& cs : command_settings) { + for (const auto& sa : static_aliases) { + if (cs.first == sa.command) { + for (const auto& alias : sa.aliases) { + cs.second.second.emplace_back(alias); + } + } + } + } + for (const auto& cs : command_settings) { auto cl = commandlist.find(cs.first); if (cl == commandlist.end()) { @@ -387,7 +417,7 @@ int command_init(void) } } - if (orphaned_command_settings.size()) { + if (!orphaned_command_settings.empty()) { if (!database.UpdateOrphanedCommandSettings(orphaned_command_settings)) { LogInfo("Failed to process 'Orphaned Commands' update operation."); } @@ -397,16 +427,16 @@ int command_init(void) for (const auto& w : working_cl) { auto cs = command_settings.find(w.first); if (cs == command_settings.end()) { - injected_command_settings.emplace_back(std::pair(w.first, w.second->admin)); + injected_command_settings.emplace_back(w.first, w.second->admin); LogInfo( - "New Command [{}] found... Adding to `command_settings` table with admin [{}]...", + "New Command [{}] found. Adding to `command_settings` table with admin [{}]...", w.first, w.second->admin ); if (w.second->admin == AccountStatus::Player) { LogCommands( - "command_init(): Warning: Command [{}] defaulting to admin level 0!", + "Warning: Command [{}] defaulting to admin level 0!", w.first ); } @@ -416,7 +446,7 @@ int command_init(void) w.second->admin = cs->second.first; LogCommands( - "command_init(): - Command [{}] set to admin level [{}]", + "Command [{}] set to admin level [{}]", w.first, cs->second.first ); @@ -450,7 +480,7 @@ int command_init(void) } } - if (injected_command_settings.size()) { + if (!injected_command_settings.empty()) { if (!database.UpdateInjectedCommandSettings(injected_command_settings)) { LogInfo("Failed to process 'Injected Commands' update operation."); } @@ -981,20 +1011,7 @@ void command_bot(Client *c, const Seperator *sep) #include "gm_commands/exptoggle.cpp" #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/findcurrency.cpp" -#include "gm_commands/finddeity.cpp" -#include "gm_commands/findfaction.cpp" -#include "gm_commands/findlanguage.cpp" -#include "gm_commands/findnpctype.cpp" -#include "gm_commands/findrace.cpp" -#include "gm_commands/findrecipe.cpp" -#include "gm_commands/findskill.cpp" -#include "gm_commands/findspell.cpp" -#include "gm_commands/findtask.cpp" -#include "gm_commands/findzone.cpp" +#include "gm_commands/find.cpp" #include "gm_commands/fixmob.cpp" #include "gm_commands/flag.cpp" #include "gm_commands/flagedit.cpp" @@ -1032,7 +1049,6 @@ void command_bot(Client *c, const Seperator *sep) #include "gm_commands/invul.cpp" #include "gm_commands/ipban.cpp" #include "gm_commands/iplookup.cpp" -#include "gm_commands/itemsearch.cpp" #include "gm_commands/kick.cpp" #include "gm_commands/kill.cpp" #include "gm_commands/killallnpcs.cpp" diff --git a/zone/command.h b/zone/command.h index 22d591cdb..5eb3ee905 100644 --- a/zone/command.h +++ b/zone/command.h @@ -87,21 +87,7 @@ void command_exptoggle(Client *c, const Seperator *sep); void command_faction(Client *c, const Seperator *sep); 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_findcurrency(Client *c, const Seperator *sep); -void command_finddeity(Client *c, const Seperator *sep); -void command_findfaction(Client *c, const Seperator *sep); -void command_findlanguage(Client *c, const Seperator *sep); -void command_findnpctype(Client *c, const Seperator *sep); -void command_findrace(Client *c, const Seperator *sep); -void command_findrecipe(Client *c, const Seperator *sep); -void command_findskill(Client *c, const Seperator *sep); -void command_findspell(Client *c, const Seperator *sep); -void command_findtask(Client *c, const Seperator *sep); -void command_findzone(Client *c, const Seperator *sep); +void command_find(Client *c, const Seperator *sep); void command_fixmob(Client *c, const Seperator *sep); void command_flag(Client *c, const Seperator *sep); void command_flagedit(Client *c, const Seperator *sep); @@ -141,7 +127,6 @@ void command_invsnapshot(Client *c, const Seperator *sep); void command_invul(Client *c, const Seperator *sep); void command_ipban(Client *c, const Seperator *sep); void command_iplookup(Client *c, const Seperator *sep); -void command_itemsearch(Client *c, const Seperator *sep); void command_kick(Client *c, const Seperator *sep); void command_killallnpcs(Client *c, const Seperator *sep); void command_kill(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/find.cpp b/zone/gm_commands/find.cpp new file mode 100644 index 000000000..9d7642e86 --- /dev/null +++ b/zone/gm_commands/find.cpp @@ -0,0 +1,97 @@ +#include "../client.h" +#include "find/aa.cpp" +#include "find/character.cpp" +#include "find/class.cpp" +#include "find/currency.cpp" +#include "find/deity.cpp" +#include "find/faction.cpp" +#include "find/item.cpp" +#include "find/language.cpp" +#include "find/npctype.cpp" +#include "find/race.cpp" +#include "find/recipe.cpp" +#include "find/skill.cpp" +#include "find/spell.cpp" +#include "find/task.cpp" +#include "find/zone.cpp" + +void command_find(Client *c, const Seperator *sep) +{ + // Cmd represents a command + // variables are short to save space horizontally + // when adding a new sub-command, add it to the vector below + struct Cmd { + std::string cmd{}; // command + std::string u{}; // usage + void (*fn)(Client *c, const Seperator *sep) = nullptr; // function + std::vector a{}; // aliases + }; + + std::vector commands = { + Cmd{.cmd = "aa", .u = "aa [Search Criteria]", .fn = FindAA, .a = {"#findaa"}}, + Cmd{.cmd = "character", .u = "character [Search Criteria]", .fn = FindCharacter, .a = {"#findcharacter"}}, + Cmd{.cmd = "class", .u = "class [Search Criteria]", .fn = FindClass, .a = {"#findclass"}}, + Cmd{.cmd = "currency", .u = "currency [Search Criteria]", .fn = FindCurrency, .a = {"#findcurrency"}}, + Cmd{.cmd = "deity", .u = "deity [Search Criteria]", .fn = FindDeity, .a = {"#finddeity"}}, + Cmd{.cmd = "faction", .u = "faction [Search Criteria]", .fn = FindFaction, .a = {"#findfaction"}}, + Cmd{.cmd = "item", .u = "item [Search Criteria]", .fn = FindItem, .a = {"#fi", "#finditem"}}, + Cmd{.cmd = "language", .u = "language [Search Criteria]", .fn = FindLanguage, .a = {"#findlanguage"}}, + Cmd{ + .cmd = "npctype", .u = "npctype [Search Criteria]", .fn = FindNPCType, .a = { + "#fn", + "#findnpc", + "#findnpctype" + } + }, + Cmd{.cmd = "race", .u = "race [Search Criteria]", .fn = FindRace, .a = {"#findrace"}}, + Cmd{.cmd = "recipe", .u = "recipe [Search Criteria]", .fn = FindRecipe, .a = {"#findrecipe"}}, + Cmd{.cmd = "skill", .u = "skill [Search Criteria]", .fn = FindSkill, .a = {"#findskill"}}, + Cmd{.cmd = "spell", .u = "spell [Search Criteria]", .fn = FindSpell, .a = {"#fs", "#findspell"}}, + Cmd{.cmd = "task", .u = "task [Search Criteria]", .fn = FindTask, .a = {"#findtask"}}, + Cmd{.cmd = "zone", .u = "zone [Search Criteria]", .fn = FindZone, .a = {"#fz", "#findzone"}}, + }; + + // Check for arguments + const auto arguments = sep->argnum; + if (!arguments) { + for (const auto &cmd: commands) { + c->Message(Chat::White, fmt::format("Usage: #find {}", cmd.u).c_str()); + } + return; + } + + // look for alias or command + for (const auto &cmd: commands) { + // Check for alias first + for (const auto &alias: cmd.a) { + if (!alias.empty() && alias == Strings::ToLower(sep->arg[0])) { + // build string from sep args + std::vector args = {}; + + // skip the first arg + for (auto i = 1; i <= arguments; i++) { + args.emplace_back(sep->arg[i]); + } + + // build the rewrite string + std::string rewrite = fmt::format("#find {} {}", cmd.cmd, Strings::Join(args, " ")); + + // rewrite to #find + c->SendGMCommand(rewrite); + return; + } + } + + // Check for command + if (cmd.cmd == Strings::ToLower(sep->arg[1])) { + cmd.fn(c, sep); + return; + } + } + + // Command not found + c->Message(Chat::White, "Command not found. Usage: #find [command]"); + for (const auto &cmd: commands) { + c->Message(Chat::White, fmt::format("Usage: #find {}", cmd.u).c_str()); + } +} diff --git a/zone/gm_commands/find/aa.cpp b/zone/gm_commands/find/aa.cpp new file mode 100644 index 000000000..fd1ce0bd4 --- /dev/null +++ b/zone/gm_commands/find/aa.cpp @@ -0,0 +1,88 @@ +#include "../../client.h" + +void FindAA(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto aa_id = Strings::ToInt(sep->arg[2]); + const auto& aa_name = zone->GetAAName(aa_id); + if (!aa_name.empty()) { + c->Message( + Chat::White, + fmt::format( + "AA {} | {}", + Strings::Commify(aa_id), + aa_name + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "AA ID {} was not found.", + Strings::Commify(aa_id) + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + std::map ordered_aas; + + for (const auto &a: zone->aa_abilities) { + ordered_aas[a.second.get()->first->id] = a.second.get()->name; + } + + for (const auto &a: ordered_aas) { + const auto& aa_name = zone->GetAAName(a.first); + if (!aa_name.empty()) { + const auto& aa_name_lower = Strings::ToLower(aa_name); + if (!Strings::Contains(aa_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "AA {} | {}", + Strings::Commify(a.first), + aa_name + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 AAs were found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} AA{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/character.cpp b/zone/gm_commands/find/character.cpp new file mode 100644 index 000000000..9aeab28f1 --- /dev/null +++ b/zone/gm_commands/find/character.cpp @@ -0,0 +1,95 @@ +#include "../../client.h" +#include "../../common/repositories/character_data_repository.h" + +void FindCharacter(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto character_id = Strings::ToUnsignedInt(sep->arg[2]); + + 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.", + Strings::Commify(character_id) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Character ID {} | {}", + Strings::Commify(character_id), + e.name + ).c_str() + ); + + return; + } + + const auto search_criteria = Strings::ToLower(sep->argplus[2]); + + const auto& l = CharacterDataRepository::GetWhere( + content_db, + fmt::format( + "LOWER(`name`) LIKE '%%{}%%' ORDER BY `id` ASC LIMIT 50", + search_criteria + ) + ); + + if (l.empty()) { + c->Message( + Chat::White, + fmt::format( + "No characters found matching '{}'.", + sep->argplus[2] + ).c_str() + ); + } + + auto found_count = 0; + + for (const auto& e : l) { + c->Message( + Chat::White, + fmt::format( + "Character ID {} | {}", + Strings::Commify(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[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Character{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} + diff --git a/zone/gm_commands/find/class.cpp b/zone/gm_commands/find/class.cpp new file mode 100644 index 000000000..9c6a6eec0 --- /dev/null +++ b/zone/gm_commands/find/class.cpp @@ -0,0 +1,80 @@ +#include "../../client.h" + +void FindClass(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto class_id = Strings::ToInt(sep->arg[2]); + if (EQ::ValueWithin(class_id, WARRIOR, BERSERKER)) { + const std::string& class_name = GetClassIDName(class_id); + c->Message( + Chat::White, + fmt::format( + "Class {} | {}{}", + class_id, + class_name, + ( + c->IsPlayerClass(class_id) ? + fmt::format( + " ({})", + Strings::Commify(GetPlayerClassBit(class_id)) + ) : + "" + ) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Class ID {} was not found.", + class_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (uint16 class_id = WARRIOR; class_id <= MERCENARY_MASTER; class_id++) { + const std::string& class_name = GetClassIDName(class_id); + const auto& class_name_lower = Strings::ToLower(class_name); + if (!Strings::Contains(class_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Class {} | {}{}", + class_id, + class_name, + ( + c->IsPlayerClass(class_id) ? + fmt::format( + " | ({})", + Strings::Commify(GetPlayerClassBit(class_id)) + ) : + "" + ) + ).c_str() + ); + + found_count++; + } + + c->Message( + Chat::White, + fmt::format( + "{} Class{} found matching '{}'.", + found_count, + found_count != 1 ? "es" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/currency.cpp b/zone/gm_commands/find/currency.cpp new file mode 100644 index 000000000..dde937824 --- /dev/null +++ b/zone/gm_commands/find/currency.cpp @@ -0,0 +1,131 @@ +#include "../../client.h" + +void FindCurrency(Client *c, const Seperator *sep) +{ + const auto can_summon_items = c->Admin() >= GetCommandStatus(c, "summonitem"); + + if (sep->IsNumber(2)) { + const auto item_id = Strings::ToUnsignedInt(sep->arg[2]); + const auto currency_id = zone->GetCurrencyID(item_id); + + if (!currency_id) { + c->Message( + Chat::White, + fmt::format( + "There is no currency with an item ID of {}.", + Strings::Commify(item_id) + ).c_str() + ); + + return; + } + + const auto item_data = database.GetItem(item_id); + if (!item_data) { + c->Message( + Chat::White, + fmt::format( + "Item ID {} does not exist.", + Strings::Commify(item_id) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Currency {} | {}{}", + currency_id, + database.CreateItemLink(item_id), + ( + can_summon_items ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#summonitem {} {}", + item_id, + item_data->StackSize + ), + "Summon" + ) + ) : + "" + ) + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (const auto& e : zone->AlternateCurrencies) { + const auto item_data = database.GetItem(e.item_id); + if (!item_data) { + continue; + } + + const auto& item_name = Strings::ToLower(item_data->Name); + + if (!Strings::Contains(item_name, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Currency {} | {}{}", + e.id, + database.CreateItemLink(e.item_id), + ( + can_summon_items ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#summonitem {} {}", + e.item_id, + item_data->StackSize + ), + "Summon" + ) + ) : + "" + ) + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Currencies found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Currenc{} found matching '{}'.", + found_count, + found_count != 1 ? "ies" : "y", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/deity.cpp b/zone/gm_commands/find/deity.cpp new file mode 100644 index 000000000..25d9365d7 --- /dev/null +++ b/zone/gm_commands/find/deity.cpp @@ -0,0 +1,69 @@ +#include "../../client.h" + +void FindDeity(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto deity_id = static_cast(Strings::ToInt(sep->arg[2])); + const auto& deity_name = EQ::deity::GetDeityName(deity_id); + if (!deity_name.empty()) { + const auto deity_bit = EQ::deity::GetDeityBitmask(deity_id); + + c->Message( + Chat::White, + fmt::format( + "Deity {} | {} ({})", + deity_id, + deity_name, + Strings::Commify(deity_bit) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Deity ID {} was not found.", + deity_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (const auto& d : EQ::deity::GetDeityMap()) { + const auto& deity_name_lower = Strings::ToLower(d.second); + if (!Strings::Contains(deity_name_lower, search_criteria)) { + continue; + } + + const auto deity_bit = EQ::deity::GetDeityBitmask(d.first); + + c->Message( + Chat::White, + fmt::format( + "Deity {} | {} ({})", + d.first, + d.second, + Strings::Commify(deity_bit) + ).c_str() + ); + + found_count++; + } + + c->Message( + Chat::White, + fmt::format( + "{} Deit{} found matching '{}'.", + found_count, + found_count != 1 ? "ies" : "y", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/faction.cpp b/zone/gm_commands/find/faction.cpp new file mode 100644 index 000000000..f8412d013 --- /dev/null +++ b/zone/gm_commands/find/faction.cpp @@ -0,0 +1,84 @@ +#include "../../client.h" + +void FindFaction(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto faction_id = Strings::ToInt(sep->arg[2]); + const auto& faction_name = content_db.GetFactionName(faction_id); + if (!faction_name.empty()) { + c->Message( + Chat::White, + fmt::format( + "Faction {} | {}", + Strings::Commify(faction_id), + faction_name + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Faction ID {} was not found.", + Strings::Commify(faction_id) + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + auto found_count = 0; + const auto max_faction_id = content_db.GetMaxFaction(); + + for (uint32 faction_id = 0; faction_id < max_faction_id; faction_id++) { + const auto& faction_name = content_db.GetFactionName(faction_id); + const auto& faction_name_lower = Strings::ToLower(faction_name); + if (faction_name.empty()) { + continue; + } + + if (!Strings::Contains(faction_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Faction {} | {}", + Strings::Commify(faction_id), + faction_name + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Factions found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Faction{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/item.cpp b/zone/gm_commands/find/item.cpp new file mode 100644 index 000000000..24a3ef46b --- /dev/null +++ b/zone/gm_commands/find/item.cpp @@ -0,0 +1,135 @@ +#include "../../client.h" +#include "../../common/repositories/items_repository.h" + +void FindItem(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto item_id = Strings::ToUnsignedInt(sep->arg[2]); + const auto* item = database.GetItem(item_id); + if (item) { + auto summon_links = Saylink::Silent( + fmt::format( + "#si {}", + item_id + ), + "X" + ); + + if (item->Stackable && item->StackSize > 1) { + summon_links += fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#si {} {}", + item_id, + item->StackSize + ), + std::to_string(item->StackSize) + ) + ); + } + + c->Message( + Chat::White, + fmt::format( + "{} | {}", + database.CreateItemLink(item_id), + summon_links + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Item ID {} not found", + item_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + const auto& l = ItemsRepository::GetItemIDsBySearchCriteria(content_db, search_criteria, 50); + + if (l.empty()) { + c->Message( + Chat::White, + fmt::format( + "No items were found matching '{}'.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + auto found_count = 0; + + for (const auto& e : l) { + const auto *item = database.GetItem(e); + auto summon_links = Saylink::Silent( + fmt::format( + "#si {}", + e + ), + "X" + ); + + if (item->Stackable && item->StackSize > 1) { + summon_links += fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#si {} {}", + e, + item->StackSize + ), + std::to_string(item->StackSize) + ) + ); + } + + c->Message( + Chat::White, + fmt::format( + "{} | {}", + database.CreateItemLink(e), + summon_links + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Items found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Item{} found matching '{}'.", + found_count, + found_count != 1 ? "s" :"", + sep->argplus[2] + ).c_str() + ); +} + diff --git a/zone/gm_commands/find/language.cpp b/zone/gm_commands/find/language.cpp new file mode 100644 index 000000000..217e54bfe --- /dev/null +++ b/zone/gm_commands/find/language.cpp @@ -0,0 +1,64 @@ +#include "../../client.h" +#include "../../common/languages.h" + +void FindLanguage(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto language_id = Strings::ToInt(sep->arg[2]); + if (EQ::ValueWithin(language_id, LANG_COMMON_TONGUE, LANG_UNKNOWN)) { + c->Message( + Chat::White, + fmt::format( + "Language {} | {}", + language_id, + EQ::constants::GetLanguageName(language_id) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Language ID {} was not found.", + language_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (const auto& l : EQ::constants::GetLanguageMap()) { + const auto& language_name_lower = Strings::ToLower(l.second); + if (!Strings::Contains(language_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Language {} | {}", + l.first, + l.second + ).c_str() + ); + + found_count++; + } + + c->Message( + Chat::White, + fmt::format( + "{} Language{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} + diff --git a/zone/gm_commands/find/npctype.cpp b/zone/gm_commands/find/npctype.cpp new file mode 100644 index 000000000..bf8fc95d6 --- /dev/null +++ b/zone/gm_commands/find/npctype.cpp @@ -0,0 +1,94 @@ +#include "../../client.h" + +void FindNPCType(Client *c, const Seperator *sep) +{ + std::string query = "SELECT `id`, `name` FROM npc_types WHERE "; + const std::string& search_criteria = sep->argplus[2]; + if (sep->IsNumber(2)) { + const auto npc_id = Strings::ToUnsignedInt(sep->arg[2]); + + query += fmt::format( + "id = {}", + npc_id + ); + } else { + query += fmt::format( + "`name` LIKE '%%{}%%'", + Strings::Escape(search_criteria) + ); + } + + query += " ORDER BY `id` ASC LIMIT 50"; + + auto results = content_db.QueryDatabase(query); + if (!results.Success() || !results.RowCount()) { + c->Message( + Chat::White, + fmt::format( + "No NPCs matching '{}' were found.", + search_criteria + ).c_str() + ); + + return; + } + + const auto can_spawn_npcs = c->Admin() >= GetCommandStatus(c, "#npctypespawn"); + + auto found_count = 0; + + for (auto row : results) { + auto found_number = (found_count + 1); + if (found_count == 50) { + break; + } + + c->Message( + Chat::White, + fmt::format( + "NPC {} | {}{}", + Strings::Commify(row[0]), + row[1], + ( + can_spawn_npcs ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#npctypespawn {}", + row[0] + ), + "Spawn" + ) + ) : + "" + ) + ).c_str() + ); + + found_count++; + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 NPCs found matching '{}', max reached.", + search_criteria + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} NPC{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + search_criteria + ).c_str() + ); +} + diff --git a/zone/gm_commands/find/race.cpp b/zone/gm_commands/find/race.cpp new file mode 100644 index 000000000..c2f2db0d6 --- /dev/null +++ b/zone/gm_commands/find/race.cpp @@ -0,0 +1,96 @@ +#include "../../client.h" + +void FindRace(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto race_id = static_cast(Strings::ToUnsignedInt(sep->arg[2])); + const std::string& race_name = GetRaceIDName(race_id); + if (EQ::ValueWithin(race_id, RACE_HUMAN_1, RACE_PEGASUS_732)) { + c->Message( + Chat::White, + fmt::format( + "Race {} | {}{}", + race_id, + race_name, + ( + c->IsPlayerRace(race_id) ? + fmt::format( + " ({})", + Strings::Commify(GetPlayerRaceBit(race_id)) + ) : + "" + ) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Race ID {} was not found.", + race_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (uint16 race_id = RACE_HUMAN_1; race_id <= RACE_PEGASUS_732; race_id++) { + std::string race_name = GetRaceIDName(race_id); + auto race_name_lower = Strings::ToLower(race_name); + if (!Strings::Contains(race_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Race {} | {}{}", + race_id, + race_name, + ( + c->IsPlayerRace(race_id) ? + fmt::format( + " ({})", + Strings::Commify(GetPlayerRaceBit(race_id)) + ) : + "" + ) + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Races found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Race{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/recipe.cpp b/zone/gm_commands/find/recipe.cpp new file mode 100644 index 000000000..2a675dc26 --- /dev/null +++ b/zone/gm_commands/find/recipe.cpp @@ -0,0 +1,130 @@ +#include "../../client.h" +#include "../../command.h" +#include "../../common/repositories/tradeskill_recipe_repository.h" + +void FindRecipe(Client *c, const Seperator *sep) +{ + const auto can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe"); + + if (sep->IsNumber(2)) { + const auto recipe_id = static_cast(Strings::ToUnsignedInt(sep->arg[2])); + + const auto& l = TradeskillRecipeRepository::GetWhere( + database, + fmt::format("id = {}", recipe_id) + ); + + if (l.empty() || !l[0].id) { + c->Message( + Chat::White, + fmt::format( + "Recipe ID {} could not be found.", + Strings::Commify(recipe_id) + ).c_str() + ); + return; + } + + c->Message( + Chat::White, + fmt::format( + "Recipe {} | {}{}", + Strings::Commify(recipe_id), + l[0].name, + ( + can_view_recipes ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#viewrecipe {}", + l[0].id + ), + "View" + ) + ) : + "" + ) + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + const auto& l = TradeskillRecipeRepository::GetWhere( + database, + fmt::format( + "LOWER(`name`) LIKE '%%{}%%' ORDER BY `id` ASC", + search_criteria + ) + ); + + if (l.empty() || !l[0].id) { + c->Message( + Chat::White, + fmt::format( + "No recipes were found matching '{}'.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + for (const auto& e : l) { + c->Message( + Chat::White, + fmt::format( + "Recipe {} | {}{}", + Strings::Commify(e.id), + e.name, + ( + can_view_recipes ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#viewrecipe {}", + e.id + ), + "View" + ) + ) : + "" + ) + ).c_str() + ); + + if (found_count == 50) { + break; + } + + found_count++; + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Recipes found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Recipe{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/skill.cpp b/zone/gm_commands/find/skill.cpp new file mode 100644 index 000000000..7c92f4359 --- /dev/null +++ b/zone/gm_commands/find/skill.cpp @@ -0,0 +1,83 @@ +#include "../../client.h" + +void FindSkill(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const auto skill_id = Strings::ToInt(sep->arg[2]); + if (EQ::ValueWithin(skill_id, EQ::skills::Skill1HBlunt, EQ::skills::SkillCount)) { + for (const auto& s : EQ::skills::GetSkillTypeMap()) { + if (skill_id == s.first) { + c->Message( + Chat::White, + fmt::format( + "Skill {} | {}", + s.first, + s.second + ).c_str() + ); + break; + } + } + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Skill ID {} was not found.", + skill_id + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (const auto& s : EQ::skills::GetSkillTypeMap()) { + const auto& skill_name_lower = Strings::ToLower(s.second); + if (!Strings::Contains(skill_name_lower, sep->argplus[2])) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Skill {} | {}", + s.first, + s.second + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Skills were found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Skill{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/spell.cpp b/zone/gm_commands/find/spell.cpp new file mode 100644 index 000000000..5aa157cbc --- /dev/null +++ b/zone/gm_commands/find/spell.cpp @@ -0,0 +1,104 @@ +#include "../../client.h" + +void FindSpell(Client *c, const Seperator *sep) +{ + if (SPDAT_RECORDS <= 0) { + c->Message(Chat::White, "Spells not loaded."); + return; + } + + const auto can_cast_spells = c->Admin() >= GetCommandStatus(c, "castspell"); + + if (sep->IsNumber(2)) { + const auto spell_id = Strings::ToUnsignedInt(sep->arg[2]); + if (!IsValidSpell(spell_id)) { + c->Message( + Chat::White, + fmt::format( + "Spell ID {} was not found.", + Strings::Commify(spell_id) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Spell {} | {}", + Strings::Commify(spell_id), + spells[spell_id].name + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (uint32 spell_id = 0; spell_id < SPDAT_RECORDS; spell_id++) { + if (IsValidSpell(spell_id)) { + const auto& current_spell = spells[spell_id]; + + const std::string& spell_name = current_spell.name; + const auto& spell_name_lower = Strings::ToLower(spell_name); + if (!Strings::Contains(spell_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Spell {} | {}{}", + Strings::Commify(spell_id), + spell_name, + ( + can_cast_spells ? + fmt::format( + " | {}", + Saylink::Silent( + fmt::format( + "#castspell {}", + spell_id + ), + "Cast" + ) + ) : + "" + ) + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Spells found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Spell{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/task.cpp b/zone/gm_commands/find/task.cpp new file mode 100644 index 000000000..dd38433ca --- /dev/null +++ b/zone/gm_commands/find/task.cpp @@ -0,0 +1,109 @@ +#include "../../client.h" + +void FindTask(Client *c, const Seperator *sep) +{ + if (!RuleB(TaskSystem, EnableTaskSystem)) { + c->Message(Chat::White, "This command cannot be used while the Task system is disabled."); + return; + } + + const auto can_assign_tasks = c->Admin() >= GetCommandStatus(c, "task"); + + if (sep->IsNumber(2)) { + const auto task_id = Strings::ToUnsignedInt(sep->arg[2]); + const auto& task_name = task_manager->GetTaskName(task_id); + + if (task_name.empty()) { + c->Message( + Chat::White, + fmt::format( + "Task ID {} was not found.", + Strings::Commify(task_id) + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Task {} | {}", + Strings::Commify(task_id), + task_name + ).c_str() + ); + + return; + } + + const auto& search_criteria = Strings::ToLower(sep->argplus[2]); + + auto found_count = 0; + + for (const auto& t : task_manager->GetTaskData()) { + const auto& task_name = t.second.title; + const auto& task_name_lower = Strings::ToLower(task_name); + if (!Strings::Contains(task_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Task {} | {}{}", + Strings::Commify(t.first), + task_name, + ( + can_assign_tasks ? + fmt::format( + " | {}{}", + Saylink::Silent( + fmt::format( + "#task assign {}", + t.first + ), + "Assign" + ), + Saylink::Silent( + fmt::format( + "#task uncomplete {}", + t.first + ), + "Uncomplete" + ) + ) : + "" + ) + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Tasks were found matching '{}', max reached.", + sep->argplus[2] + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Task{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} diff --git a/zone/gm_commands/find/zone.cpp b/zone/gm_commands/find/zone.cpp new file mode 100644 index 000000000..92cb55968 --- /dev/null +++ b/zone/gm_commands/find/zone.cpp @@ -0,0 +1,132 @@ +#include "../../client.h" +#include "../../common/content/world_content_service.h" + +void FindZone(Client *c, const Seperator *sep) +{ + std::string query = "SELECT zoneidnumber, short_name, long_name, version FROM zone WHERE "; + + 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; + + std::string search_string; + std::string search_type; + + if (is_expansion_search) { + query += fmt::format( + "expansion = {}", + Strings::ToInt(sep->arg[3]) + ); + + search_string = Expansion::ExpansionName[Strings::ToInt(sep->arg[3])]; + search_type = "Expansion"; + } else if (is_id_search) { + query += fmt::format( + "zoneidnumber = {}", + Strings::ToUnsignedInt(sep->arg[2]) + ); + + search_string = sep->arg[2]; + search_type = "Expansion"; + } else if (is_short_name_search) { + query += 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])) + ); + + search_string = sep->argplus[2]; + search_type = "Expansion"; + } + + query += " ORDER BY `zoneidnumber` ASC LIMIT 50"; + + auto results = content_db.QueryDatabase(query); + if (!results.Success() || !results.RowCount()) { + 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]); + + c->Message( + Chat::White, + fmt::format( + "{}{} {} ({}) (ID {}){}", + ( + version == 0 ? + fmt::format( + "{} | ", + Saylink::Silent( + fmt::format( + "#zone {}", + short_name + ), + "Zone" + ) + ) : + "" + ), + fmt::format( + "{} |", + Saylink::Silent( + fmt::format( + "#gmzone {} {}", + short_name, + version + ), + "GM Zone" + ) + ), + long_name, + short_name, + zone_id, + ( + version != 0 ? + fmt::format( + " (Version {})", + version + ) : + "" + ) + ).c_str() + ); + + found_count++; + + if (found_count == 50) { + break; + } + } + + if (found_count == 50) { + c->Message( + Chat::White, + fmt::format( + "50 Zones found matching '{}' of '{}'.", + search_type, + search_string + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "{} Zone{} found matching '{}' of '{}'.", + found_count, + found_count != 1 ? "s" : "", + search_type, + search_string + ).c_str() + ); +} diff --git a/zone/gm_commands/findaa.cpp b/zone/gm_commands/findaa.cpp deleted file mode 100755 index 3a0640153..000000000 --- a/zone/gm_commands/findaa.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "../client.h" - -void command_findaa(Client *c, const Seperator *sep) -{ - auto arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Command Syntax: #findaa [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - int aa_id = Strings::ToInt(sep->arg[1]); - auto aa_name = zone->GetAAName(aa_id); - if (!aa_name.empty()) { - c->Message( - Chat::White, - fmt::format( - "AA {}: {}", - aa_id, - aa_name - ).c_str() - ); - } else { - c->Message( - Chat::White, - fmt::format( - "AA ID {} was not found.", - aa_id - ).c_str() - ); - } - } else { - const auto search_criteria = Strings::ToLower(sep->argplus[1]); - if (!search_criteria.empty()) { - std::map ordered_aas; - - for (const auto& a : zone->aa_abilities) { - ordered_aas[a.second.get()->first->id] = a.second.get()->name; - } - - int found_count = 0; - for (const auto& a : ordered_aas) { - auto aa_name = zone->GetAAName(a.first); - if (!aa_name.empty()) { - auto aa_name_lower = Strings::ToLower(aa_name); - if (aa_name_lower.find(search_criteria) == std::string::npos) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "AA {}: {}", - a.first, - aa_name - ).c_str() - ); - found_count++; - - if (found_count == 50) { - break; - } - } - } - - if (!found_count) { - c->Message( - Chat::White, - fmt::format( - "No AAs were found matching '{}'.", - search_criteria - ).c_str() - ); - return; - } - - if (found_count == 50) { - c->Message( - Chat::White, - fmt::format( - "50 AAs were found matching '{}', max reached.", - search_criteria - ).c_str() - ); - } else { - auto skill_message = found_count == 1 ? "An AA was" : fmt::format("{} AAs were", found_count); - - c->Message( - Chat::White, - fmt::format( - "{} found matching '{}'.", - skill_message, - search_criteria - ).c_str() - ); - } - } - } -} - diff --git a/zone/gm_commands/findcharacter.cpp b/zone/gm_commands/findcharacter.cpp deleted file mode 100755 index fccd7bf20..000000000 --- a/zone/gm_commands/findcharacter.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#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 = Strings::ToUnsignedInt(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() - ); - } - } -} - diff --git a/zone/gm_commands/findclass.cpp b/zone/gm_commands/findclass.cpp deleted file mode 100755 index a1ddaa18f..000000000 --- a/zone/gm_commands/findclass.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "../client.h" - -void command_findclass(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Command Syntax: #findclass [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - int class_id = Strings::ToInt(sep->arg[1]); - if (class_id >= WARRIOR && class_id <= MERCENARY_MASTER) { - std::string class_name = GetClassIDName(class_id); - c->Message( - Chat::White, - fmt::format( - "Class {} | {}{}", - class_id, - class_name, - ( - c->IsPlayerClass(class_id) ? - fmt::format( - " ({})", - GetPlayerClassBit(class_id) - ) : - "" - ) - ).c_str() - ); - } - else { - c->Message( - Chat::White, - fmt::format( - "Class ID {} was not found.", - class_id - ).c_str() - ); - } - } else { - auto search_criteria = Strings::ToLower(sep->argplus[1]); - int found_count = 0; - for (uint16 class_id = WARRIOR; class_id <= MERCENARY_MASTER; class_id++) { - std::string class_name = GetClassIDName(class_id); - auto class_name_lower = Strings::ToLower(class_name); - if ( - search_criteria.length() && - class_name_lower.find(search_criteria) == std::string::npos - ) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Class {} | {}{}", - class_id, - class_name, - ( - c->IsPlayerClass(class_id) ? - fmt::format( - " ({})", - GetPlayerClassBit(class_id) - ) : - "" - ) - ).c_str() - ); - - found_count++; - - if (found_count == 50) { - break; - } - } - - if (found_count == 50) { - c->Message(Chat::White, "50 Classes found, max reached."); - } else { - c->Message( - Chat::White, - fmt::format( - "{} Class{} found.", - found_count, - found_count != 1 ? "es" : "" - ).c_str() - ); - } - } -} - diff --git a/zone/gm_commands/findcurrency.cpp b/zone/gm_commands/findcurrency.cpp deleted file mode 100755 index b5ad64c5a..000000000 --- a/zone/gm_commands/findcurrency.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "../client.h" - -void command_findcurrency(Client *c, const Seperator *sep) -{ - const auto arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Usage: #findcurrency [Search Criteria]"); - return; - } - - const auto can_summon_items = c->Admin() >= GetCommandStatus(c, "summonitem"); - - if (sep->IsNumber(1)) { - const auto item_id = Strings::ToUnsignedInt(sep->arg[1]); - const auto currency_id = zone->GetCurrencyID(item_id); - - if (!currency_id) { - c->Message( - Chat::White, - fmt::format( - "There is no currency with an item ID of {}.", - item_id - ).c_str() - ); - - return; - } - - const auto item_data = database.GetItem(item_id); - if (!item_data) { - c->Message( - Chat::White, - fmt::format( - "Item ID {} does not exist.", - item_id - ).c_str() - ); - - return; - } - - c->Message( - Chat::White, - fmt::format( - "Currency {} | {} ({}){}", - currency_id, - database.CreateItemLink(item_id), - item_id, - ( - can_summon_items ? - fmt::format( - " | {}", - Saylink::Silent( - fmt::format( - "#summonitem {} {}", - item_id, - item_data->StackSize - ), - "Summon" - ) - ) : - "" - ) - ).c_str() - ); - - return; - } - - const std::string search_criteria = sep->argplus[1]; - - uint32 found_count = 0; - - for (const auto& e : zone->AlternateCurrencies) { - const auto item_data = database.GetItem(e.item_id); - if (!item_data) { - continue; - } - - const std::string item_name = Strings::ToLower(item_data->Name); - - if (Strings::Contains(item_name, Strings::ToLower(search_criteria))) { - c->Message( - Chat::White, - fmt::format( - "Currency {} | {} ({}){}", - e.id, - database.CreateItemLink(e.item_id), - e.item_id, - ( - can_summon_items ? - fmt::format( - " | {}", - Saylink::Silent( - fmt::format( - "#summonitem {} {}", - e.item_id, - item_data->StackSize - ), - "Summon" - ) - ) : - "" - ) - ).c_str() - ); - - found_count++; - } - } - - if (!found_count) { - c->Message( - Chat::White, - fmt::format( - "No currencies were found matching '{}'.", - search_criteria - ).c_str() - ); - - return; - } - - c->Message( - Chat::White, - fmt::format( - "{} currenc{} found matching '{}'.", - found_count, - found_count != 1 ? "ies were" : "y was", - search_criteria - ).c_str() - ); -} - diff --git a/zone/gm_commands/finddeity.cpp b/zone/gm_commands/finddeity.cpp deleted file mode 100755 index 560952cc7..000000000 --- a/zone/gm_commands/finddeity.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "../client.h" - -void command_finddeity(Client *c, const Seperator *sep) -{ - const auto arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Usage: #finddeity [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - const auto deity_id = static_cast(Strings::ToInt(sep->arg[1])); - const auto& deity_name = EQ::deity::GetDeityName(deity_id); - if (!deity_name.empty()) { - const auto deity_bit = EQ::deity::GetDeityBitmask(deity_id); - - c->Message( - Chat::White, - fmt::format( - "Deity {} | {} ({})", - deity_id, - deity_name, - deity_bit - ).c_str() - ); - return; - } - - c->Message( - Chat::White, - fmt::format( - "Deity ID {} was not found.", - deity_id - ).c_str() - ); - return; - } - - const auto& search_criteria = Strings::ToLower(sep->argplus[1]); - if (!search_criteria.empty()) { - auto found_count = 0; - for (const auto& d : EQ::deity::GetDeityMap()) { - const auto& deity_name_lower = Strings::ToLower(d.second); - if (!Strings::Contains(deity_name_lower, search_criteria)) { - continue; - } - - const auto deity_bit = EQ::deity::GetDeityBitmask(d.first); - - c->Message( - Chat::White, - fmt::format( - "Deity {} | {} ({})", - d.first, - d.second, - deity_bit - ).c_str() - ); - - found_count++; - } - - c->Message( - Chat::White, - fmt::format( - "{} Deit{} found.", - found_count, - found_count != 1 ? "ies" : "y" - ).c_str() - ); - } -} - diff --git a/zone/gm_commands/findfaction.cpp b/zone/gm_commands/findfaction.cpp deleted file mode 100755 index a6d75874d..000000000 --- a/zone/gm_commands/findfaction.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "../client.h" - -void command_findfaction(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findfaction [search criteria]"); - return; - } - - if (sep->IsNumber(1)) { - int faction_id = Strings::ToInt(sep->arg[1]); - auto faction_name = content_db.GetFactionName(faction_id); - if (!faction_name.empty()) { - c->Message( - Chat::White, - fmt::format( - "Faction {}: {}", - faction_id, - faction_name - ).c_str() - ); - } - else { - c->Message( - Chat::White, - fmt::format( - "Faction ID {} was not found.", - faction_id - ).c_str() - ); - } - } - else { - std::string search_criteria = Strings::ToLower(sep->argplus[1]); - int found_count = 0; - int max_faction_id = content_db.GetMaxFaction(); - for (int faction_id = 0; faction_id < max_faction_id; faction_id++) { - std::string faction_name = content_db.GetFactionName(faction_id); - std::string faction_name_lower = Strings::ToLower(faction_name); - if (faction_name.empty()) { - continue; - } - - if (faction_name.find(search_criteria) == std::string::npos) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Faction {}: {}", - faction_id, - faction_name - ).c_str() - ); - found_count++; - - if (found_count == 20) { - break; - } - } - - if (found_count == 20) { - c->Message(Chat::White, "20 Factions found... max reached."); - } - else { - auto faction_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Faction was" : - fmt::format("{} Factions were", found_count) - ) : - "No Factions were" - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - faction_message - ).c_str() - ); - } - } -} - diff --git a/zone/gm_commands/findlanguage.cpp b/zone/gm_commands/findlanguage.cpp deleted file mode 100755 index 9eaed06e7..000000000 --- a/zone/gm_commands/findlanguage.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "../client.h" -#include "../../common/languages.h" - -void command_findlanguage(Client *c, const Seperator *sep) -{ - const auto arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Command Syntax: #findlanguage [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - const auto language_id = Strings::ToInt(sep->arg[1]); - if (EQ::ValueWithin(language_id, LANG_COMMON_TONGUE, LANG_UNKNOWN)) { - c->Message( - Chat::White, - fmt::format( - "Language {} | {}", - language_id, - EQ::constants::GetLanguageName(language_id) - ).c_str() - ); - return; - } - - c->Message( - Chat::White, - fmt::format( - "Language ID {} was not found.", - language_id - ).c_str() - ); - return; - } - - const auto& search_criteria = Strings::ToLower(sep->argplus[1]); - if (!search_criteria.empty()) { - const auto& m = EQ::constants::GetLanguageMap(); - auto found_count = 0; - for (const auto& l : m) { - const auto& language_name_lower = Strings::ToLower(l.second); - if (Strings::Contains(language_name_lower, search_criteria)) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Language {} | {}", - l.first, - l.second - ).c_str() - ); - - found_count++; - } - - auto language_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Language was" : - fmt::format("{} Languages were", found_count) - ) : - "No Languages were" - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - language_message - ).c_str() - ); - } -} - diff --git a/zone/gm_commands/findnpctype.cpp b/zone/gm_commands/findnpctype.cpp deleted file mode 100755 index 991bd8f18..000000000 --- a/zone/gm_commands/findnpctype.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "../client.h" - -void command_findnpctype(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Usage: #findnpctype [Search Criteria]"); - return; - } - - std::string query; - std::string search_criteria = sep->arg[1]; - if (sep->IsNumber(1)) { - query = fmt::format( - "SELECT id, name FROM npc_types WHERE id = {}", - search_criteria - ); - } - else { - query = fmt::format( - "SELECT id, name FROM npc_types WHERE name LIKE '%%{}%%'", - search_criteria - ); - } - - auto results = content_db.QueryDatabase(query); - if (!results.Success() || !results.RowCount()) { - c->Message( - Chat::White, - fmt::format( - "No matches found for '{}'.", - search_criteria - ).c_str() - ); - return; - } - - int found_count = 0; - - for (auto row : results) { - int found_number = (found_count + 1); - if (found_count == 20) { - break; - } - - c->Message( - Chat::White, - fmt::format( - "NPC {} | {} ({})", - found_number, - row[1], - row[0] - ).c_str() - ); - found_count++; - } - - if (found_count == 20) { - c->Message(Chat::White, "20 NPCs were found, max reached."); - } - else { - auto npc_message = ( - found_count == 1 ? - "An NPC was" : - fmt::format("{} NPCs were", found_count) - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - npc_message - ).c_str() - ); - } -} - diff --git a/zone/gm_commands/findrace.cpp b/zone/gm_commands/findrace.cpp deleted file mode 100755 index b0bee13c1..000000000 --- a/zone/gm_commands/findrace.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "../client.h" - -void command_findrace(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Command Syntax: #findrace [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - auto race_id = static_cast(Strings::ToUnsignedInt(sep->arg[1])); - std::string race_name = GetRaceIDName(race_id); - if ( - race_id >= RACE_HUMAN_1 && - race_id <= RACE_PEGASUS_732 - ) { - c->Message( - Chat::White, - fmt::format( - "Race {} | {}{}", - race_id, - race_name, - ( - c->IsPlayerRace(race_id) ? - fmt::format( - " ({})", - GetPlayerRaceBit(race_id) - ) : - "" - ) - ).c_str() - ); - } else { - c->Message( - Chat::White, - fmt::format( - "Race ID {} was not found.", - race_id - ).c_str() - ); - } - } else { - auto search_criteria = Strings::ToLower(sep->argplus[1]); - int found_count = 0; - for (uint16 race_id = RACE_HUMAN_1; race_id <= RACE_PEGASUS_732; race_id++) { - std::string race_name = GetRaceIDName(race_id); - auto race_name_lower = Strings::ToLower(race_name); - if ( - search_criteria.length() && - race_name_lower.find(search_criteria) == std::string::npos - ) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Race {} | {}{}", - race_id, - race_name, - ( - c->IsPlayerRace(race_id) ? - fmt::format( - " ({})", - GetPlayerRaceBit(race_id) - ) : - "" - ) - ).c_str() - ); - - found_count++; - - if (found_count == 50) { - break; - } - } - - if (found_count == 50) { - c->Message(Chat::White, "50 Races found, max reached."); - } else { - c->Message( - Chat::White, - fmt::format( - "{} Race{} found.", - found_count, - found_count != 1 ? "s" : "" - ).c_str() - ); - } - } -} - diff --git a/zone/gm_commands/findrecipe.cpp b/zone/gm_commands/findrecipe.cpp deleted file mode 100755 index 4b3593ea9..000000000 --- a/zone/gm_commands/findrecipe.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "../client.h" -#include "../command.h" -#include "../../common/repositories/tradeskill_recipe_repository.h" - -void command_findrecipe(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - if (!arguments) { - c->Message(Chat::White, "Command Syntax: #findrecipe [Search Criteria]"); - return; - } - - if (sep->IsNumber(1)) { - auto recipe_id = static_cast(Strings::ToUnsignedInt(sep->arg[1])); - auto r = TradeskillRecipeRepository::GetWhere( - database, - fmt::format("id = {}", recipe_id) - ); - - if (r.empty() || !r[0].id) { - c->Message( - Chat::White, - fmt::format( - "Recipe ID {} could not be found.", - Strings::Commify(std::to_string(recipe_id)) - ).c_str() - ); - return; - } - - bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe"); - - c->Message( - Chat::White, - fmt::format( - "Recipe {} | {}{}", - Strings::Commify(std::to_string(recipe_id)), - r[0].name, - can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r[0].id), "View")) : "" - ).c_str() - ); - } else { - auto search_criteria = Strings::ToLower(sep->argplus[1]); - int found_count = 0; - - auto rl = TradeskillRecipeRepository::GetWhere( - database, - fmt::format("`name` LIKE '%{}%' ORDER BY `id` ASC", search_criteria) - ); - - if (rl.empty() || !rl[0].id) { - c->Message( - Chat::White, - fmt::format( - "No recipes were found matching '{}'.", - search_criteria - ).c_str() - ); - return; - } - - bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe"); - - for (const auto& r : rl) { - c->Message( - Chat::White, - fmt::format( - "Recipe {} | {}{}", - Strings::Commify(std::to_string(r.id)), - r.name, - can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r.id), "View")) : "" - ).c_str() - ); - - if (found_count == 50) { - break; - } - - found_count++; - } - - if (found_count == 50) { - c->Message(Chat::White, "50 Recipes found, max reached."); - } else { - c->Message( - Chat::White, - fmt::format( - "{} Recipe{} found.", - found_count, - found_count != 1 ? "s" : "" - ).c_str() - ); - } - } -} - diff --git a/zone/gm_commands/findskill.cpp b/zone/gm_commands/findskill.cpp deleted file mode 100755 index 68231200f..000000000 --- a/zone/gm_commands/findskill.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "../client.h" - -void command_findskill(Client *c, const Seperator *sep) -{ - int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findskill [search criteria]"); - return; - } - - std::map skills = EQ::skills::GetSkillTypeMap(); - if (sep->IsNumber(1)) { - int skill_id = Strings::ToInt(sep->arg[1]); - if (skill_id >= EQ::skills::Skill1HBlunt && skill_id < EQ::skills::SkillCount) { - for (auto skill : skills) { - if (skill_id == skill.first) { - c->Message( - Chat::White, - fmt::format( - "Skill {}: {}", - skill.first, - skill.second - ).c_str() - ); - break; - } - } - } - else { - c->Message( - Chat::White, - fmt::format( - "Skill ID {} was not found.", - skill_id - ).c_str() - ); - } - } - else { - std::string search_criteria = Strings::ToLower(sep->argplus[1]); - if (!search_criteria.empty()) { - int found_count = 0; - for (auto skill : skills) { - std::string skill_name_lower = Strings::ToLower(skill.second); - if (skill_name_lower.find(search_criteria) == std::string::npos) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Skill {}: {}", - skill.first, - skill.second - ).c_str() - ); - found_count++; - - if (found_count == 20) { - break; - } - } - - if (found_count == 20) { - c->Message(Chat::White, "20 Skills were found, max reached."); - } - else { - auto skill_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Skill was" : - fmt::format("{} Skills were", found_count) - ) : - "No Skills were" - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - skill_message - ).c_str() - ); - } - } - } -} - diff --git a/zone/gm_commands/findspell.cpp b/zone/gm_commands/findspell.cpp deleted file mode 100755 index 1ec4f1d10..000000000 --- a/zone/gm_commands/findspell.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "../client.h" - -void command_findspell(Client *c, const Seperator *sep) -{ - if (SPDAT_RECORDS <= 0) { - c->Message(Chat::White, "Spells not loaded"); - return; - } - - int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findspell [search criteria]"); - return; - } - - if (sep->IsNumber(1)) { - int spell_id = Strings::ToInt(sep->arg[1]); - if (!IsValidSpell(spell_id)) { - c->Message( - Chat::White, - fmt::format( - "Spell ID {} was not found.", - spell_id - ).c_str() - ); - } - else { - c->Message( - Chat::White, - fmt::format( - "Spell {}: {}", - spell_id, - spells[spell_id].name - ).c_str() - ); - } - } - else { - std::string search_criteria = Strings::ToLower(sep->argplus[1]); - int found_count = 0; - for (int spell_id = 0; spell_id < SPDAT_RECORDS; spell_id++) { - auto current_spell = spells[spell_id]; - if (current_spell.name[0] != 0) { - std::string spell_name = current_spell.name; - std::string spell_name_lower = Strings::ToLower(spell_name); - if (search_criteria.length() > 0 && spell_name_lower.find(search_criteria) == std::string::npos) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Spell {}: {}", - spell_id, - spell_name - ).c_str() - ); - found_count++; - - if (found_count == 20) { - break; - } - } - } - - if (found_count == 20) { - c->Message(Chat::White, "20 Spells found... max reached."); - } - else { - auto spell_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Spell was" : - fmt::format("{} Spells were", found_count) - ) : - "No Spells were" - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - spell_message - ).c_str() - ); - } - } -} diff --git a/zone/gm_commands/findtask.cpp b/zone/gm_commands/findtask.cpp deleted file mode 100755 index 78556a158..000000000 --- a/zone/gm_commands/findtask.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "../client.h" - -void command_findtask(Client *c, const Seperator *sep) -{ - if (RuleB(TaskSystem, EnableTaskSystem)) { - int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findtask [search criteria]"); - return; - } - - if (sep->IsNumber(1)) { - auto task_id = Strings::ToUnsignedInt(sep->arg[1]); - auto task_name = task_manager->GetTaskName(task_id); - - std::string task_message = ( - !task_name.empty() ? - fmt::format( - "Task {}: {}", - task_id, - task_name - ) : - fmt::format( - "Task ID {} was not found.", - task_id - ) - ); - - c->Message( - Chat::White, - task_message.c_str() - ); - } - else { - std::string search_criteria = Strings::ToLower(sep->argplus[1]); - if (!search_criteria.empty()) { - int found_count = 0; - for (const auto &task: task_manager->GetTaskData()) { - auto task_name = task.second.title; - std::string task_name_lower = Strings::ToLower(task_name); - if (task_name_lower.find(search_criteria) == std::string::npos) { - continue; - } - - c->Message( - Chat::White, - fmt::format( - "Task {}: {}", - task.first, - task_name - ).c_str() - ); - found_count++; - - if (found_count == 20) { - break; - } - } - - if (found_count == 20) { - c->Message(Chat::White, "20 Tasks were found, max reached."); - } - else { - auto task_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Task was" : - fmt::format("{} Tasks were", found_count) - ) : - "No Tasks were" - ); - - c->Message( - Chat::White, - fmt::format( - "{} found.", - task_message - ).c_str() - ); - } - } - } - } - else { - c->Message(Chat::White, "This command cannot be used while the Task system is disabled."); - } -} - diff --git a/zone/gm_commands/findzone.cpp b/zone/gm_commands/findzone.cpp deleted file mode 100755 index baba6b63a..000000000 --- a/zone/gm_commands/findzone.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#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]); - } -} - diff --git a/zone/gm_commands/itemsearch.cpp b/zone/gm_commands/itemsearch.cpp deleted file mode 100755 index 084b38833..000000000 --- a/zone/gm_commands/itemsearch.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "../client.h" - -void command_itemsearch(Client *c, const Seperator *sep) -{ - if (sep->arg[1][0] == 0) { - c->Message(Chat::White, "Usage: #itemsearch [search string]"); - } - else { - const char *search_criteria = sep->argplus[1]; - - const EQ::ItemData *item = nullptr; - EQ::SayLinkEngine linker; - linker.SetLinkType(EQ::saylink::SayLinkItemData); - - if (Seperator::IsNumber(search_criteria)) { - item = database.GetItem(Strings::ToInt(search_criteria)); - if (item) { - linker.SetItemData(item); - std::string item_id = std::to_string(item->ID); - std::string saylink_commands = - "[" + - Saylink::Silent( - "#si " + item_id, - "X" - ) + - "] "; - - if (item->Stackable && item->StackSize > 1) { - std::string stack_size = std::to_string(item->StackSize); - saylink_commands += - "[" + - Saylink::Silent( - "#si " + item_id + " " + stack_size, - stack_size - ) + - "]"; - } - - c->Message( - Chat::White, - fmt::format( - " Summon {} [{}] [{}]", - saylink_commands, - linker.GenerateLink(), - item->ID - ).c_str() - ); - } - else { - c->Message( - Chat::White, - fmt::format( - "Item {} not found", - search_criteria - ).c_str() - ); - } - - return; - } - - int count = 0; - char sName[64]; - char sCriteria[255]; - strn0cpy(sCriteria, search_criteria, sizeof(sCriteria)); - strupr(sCriteria); - char *pdest; - uint32 it = 0; - while ((item = database.IterateItems(&it))) { - strn0cpy(sName, item->Name, sizeof(sName)); - strupr(sName); - pdest = strstr(sName, sCriteria); - if (pdest != nullptr) { - linker.SetItemData(item); - std::string item_id = std::to_string(item->ID); - std::string saylink_commands = - "[" + - Saylink::Silent( - "#si " + item_id, - "X" - ) + - "] "; - if (item->Stackable && item->StackSize > 1) { - std::string stack_size = std::to_string(item->StackSize); - saylink_commands += - "[" + - Saylink::Silent( - "#si " + item_id + " " + stack_size, - stack_size - ) + - "]"; - } - - c->Message( - Chat::White, - fmt::format( - " Summon {} [{}] [{}]", - saylink_commands, - linker.GenerateLink(), - item->ID - ).c_str() - ); - - ++count; - } - - if (count == 50) { - break; - } - } - - if (count == 50) { - c->Message(Chat::White, "50 items shown...too many results."); - } - else { - c->Message(Chat::White, "%i items found", count); - } - - } -} -