diff --git a/src/server/scripts/Commands/cs_lookup.cpp b/src/server/scripts/Commands/cs_lookup.cpp index 0417159c1..f95e553bf 100644 --- a/src/server/scripts/Commands/cs_lookup.cpp +++ b/src/server/scripts/Commands/cs_lookup.cpp @@ -32,10 +32,6 @@ EndScriptData */ #include "ScriptMgr.h" #include "SpellInfo.h" -#if AC_COMPILER == AC_COMPILER_GNU -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - using namespace Acore::ChatCommands; class lookup_commandscript : public CommandScript @@ -47,54 +43,48 @@ public: { static ChatCommandTable lookupPlayerCommandTable = { - { "ip", SEC_GAMEMASTER, true, &HandleLookupPlayerIpCommand, "" }, - { "account", SEC_GAMEMASTER, true, &HandleLookupPlayerAccountCommand, "" }, - { "email", SEC_GAMEMASTER, true, &HandleLookupPlayerEmailCommand, "" } - }; - - static ChatCommandTable lookupSpellCommandTable = - { - { "id", SEC_MODERATOR, true, &HandleLookupSpellIdCommand, "" }, - { "", SEC_MODERATOR, true, &HandleLookupSpellCommand, "" } + { "ip", HandleLookupPlayerIpCommand, SEC_GAMEMASTER, Console::Yes }, + { "account", HandleLookupPlayerAccountCommand, SEC_GAMEMASTER, Console::Yes }, + { "email", HandleLookupPlayerEmailCommand, SEC_GAMEMASTER, Console::Yes } }; static ChatCommandTable lookupCommandTable = { - { "area", SEC_MODERATOR, true, &HandleLookupAreaCommand, "" }, - { "creature", SEC_MODERATOR, true, &HandleLookupCreatureCommand, "" }, - { "event", SEC_MODERATOR, true, &HandleLookupEventCommand, "" }, - { "faction", SEC_MODERATOR, true, &HandleLookupFactionCommand, "" }, - { "item", SEC_MODERATOR, true, &HandleLookupItemCommand, "" }, - { "itemset", SEC_MODERATOR, true, &HandleLookupItemSetCommand, "" }, - { "object", SEC_MODERATOR, true, &HandleLookupObjectCommand, "" }, - { "gobject", SEC_MODERATOR, true, &HandleLookupObjectCommand, "" }, - { "quest", SEC_MODERATOR, true, &HandleLookupQuestCommand, "" }, - { "skill", SEC_MODERATOR, true, &HandleLookupSkillCommand, "" }, - { "taxinode", SEC_MODERATOR, true, &HandleLookupTaxiNodeCommand, "" }, - { "teleport", SEC_MODERATOR, true, &HandleLookupTeleCommand, "" }, - { "title", SEC_MODERATOR, true, &HandleLookupTitleCommand, "" }, - { "map", SEC_MODERATOR, true, &HandleLookupMapCommand, "" }, - { "player", SEC_GAMEMASTER, true, nullptr, "", lookupPlayerCommandTable }, - { "spell", SEC_MODERATOR, true, nullptr, "", lookupSpellCommandTable } + { "area", HandleLookupAreaCommand, SEC_MODERATOR, Console::Yes }, + { "creature", HandleLookupCreatureCommand, SEC_MODERATOR, Console::Yes }, + { "event", HandleLookupEventCommand, SEC_MODERATOR, Console::Yes }, + { "faction", HandleLookupFactionCommand, SEC_MODERATOR, Console::Yes }, + { "item", HandleLookupItemCommand, SEC_MODERATOR, Console::Yes }, + { "itemset", HandleLookupItemSetCommand, SEC_MODERATOR, Console::Yes }, + { "map", HandleLookupMapCommand, SEC_MODERATOR, Console::Yes }, + { "object", HandleLookupObjectCommand, SEC_MODERATOR, Console::Yes }, + { "gobject", HandleLookupObjectCommand, SEC_MODERATOR, Console::Yes }, + { "quest", HandleLookupQuestCommand, SEC_MODERATOR, Console::Yes }, + { "skill", HandleLookupSkillCommand, SEC_MODERATOR, Console::Yes }, + { "taxinode", HandleLookupTaxiNodeCommand, SEC_MODERATOR, Console::Yes }, + { "teleport", HandleLookupTeleCommand, SEC_MODERATOR, Console::Yes }, + { "title", HandleLookupTitleCommand, SEC_MODERATOR, Console::Yes }, + { "spell", HandleLookupSpellCommand, SEC_MODERATOR, Console::Yes }, + { "spell id", HandleLookupSpellIdCommand, SEC_MODERATOR, Console::Yes }, + { "player", lookupPlayerCommandTable }, }; static ChatCommandTable commandTable = { - { "lookup", SEC_MODERATOR, true, nullptr, "", lookupCommandTable } + { "lookup", lookupCommandTable } }; + return commandTable; } - static bool HandleLookupAreaCommand(ChatHandler* handler, char const* args) + static bool HandleLookupAreaCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } bool found = false; uint32 count = 0; @@ -104,73 +94,84 @@ public: wstrToLower(wNamePart); // Search in AreaTable.dbc - for (uint32 i = 0; i < sAreaTableStore.GetNumRows(); ++i) + for (auto const& areaEntry : sAreaTableStore) { - AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(i); - if (areaEntry) + int locale = handler->GetSessionDbcLocale(); + std::string name = areaEntry->area_name[locale]; + + if (name.empty()) { - int locale = handler->GetSessionDbcLocale(); - std::string name = areaEntry->area_name[locale]; - if (name.empty()) - continue; + continue; + } - if (!Utf8FitTo(name, wNamePart)) + if (!Utf8FitTo(name, wNamePart)) + { + locale = 0; + for (; locale < TOTAL_LOCALES; ++locale) { - locale = 0; - for (; locale < TOTAL_LOCALES; ++locale) + if (locale == handler->GetSessionDbcLocale()) { - if (locale == handler->GetSessionDbcLocale()) - continue; + continue; + } - name = areaEntry->area_name[locale]; - if (name.empty()) - continue; + name = areaEntry->area_name[locale]; + if (name.empty()) + { + continue; + } - if (Utf8FitTo(name, wNamePart)) - break; + if (Utf8FitTo(name, wNamePart)) + { + break; } } + } - if (locale < TOTAL_LOCALES) + if (locale < TOTAL_LOCALES) + { + if (maxResults && count++ == maxResults) { - if (maxResults && count++ == maxResults) - { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; - } + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } - // send area in "id - [name]" format - std::ostringstream ss; - if (handler->GetSession()) - ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << ' ' << localeNames[locale] << "]|h|r"; - else - ss << areaEntry->ID << " - " << name << ' ' << localeNames[locale]; + // send area in "id - [name]" format + std::ostringstream ss; + if (handler->GetSession()) + { + ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << ' ' << localeNames[locale] << "]|h|r"; + } + else + { + ss << areaEntry->ID << " - " << name << ' ' << localeNames[locale]; + } - handler->SendSysMessage(ss.str().c_str()); + handler->SendSysMessage(ss.str().c_str()); - if (!found) - found = true; + if (!found) + { + found = true; } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOAREAFOUND); + } return true; } - static bool HandleLookupCreatureCommand(ChatHandler* handler, char const* args) + static bool HandleLookupCreatureCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -178,10 +179,9 @@ public: uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - CreatureTemplateContainer const* ctc = sObjectMgr->GetCreatureTemplates(); - for (CreatureTemplateContainer::const_iterator itr = ctc->begin(); itr != ctc->end(); ++itr) + for (auto const& [entry, creatureTemplate] : *sObjectMgr->GetCreatureTemplates()) { - uint32 id = itr->second.Entry; + uint32 id = creatureTemplate.Entry; uint8 localeIndex = handler->GetSessionDbLocaleIndex(); if (CreatureLocale const* creatureLocale = sObjectMgr->GetCreatureLocale(id)) { @@ -198,21 +198,29 @@ public: } if (handler->GetSession()) + { handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str()); + } else + { handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str()); + } if (!found) + { found = true; + } continue; } } } - std::string name = itr->second.Name; + std::string name = creatureTemplate.Name; if (name.empty()) + { continue; + } if (Utf8FitTo(name, wNamePart)) { @@ -223,32 +231,38 @@ public: } if (handler->GetSession()) + { handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str()); + } else + { handler->PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str()); + } if (!found) + { found = true; + } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOCREATUREFOUND); + } return true; } - static bool HandleLookupEventCommand(ChatHandler* handler, char const* args) + static bool HandleLookupEventCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -265,7 +279,9 @@ public: std::string descr = eventData.description; if (descr.empty()) + { continue; + } if (Utf8FitTo(descr, wNamePart)) { @@ -278,134 +294,171 @@ public: char const* active = activeEvents.find(id) != activeEvents.end() ? handler->GetAcoreString(LANG_ACTIVE) : ""; if (handler->GetSession()) + { handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, id, id, eventData.description.c_str(), active); + } else + { handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, id, eventData.description.c_str(), active); + } if (!found) + { found = true; + } } } if (!found) + { handler->SendSysMessage(LANG_NOEVENTFOUND); + } return true; } - static bool HandleLookupFactionCommand(ChatHandler* handler, char const* args) + static bool HandleLookupFactionCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - // Can be nullptr at console call Player* target = handler->getSelectedPlayer(); - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case - wstrToLower (wNamePart); + wstrToLower(wNamePart); bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - for (uint32 id = 0; id < sFactionStore.GetNumRows(); ++id) + for (auto const& factionEntry : sFactionStore) { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(id); - if (factionEntry) + FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : nullptr; + + int locale = handler->GetSessionDbcLocale(); + std::string name = factionEntry->name[locale]; + if (name.empty()) { - FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : nullptr; + continue; + } - int locale = handler->GetSessionDbcLocale(); - std::string name = factionEntry->name[locale]; - if (name.empty()) - continue; + if (!Utf8FitTo(name, wNamePart)) + { + locale = 0; - if (!Utf8FitTo(name, wNamePart)) + for (; locale < TOTAL_LOCALES; ++locale) { - locale = 0; - for (; locale < TOTAL_LOCALES; ++locale) + if (locale == handler->GetSessionDbcLocale()) { - if (locale == handler->GetSessionDbcLocale()) - continue; + continue; + } - name = factionEntry->name[locale]; - if (name.empty()) - continue; + name = factionEntry->name[locale]; + if (name.empty()) + { + continue; + } - if (Utf8FitTo(name, wNamePart)) - break; + if (Utf8FitTo(name, wNamePart)) + { + break; } } + } - if (locale < TOTAL_LOCALES) + if (locale < TOTAL_LOCALES) + { + if (maxResults && count++ == maxResults) { - if (maxResults && count++ == maxResults) + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } + + // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format + // or "id - [faction] [no reputation]" format + std::ostringstream ss; + if (handler->GetSession()) + { + ss << factionEntry->ID << " - |cffffffff|Hfaction:" << factionEntry->ID << "|h[" << name << ' ' << localeNames[locale] << "]|h|r"; + } + else + { + ss << factionEntry->ID << " - " << name << ' ' << localeNames[locale]; + } + + if (factionState) // and then target != nullptr also + { + uint32 index = target->GetReputationMgr().GetReputationRankStrIndex(factionEntry); + std::string rankName = handler->GetAcoreString(index); + + ss << ' ' << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ')'; + + if (factionState->Flags & FACTION_FLAG_VISIBLE) { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; + ss << handler->GetAcoreString(LANG_FACTION_VISIBLE); } - // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format - // or "id - [faction] [no reputation]" format - std::ostringstream ss; - if (handler->GetSession()) - ss << id << " - |cffffffff|Hfaction:" << id << "|h[" << name << ' ' << localeNames[locale] << "]|h|r"; - else - ss << id << " - " << name << ' ' << localeNames[locale]; - - if (factionState) // and then target != nullptr also + if (factionState->Flags & FACTION_FLAG_AT_WAR) { - uint32 index = target->GetReputationMgr().GetReputationRankStrIndex(factionEntry); - std::string rankName = handler->GetAcoreString(index); - - ss << ' ' << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ')'; - - if (factionState->Flags & FACTION_FLAG_VISIBLE) - ss << handler->GetAcoreString(LANG_FACTION_VISIBLE); - if (factionState->Flags & FACTION_FLAG_AT_WAR) - ss << handler->GetAcoreString(LANG_FACTION_ATWAR); - if (factionState->Flags & FACTION_FLAG_PEACE_FORCED) - ss << handler->GetAcoreString(LANG_FACTION_PEACE_FORCED); - if (factionState->Flags & FACTION_FLAG_HIDDEN) - ss << handler->GetAcoreString(LANG_FACTION_HIDDEN); - if (factionState->Flags & FACTION_FLAG_INVISIBLE_FORCED) - ss << handler->GetAcoreString(LANG_FACTION_INVISIBLE_FORCED); - if (factionState->Flags & FACTION_FLAG_INACTIVE) - ss << handler->GetAcoreString(LANG_FACTION_INACTIVE); + ss << handler->GetAcoreString(LANG_FACTION_ATWAR); } - else - ss << handler->GetAcoreString(LANG_FACTION_NOREPUTATION); - handler->SendSysMessage(ss.str().c_str()); + if (factionState->Flags & FACTION_FLAG_PEACE_FORCED) + { + ss << handler->GetAcoreString(LANG_FACTION_PEACE_FORCED); + } - if (!found) - found = true; + if (factionState->Flags & FACTION_FLAG_HIDDEN) + { + ss << handler->GetAcoreString(LANG_FACTION_HIDDEN); + } + + if (factionState->Flags & FACTION_FLAG_INVISIBLE_FORCED) + { + ss << handler->GetAcoreString(LANG_FACTION_INVISIBLE_FORCED); + } + + if (factionState->Flags & FACTION_FLAG_INACTIVE) + { + ss << handler->GetAcoreString(LANG_FACTION_INACTIVE); + } + } + else + { + ss << handler->GetAcoreString(LANG_FACTION_NOREPUTATION); + } + + handler->SendSysMessage(ss.str().c_str()); + + if (!found) + { + found = true; } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_FACTION_NOTFOUND); + } + return true; } - static bool HandleLookupItemCommand(ChatHandler* handler, char const* args) + static bool HandleLookupItemCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -414,14 +467,13 @@ public: uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in `item_template` - ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore(); - for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr) + for (auto const& [entry, itemTemplate] : *sObjectMgr->GetItemTemplateStore()) { int localeIndex = handler->GetSessionDbLocaleIndex(); if (localeIndex >= 0) { uint8 ulocaleIndex = uint8(localeIndex); - if (ItemLocale const* il = sObjectMgr->GetItemLocale(itr->second.ItemId)) + if (ItemLocale const* il = sObjectMgr->GetItemLocale(itemTemplate.ItemId)) { if (il->Name.size() > ulocaleIndex && !il->Name[ulocaleIndex].empty()) { @@ -436,12 +488,18 @@ public: } if (handler->GetSession()) - handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str()); + { + handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itemTemplate.ItemId, itemTemplate.ItemId, name.c_str()); + } else - handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str()); + { + handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itemTemplate.ItemId, name.c_str()); + } if (!found) + { found = true; + } continue; } @@ -449,9 +507,11 @@ public: } } - std::string name = itr->second.Name1; + std::string name = itemTemplate.Name1; if (name.empty()) + { continue; + } if (Utf8FitTo(name, wNamePart)) { @@ -462,31 +522,37 @@ public: } if (handler->GetSession()) - handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str()); + { + handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itemTemplate.ItemId, itemTemplate.ItemId, name.c_str()); + } else - handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str()); + { + handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itemTemplate.ItemId, name.c_str()); + } if (!found) + { found = true; + } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOITEMFOUND); + } return true; } - static bool HandleLookupItemSetCommand(ChatHandler* handler, char const* args) + static bool HandleLookupItemSetCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case wstrToLower(wNamePart); @@ -504,7 +570,9 @@ public: int locale = handler->GetSessionDbcLocale(); std::string name = set->name[locale]; if (name.empty()) + { continue; + } if (!Utf8FitTo(name, wNamePart)) { @@ -512,14 +580,20 @@ public: for (; locale < TOTAL_LOCALES; ++locale) { if (locale == handler->GetSessionDbcLocale()) + { continue; + } name = set->name[locale]; if (name.empty()) + { continue; + } if (Utf8FitTo(name, wNamePart)) + { break; + } } } @@ -533,32 +607,39 @@ public: // send item set in "id - [namedlink locale]" format if (handler->GetSession()) + { handler->PSendSysMessage(LANG_ITEMSET_LIST_CHAT, id, id, name.c_str(), localeNames[locale]); + } else + { handler->PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE, id, name.c_str(), localeNames[locale]); + } if (!found) + { found = true; + } } } } + if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOITEMSETFOUND); + } return true; } - static bool HandleLookupObjectCommand(ChatHandler* handler, char const* args) + static bool HandleLookupObjectCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -566,11 +647,10 @@ public: uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - GameObjectTemplateContainer const* gotc = sObjectMgr->GetGameObjectTemplates(); - for (GameObjectTemplateContainer::const_iterator itr = gotc->begin(); itr != gotc->end(); ++itr) + for (auto const& [entry, gameObjectTemplate] : *sObjectMgr->GetGameObjectTemplates()) { uint8 localeIndex = handler->GetSessionDbLocaleIndex(); - if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(itr->second.entry)) + if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(gameObjectTemplate.entry)) { if (objectLocalte->Name.size() > localeIndex && !objectLocalte->Name[localeIndex].empty()) { @@ -585,21 +665,29 @@ public: } if (handler->GetSession()) - handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str()); + { + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, gameObjectTemplate.entry, gameObjectTemplate.entry, name.c_str()); + } else - handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str()); + { + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, gameObjectTemplate.entry, name.c_str()); + } if (!found) + { found = true; + } continue; } } } - std::string name = itr->second.name; + std::string name = gameObjectTemplate.name; if (name.empty()) + { continue; + } if (Utf8FitTo(name, wNamePart)) { @@ -610,35 +698,41 @@ public: } if (handler->GetSession()) - handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str()); + { + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, gameObjectTemplate.entry, gameObjectTemplate.entry, name.c_str()); + } else - handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str()); + { + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, gameObjectTemplate.entry, name.c_str()); + } if (!found) + { found = true; + } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND); + } return true; } - static bool HandleLookupQuestCommand(ChatHandler* handler, char const* args) + static bool HandleLookupQuestCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - // can be nullptr at console call Player* target = handler->getSelectedPlayer(); - std::string namePart = args; std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -646,11 +740,8 @@ public: uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - ObjectMgr::QuestMap const& qTemplates = sObjectMgr->GetQuestTemplates(); - for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter) + for (auto const& [entry, qInfo] : sObjectMgr->GetQuestTemplates()) { - Quest* qInfo = iter->second; - int localeIndex = handler->GetSessionDbLocaleIndex(); if (localeIndex >= 0) { @@ -692,12 +783,19 @@ public: } if (handler->GetSession()) + { handler->PSendSysMessage(LANG_QUEST_LIST_CHAT, qInfo->GetQuestId(), qInfo->GetQuestId(), qInfo->GetQuestLevel(), title.c_str(), statusStr); + } else + { handler->PSendSysMessage(LANG_QUEST_LIST_CONSOLE, qInfo->GetQuestId(), title.c_str(), statusStr); + } if (!found) + { found = true; + } + continue; } } @@ -706,7 +804,9 @@ public: std::string title = qInfo->GetTitle(); if (title.empty()) + { continue; + } if (Utf8FitTo(title, wNamePart)) { @@ -739,34 +839,40 @@ public: } if (handler->GetSession()) + { handler->PSendSysMessage(LANG_QUEST_LIST_CHAT, qInfo->GetQuestId(), qInfo->GetQuestId(), qInfo->GetQuestLevel(), title.c_str(), statusStr); + } else + { handler->PSendSysMessage(LANG_QUEST_LIST_CONSOLE, qInfo->GetQuestId(), title.c_str(), statusStr); + } if (!found) + { found = true; + } } } if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOQUESTFOUND); + } return true; } - static bool HandleLookupSkillCommand(ChatHandler* handler, char const* args) + static bool HandleLookupSkillCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - // can be nullptr in console call Player* target = handler->getSelectedPlayer(); - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case wstrToLower(wNamePart); @@ -776,85 +882,97 @@ public: uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in SkillLine.dbc - for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++) + for (auto const& skillInfo : sSkillLineStore) { - SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id); - if (skillInfo) + int locale = handler->GetSessionDbcLocale(); + std::string name = skillInfo->name[locale]; + + if (name.empty()) { - int locale = handler->GetSessionDbcLocale(); - std::string name = skillInfo->name[locale]; - if (name.empty()) - continue; + continue; + } - if (!Utf8FitTo(name, wNamePart)) + if (!Utf8FitTo(name, wNamePart)) + { + locale = 0; + for (; locale < TOTAL_LOCALES; ++locale) { - locale = 0; - for (; locale < TOTAL_LOCALES; ++locale) + if (locale == handler->GetSessionDbcLocale()) { - if (locale == handler->GetSessionDbcLocale()) - continue; + continue; + } - name = skillInfo->name[locale]; - if (name.empty()) - continue; + name = skillInfo->name[locale]; + if (name.empty()) + { + continue; + } - if (Utf8FitTo(name, wNamePart)) - break; + if (Utf8FitTo(name, wNamePart)) + { + break; } } + } - if (locale < TOTAL_LOCALES) + if (locale < TOTAL_LOCALES) + { + if (maxResults && count++ == maxResults) { - if (maxResults && count++ == maxResults) - { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; - } + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } - char valStr[50] = ""; - char const* knownStr = ""; - if (target && target->HasSkill(id)) - { - knownStr = handler->GetAcoreString(LANG_KNOWN); - uint32 curValue = target->GetPureSkillValue(id); - uint32 maxValue = target->GetPureMaxSkillValue(id); - uint32 permValue = target->GetSkillPermBonusValue(id); - uint32 tempValue = target->GetSkillTempBonusValue(id); + std::string valStr; + std::string knownStr; - char const* valFormat = handler->GetAcoreString(LANG_SKILL_VALUES); - snprintf(valStr, 50, valFormat, curValue, maxValue, permValue, tempValue); - } + if (target && target->HasSkill(skillInfo->id)) + { + knownStr = handler->GetAcoreString(LANG_KNOWN); + uint32 curValue = target->GetPureSkillValue(skillInfo->id); + uint32 maxValue = target->GetPureMaxSkillValue(skillInfo->id); + uint32 permValue = target->GetSkillPermBonusValue(skillInfo->id); + uint32 tempValue = target->GetSkillTempBonusValue(skillInfo->id); - // send skill in "id - [namedlink locale]" format - if (handler->GetSession()) - handler->PSendSysMessage(LANG_SKILL_LIST_CHAT, id, id, name.c_str(), localeNames[locale], knownStr, valStr); - else - handler->PSendSysMessage(LANG_SKILL_LIST_CONSOLE, id, name.c_str(), localeNames[locale], knownStr, valStr); + valStr = Acore::StringFormat(handler->GetAcoreString(LANG_SKILL_VALUES), curValue, maxValue, permValue, tempValue); + } - if (!found) - found = true; + // send skill in "id - [namedlink locale]" format + if (handler->GetSession()) + { + handler->PSendSysMessage(LANG_SKILL_LIST_CHAT, skillInfo->id, skillInfo->id, name.c_str(), localeNames[locale], knownStr.c_str(), valStr.c_str()); + } + else + { + handler->PSendSysMessage(LANG_SKILL_LIST_CONSOLE, skillInfo->id, name.c_str(), localeNames[locale], knownStr.c_str(), valStr.c_str()); + } + + if (!found) + { + found = true; } } } + if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOSKILLFOUND); + } return true; } - static bool HandleLookupSpellCommand(ChatHandler* handler, char const* args) + static bool HandleLookupSpellCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - // can be nullptr at console call Player* target = handler->getSelectedPlayer(); - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case wstrToLower(wNamePart); @@ -872,7 +990,9 @@ public: int locale = handler->GetSessionDbcLocale(); std::string name = spellInfo->SpellName[locale]; if (name.empty()) + { continue; + } if (!Utf8FitTo(name, wNamePart)) { @@ -880,14 +1000,20 @@ public: for (; locale < TOTAL_LOCALES; ++locale) { if (locale == handler->GetSessionDbcLocale()) + { continue; + } name = spellInfo->SpellName[locale]; if (name.empty()) + { continue; + } if (Utf8FitTo(name, wNamePart)) + { break; + } } } @@ -917,66 +1043,235 @@ public: // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format std::ostringstream ss; if (handler->GetSession()) + { ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; + } else + { ss << id << " - " << name; + } // include rank in link name if (rank) + { ss << handler->GetAcoreString(LANG_SPELL_RANK) << rank; + } if (handler->GetSession()) + { ss << ' ' << localeNames[locale] << "]|h|r"; + } else + { ss << ' ' << localeNames[locale]; + } if (talent) + { ss << handler->GetAcoreString(LANG_TALENT); + } + if (passive) + { ss << handler->GetAcoreString(LANG_PASSIVE); + } + if (learn) + { ss << handler->GetAcoreString(LANG_LEARN); + } + if (known) + { ss << handler->GetAcoreString(LANG_KNOWN); + } + if (active) + { ss << handler->GetAcoreString(LANG_ACTIVE); + } handler->SendSysMessage(ss.str().c_str()); if (!found) + { found = true; + } } } } + if (!found) + { handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); + } return true; } - static bool HandleLookupSpellIdCommand(ChatHandler* handler, char const* args) + static bool HandleLookupSpellIdCommand(ChatHandler* handler, SpellInfo const* spell) { - if (!*args) - return false; - // can be nullptr at console call Player* target = handler->getSelectedPlayer(); - uint32 id = atoi((char*)args); - bool found = false; uint32 count = 0; uint32 maxResults = 1; - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id); - if (spellInfo) + if (!SpellMgr::IsSpellValid(spell)) + { + handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id); + handler->SetSentErrorMessage(true); + return false; + } + + int locale = handler->GetSessionDbcLocale(); + std::string name = spell->SpellName[locale]; + if (name.empty()) + { + handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); + return true; + } + + if (locale < TOTAL_LOCALES) + { + if (maxResults && count++ == maxResults) + { + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } + + bool known = target && target->HasSpell(spell->Id); + bool learn = (spell->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL); + + SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spell->Effects[0].TriggerSpell); + + uint32 talentCost = GetTalentSpellCost(spell->Id); + + bool talent = (talentCost > 0); + bool passive = spell->IsPassive(); + bool active = target && target->HasAura(spell->Id); + + // unit32 used to prevent interpreting uint8 as char at output + // find rank of learned spell for learning spell, or talent rank + uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spell->GetRank(); + + // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format + std::ostringstream ss; + if (handler->GetSession()) + { + ss << spell->Id << " - |cffffffff|Hspell:" << spell->Id << "|h[" << name; + } + else + { + ss << spell->Id << " - " << name; + } + + // include rank in link name + if (rank) + { + ss << handler->GetAcoreString(LANG_SPELL_RANK) << rank; + } + + if (handler->GetSession()) + { + ss << ' ' << localeNames[locale] << "]|h|r"; + } + else + { + ss << ' ' << localeNames[locale]; + } + + if (talent) + { + ss << handler->GetAcoreString(LANG_TALENT); + } + + if (passive) + { + ss << handler->GetAcoreString(LANG_PASSIVE); + } + + if (learn) + { + ss << handler->GetAcoreString(LANG_LEARN); + } + + if (known) + { + ss << handler->GetAcoreString(LANG_KNOWN); + } + + if (active) + { + ss << handler->GetAcoreString(LANG_ACTIVE); + } + + handler->SendSysMessage(ss.str().c_str()); + + if (!found) + { + found = true; + } + } + + if (!found) + { + handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); + } + + return true; + } + + static bool HandleLookupTaxiNodeCommand(ChatHandler* handler, std::string_view namePart) + { + std::wstring wNamePart; + + if (!Utf8toWStr(namePart, wNamePart)) + { + return false; + } + + // converting string that we try to find to lower case + wstrToLower(wNamePart); + + bool found = false; + uint32 count = 0; + uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); + + // Search in TaxiNodes.dbc + for (auto const& nodeEntry : sTaxiNodesStore) { int locale = handler->GetSessionDbcLocale(); - std::string name = spellInfo->SpellName[locale]; + std::string name = nodeEntry->name[locale]; + if (name.empty()) { - handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); - return true; + continue; + } + + if (!Utf8FitTo(name, wNamePart)) + { + locale = 0; + + for (; locale < TOTAL_LOCALES; ++locale) + { + if (locale == handler->GetSessionDbcLocale()) + { + continue; + } + + name = nodeEntry->name[locale]; + if (name.empty()) + { + continue; + } + + if (Utf8FitTo(name, wNamePart)) + { + break; + } + } } if (locale < TOTAL_LOCALES) @@ -987,153 +1282,41 @@ public: return true; } - bool known = target && target->HasSpell(id); - bool learn = (spellInfo->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL); - - SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[0].TriggerSpell); - - uint32 talentCost = GetTalentSpellCost(id); - - bool talent = (talentCost > 0); - bool passive = spellInfo->IsPassive(); - bool active = target && target->HasAura(id); - - // unit32 used to prevent interpreting uint8 as char at output - // find rank of learned spell for learning spell, or talent rank - uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spellInfo->GetRank(); - - // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format - std::ostringstream ss; + // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format if (handler->GetSession()) - ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; + { + handler->PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CHAT, nodeEntry->ID, nodeEntry->ID, name.c_str(), localeNames[locale], + nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); + } else - ss << id << " - " << name; - - // include rank in link name - if (rank) - ss << handler->GetAcoreString(LANG_SPELL_RANK) << rank; - - if (handler->GetSession()) - ss << ' ' << localeNames[locale] << "]|h|r"; - else - ss << ' ' << localeNames[locale]; - - if (talent) - ss << handler->GetAcoreString(LANG_TALENT); - if (passive) - ss << handler->GetAcoreString(LANG_PASSIVE); - if (learn) - ss << handler->GetAcoreString(LANG_LEARN); - if (known) - ss << handler->GetAcoreString(LANG_KNOWN); - if (active) - ss << handler->GetAcoreString(LANG_ACTIVE); - - handler->SendSysMessage(ss.str().c_str()); + { + handler->PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CONSOLE, nodeEntry->ID, name.c_str(), localeNames[locale], + nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); + } if (!found) + { found = true; + } } } - if (!found) - handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); - - return true; - } - - static bool HandleLookupTaxiNodeCommand(ChatHandler* handler, const char* args) - { - if (!*args) - return false; - - std::string namePart = args; - std::wstring wNamePart; - - if (!Utf8toWStr(namePart, wNamePart)) - return false; - - // converting string that we try to find to lower case - wstrToLower(wNamePart); - - bool found = false; - uint32 count = 0; - uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - - // Search in TaxiNodes.dbc - for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++) { - TaxiNodesEntry const* nodeEntry = sTaxiNodesStore.LookupEntry(id); - if (nodeEntry) - { - int locale = handler->GetSessionDbcLocale(); - std::string name = nodeEntry->name[locale]; - if (name.empty()) - continue; - - if (!Utf8FitTo(name, wNamePart)) - { - locale = 0; - for (; locale < TOTAL_LOCALES; ++locale) - { - if (locale == handler->GetSessionDbcLocale()) - continue; - - name = nodeEntry->name[locale]; - if (name.empty()) - continue; - - if (Utf8FitTo(name, wNamePart)) - break; - } - } - - if (locale < TOTAL_LOCALES) - { - if (maxResults && count++ == maxResults) - { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; - } - - // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format - if (handler->GetSession()) - handler->PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(), localeNames[locale], - nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); - else - handler->PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[locale], - nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); - - if (!found) - found = true; - } - } - } - if (!found) handler->SendSysMessage(LANG_COMMAND_NOTAXINODEFOUND); + } return true; } // Find teleport in game_tele order by name - static bool HandleLookupTeleCommand(ChatHandler* handler, char const* args) + static bool HandleLookupTeleCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - { - handler->SendSysMessage(LANG_COMMAND_TELE_PARAMETER); - handler->SetSentErrorMessage(true); - return false; - } - - char const* str = strtok((char*)args, " "); - if (!str) - return false; - - std::string namePart = str; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case wstrToLower(wNamePart); @@ -1143,13 +1326,12 @@ public: uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); bool limitReached = false; - GameTeleContainer const& teleMap = sObjectMgr->GetGameTeleMap(); - for (GameTeleContainer::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr) + for (auto const& [id, tele] : sObjectMgr->GetGameTeleMap()) { - GameTele const* tele = &itr->second; - - if (tele->wnameLow.find(wNamePart) == std::wstring::npos) + if (tele.wnameLow.find(wNamePart) == std::wstring::npos) + { continue; + } if (maxResults && count++ == maxResults) { @@ -1158,38 +1340,46 @@ public: } if (handler->GetSession()) - reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n"; + { + reply << " |cffffffff|Htele:" << id << "|h[" << tele.name << "]|h|r\n"; + } else - reply << " " << itr->first << ' ' << tele->name << "\n"; + { + reply << " " << id << ' ' << tele.name << "\n"; + } } if (reply.str().empty()) + { handler->SendSysMessage(LANG_COMMAND_TELE_NOLOCATION); + } else + { handler->PSendSysMessage(LANG_COMMAND_TELE_LOCATION, reply.str().c_str()); + } if (limitReached) + { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + } return true; } - static bool HandleLookupTitleCommand(ChatHandler* handler, char const* args) + static bool HandleLookupTitleCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - // can be nullptr in console call Player* target = handler->getSelectedPlayer(); // title name have single string arg for player name char const* targetName = target ? target->GetName().c_str() : "NAME"; - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } // converting string that we try to find to lower case wstrToLower(wNamePart); @@ -1198,76 +1388,81 @@ public: uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in CharTitles.dbc - for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++) + for (auto const& titleInfo : sCharTitlesStore) { - CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); - if (titleInfo) + int locale = handler->GetSessionDbcLocale(); + std::string name = titleInfo->nameMale[locale]; + if (name.empty()) { - int locale = handler->GetSessionDbcLocale(); - std::string name = titleInfo->nameMale[locale]; - if (name.empty()) - continue; + continue; + } - if (!Utf8FitTo(name, wNamePart)) + if (!Utf8FitTo(name, wNamePart)) + { + locale = 0; + for (; locale < TOTAL_LOCALES; ++locale) { - locale = 0; - for (; locale < TOTAL_LOCALES; ++locale) + if (locale == handler->GetSessionDbcLocale()) { - if (locale == handler->GetSessionDbcLocale()) - continue; - - name = titleInfo->nameMale[locale]; - if (name.empty()) - continue; - - if (Utf8FitTo(name, wNamePart)) - break; - } - } - - if (locale < TOTAL_LOCALES) - { - if (maxResults && counter == maxResults) - { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; + continue; } - char const* knownStr = target && target->HasTitle(titleInfo) ? handler->GetAcoreString(LANG_KNOWN) : ""; + name = titleInfo->nameMale[locale]; + if (name.empty()) + { + continue; + } - char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index - ? handler->GetAcoreString(LANG_ACTIVE) - : ""; - - char titleNameStr[80]; - snprintf(titleNameStr, 80, name.c_str(), targetName); - - // send title in "id (idx:idx) - [namedlink locale]" format - if (handler->GetSession()) - handler->PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[locale], knownStr, activeStr); - else - handler->PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[locale], knownStr, activeStr); - - ++counter; + if (Utf8FitTo(name, wNamePart)) + { + break; + } } } + + if (locale < TOTAL_LOCALES) + { + if (maxResults && counter == maxResults) + { + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } + + char const* knownStr = target && target->HasTitle(titleInfo) ? handler->GetAcoreString(LANG_KNOWN) : ""; + char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index ? handler->GetAcoreString(LANG_ACTIVE) : ""; + + std::string titleNameStr = Acore::StringFormat(name, targetName); + + // send title in "id (idx:idx) - [namedlink locale]" format + if (handler->GetSession()) + { + handler->PSendSysMessage(LANG_TITLE_LIST_CHAT, titleInfo->ID, titleInfo->bit_index, titleInfo->ID, titleNameStr, localeNames[locale], knownStr, activeStr); + } + else + { + handler->PSendSysMessage(LANG_TITLE_LIST_CONSOLE, titleInfo->ID, titleInfo->bit_index, titleNameStr, localeNames[locale], knownStr, activeStr); + } + + ++counter; + } } - if (counter == 0) // if counter == 0 then we found nth + + if (!counter) // if counter == 0 then we found nth + { handler->SendSysMessage(LANG_COMMAND_NOTITLEFOUND); + } return true; } - static bool HandleLookupMapCommand(ChatHandler* handler, char const* args) + static bool HandleLookupMapCommand(ChatHandler* handler, std::string_view namePart) { - if (!*args) - return false; - - std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) + { return false; + } wstrToLower(wNamePart); @@ -1276,121 +1471,107 @@ public: uint8 locale = handler->GetSession() ? handler->GetSession()->GetSessionDbcLocale() : sWorld->GetDefaultDbcLocale(); // search in Map.dbc - for (uint32 id = 0; id < sMapStore.GetNumRows(); id++) + for (auto const& mapInfo : sMapStore) { - if (MapEntry const* mapInfo = sMapStore.LookupEntry(id)) + std::string name = mapInfo->name[locale]; + + if (name.empty()) { - std::string name = mapInfo->name[locale]; - if (name.empty()) - continue; + continue; + } - if (Utf8FitTo(name, wNamePart) && locale < TOTAL_LOCALES) + if (Utf8FitTo(name, wNamePart) && locale < TOTAL_LOCALES) + { + if (maxResults && counter == maxResults) { - if (maxResults && counter == maxResults) - { - handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); - return true; - } - - std::ostringstream ss; - ss << id << " - [" << name << ']'; - - if (mapInfo->IsContinent()) - ss << handler->GetAcoreString(LANG_CONTINENT); - - switch (mapInfo->map_type) - { - case MAP_INSTANCE: - ss << handler->GetAcoreString(LANG_INSTANCE); - break; - case MAP_RAID: - ss << handler->GetAcoreString(LANG_RAID); - break; - case MAP_BATTLEGROUND: - ss << handler->GetAcoreString(LANG_BATTLEGROUND); - break; - case MAP_ARENA: - ss << handler->GetAcoreString(LANG_ARENA); - break; - } - - handler->SendSysMessage(ss.str().c_str()); - - ++counter; + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; } + + std::ostringstream ss; + ss << mapInfo->MapID << " - [" << name << ']'; + + if (mapInfo->IsContinent()) + { + ss << handler->GetAcoreString(LANG_CONTINENT); + } + + switch (mapInfo->map_type) + { + case MAP_INSTANCE: + ss << handler->GetAcoreString(LANG_INSTANCE); + break; + case MAP_RAID: + ss << handler->GetAcoreString(LANG_RAID); + break; + case MAP_BATTLEGROUND: + ss << handler->GetAcoreString(LANG_BATTLEGROUND); + break; + case MAP_ARENA: + ss << handler->GetAcoreString(LANG_ARENA); + break; + } + + handler->SendSysMessage(ss.str().c_str()); + + ++counter; } } if (!counter) + { handler->SendSysMessage(LANG_COMMAND_NOMAPFOUND); + } return true; } - static bool HandleLookupPlayerIpCommand(ChatHandler* handler, char const* args) + static bool HandleLookupPlayerIpCommand(ChatHandler* handler, Optional ip, Optional limit) { - std::string ip; - int32 limit; - char* limitStr; - - Player* target = handler->getSelectedPlayer(); - if (!*args) + Player* target = handler->getSelectedPlayerOrSelf(); + if (!ip) { // nullptr only if used from console if (!target || target == handler->GetSession()->GetPlayer()) + { return false; + } - ip = target->GetSession()->GetRemoteAddress(); - limit = -1; + *ip = target->GetSession()->GetRemoteAddress(); } else { - ip = strtok((char*)args, " "); - limitStr = strtok(nullptr, " "); - limit = limitStr ? atoi(limitStr) : -1; + ip = *ip; } LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BY_IP); - stmt->setString(0, ip); + stmt->setStringView(0, *ip); PreparedQueryResult result = LoginDatabase.Query(stmt); - return LookupPlayerSearchCommand(result, limit, handler); + return LookupPlayerSearchCommand(result, *limit ? *limit : -1, handler); } - static bool HandleLookupPlayerAccountCommand(ChatHandler* handler, char const* args) + static bool HandleLookupPlayerAccountCommand(ChatHandler* handler, std::string account, Optional limit) { - if (!*args) - return false; - - std::string account = strtok((char*)args, " "); - char* limitStr = strtok(nullptr, " "); - int32 limit = limitStr ? atoi(limitStr) : -1; - - if (!Utf8ToUpperOnlyLatin - (account)) + if (!Utf8ToUpperOnlyLatin(account)) + { return false; + } LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_LIST_BY_NAME); stmt->setString(0, account); PreparedQueryResult result = LoginDatabase.Query(stmt); - return LookupPlayerSearchCommand(result, limit, handler); + return LookupPlayerSearchCommand(result, *limit ? *limit : -1, handler); } - static bool HandleLookupPlayerEmailCommand(ChatHandler* handler, char const* args) + static bool HandleLookupPlayerEmailCommand(ChatHandler* handler, std::string email, Optional limit) { - if (!*args) - return false; - - std::string email = strtok((char*)args, " "); - char* limitStr = strtok(nullptr, " "); - int32 limit = limitStr ? atoi(limitStr) : -1; - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL); stmt->setString(0, email); PreparedQueryResult result = LoginDatabase.Query(stmt); - return LookupPlayerSearchCommand(result, limit, handler); + return LookupPlayerSearchCommand(result, *limit ? *limit : -1, handler); } static bool LookupPlayerSearchCommand(PreparedQueryResult result, int32 limit, ChatHandler* handler) @@ -1406,9 +1587,6 @@ public: uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); - const char* name_races[RACE_DRAENEI] = {"Human", "Orc", "Dwarf", "Night Elf", "Undead", "Tauren", "Gnome", "Troll", "", "Blood Elf", "Draenei"}; - const char* name_classes[CLASS_DRUID] = {"Warrior", "Paladin", "Hunter", "Rogue", "Priest", "Death Knight", "Shaman", "Mage", "Warlock", "", "Druid"}; - do { if (maxResults && count++ == maxResults) @@ -1445,15 +1623,20 @@ public: } if (plevel > 0 && prace > 0 && prace <= RACE_DRAENEI && pclass > 0 && pclass <= CLASS_DRUID) - handler->PSendSysMessage(" %s (GUID %u) - %s - %s - %u%s", name.c_str(), guid, name_races[prace - 1], name_classes[pclass - 1], plevel, (online ? " - [ONLINE]" : "")); + { + handler->PSendSysMessage(" %s (GUID %u) - %s - %s - %u%s", name.c_str(), guid, EnumUtils::ToTitle(Races(prace)), EnumUtils::ToTitle(Classes(pclass)), plevel, (online ? " - [ONLINE]" : "")); + } else + { handler->PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER, name.c_str(), guid); + } + ++counter; } while (result2->NextRow() && (limit == -1 || counter < limit)); } } while (result->NextRow()); - if (counter == 0) // empty accounts only + if (!counter) // empty accounts only { handler->PSendSysMessage(LANG_NO_PLAYERS_FOUND); handler->SetSentErrorMessage(true); diff --git a/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp b/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp index 3bf8dd0ca..1bdaf7fb5 100644 --- a/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp +++ b/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp @@ -147,4 +147,3 @@ void AddSC_boss_baroness_anastari() { new boss_baroness_anastari; } -