bool ChatHandler::HandleLookupAreaCommand(const char* args) { if (!*args) return false; std::string namepart = args; std::wstring wnamepart; if (!Utf8toWStr (namepart, wnamepart)) return false; bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // converting string that we try to find to lower case wstrToLower (wnamepart); // Search in AreaTable.dbc for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag) { AreaTableEntry const* areaEntry = sAreaStore.LookupEntry (areaflag); if (areaEntry) { int loc = GetSessionDbcLocale (); std::string name = areaEntry->area_name[loc]; if (name.empty()) continue; if (!Utf8FitTo (name, wnamepart)) { loc = 0; for (; loc < TOTAL_LOCALES; ++loc) { if (loc == GetSessionDbcLocale ()) continue; name = areaEntry->area_name[loc]; if (name.empty ()) continue; if (Utf8FitTo (name, wnamepart)) break; } } if (loc < TOTAL_LOCALES) { if (maxResults && count++ == maxResults) { PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } // send area in "id - [name]" format std::ostringstream ss; if (m_session) ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << ' ' << localeNames[loc]<< "]|h|r"; else ss << areaEntry->ID << " - " << name << ' ' << localeNames[loc]; SendSysMessage (ss.str ().c_str()); if (!found) found = true; } } } if (!found) SendSysMessage (LANG_COMMAND_NOAREAFOUND); return true; }
void WorldSession::BuildListAuctionItems(std::vector<AuctionEntry*> const& auctions, WorldPacket& data, std::wstring const& wsearchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& count, uint32& totalcount, bool isFull) { int loc_idx = _player->GetSession()->GetSessionDbLocaleIndex(); for (std::vector<AuctionEntry*>::const_iterator itr = auctions.begin(); itr != auctions.end(); ++itr) { AuctionEntry* Aentry = *itr; if (Aentry->moneyDeliveryTime) continue; Item* item = sAuctionMgr.GetAItem(Aentry->itemGuidLow); if (!item) continue; if (isFull) { ++count; Aentry->BuildAuctionInfo(data); } else { ItemPrototype const* proto = item->GetProto(); if (itemClass != 0xffffffff && proto->Class != itemClass) continue; if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType) continue; if (quality != 0xffffffff && proto->Quality < quality) continue; if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; if (usable != 0x00) { if (_player->CanUseItem(item) != EQUIP_ERR_OK) continue; if (proto->Class == ITEM_CLASS_RECIPE) { if (SpellEntry const* spell = sSpellStore.LookupEntry(proto->Spells[0].SpellId)) { SpellEffectEntry const* spellEff = spell->GetSpellEffect(EFFECT_INDEX_0); if (!spellEff) continue; if (_player->HasSpell(spellEff->EffectTriggerSpell)) continue; } } } std::string name = proto->Name1; sObjectMgr.GetItemLocaleStrings(proto->ItemId, loc_idx, &name); if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname)) continue; if (count < 50 && totalcount >= listfrom) { ++count; Aentry->BuildAuctionInfo(data); } } ++totalcount; } }
void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player, std::wstring const& wsearchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& count, uint32& totalcount) { int loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr) { AuctionEntry *Aentry = itr->second; Item *item = sAuctionMgr.GetAItem(Aentry->itemGuidLow); if (!item) continue; { ItemPrototype const *proto = item->GetProto(); if (itemClass != 0xffffffff && proto->Class != itemClass) continue; if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType) continue; if (quality != 0xffffffff && proto->Quality < quality) continue; if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; if (usable != 0x00 && player->CanUseItem(item) != EQUIP_ERR_OK) continue; if (usable != 0x00 && proto->Class == ITEM_CLASS_RECIPE) if (SpellEntry const* spell = sSpellStore.LookupEntry(proto->Spells[0].SpellId)) if (player->HasSpell(spell->EffectTriggerSpell[EFFECT_INDEX_0])) continue; std::string name = proto->Name1; if (name.empty()) continue; // local name if (loc_idx >= 0) { ItemLocale const *il = sObjectMgr.GetItemLocale(proto->ItemId); if (il) { if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) name = il->Name[loc_idx]; } } if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname)) continue; if (count < 50 && totalcount >= listfrom) { ++count; Aentry->BuildAuctionInfo(data); } } ++totalcount; } }
void WorldSession::HandleWhoOpcode( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,4+4+1+1+4+4+4+4); sLog.outDebug( "WORLD: Recvd CMSG_WHO Message" ); //recv_data.hexlike(); uint32 clientcount = 0; uint32 level_min, level_max, racemask, classmask, zones_count, str_count; uint32 zoneids[10]; // 10 is client limit std::string player_name, guild_name; recv_data >> level_min; // maximal player level, default 0 recv_data >> level_max; // minimal player level, default 100 recv_data >> player_name; // player name, case sensitive... // recheck CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+1+4+4+4+4); recv_data >> guild_name; // guild name, case sensitive... // recheck CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+4); recv_data >> racemask; // race mask recv_data >> classmask; // class mask recv_data >> zones_count; // zones count, client limit=10 (2.0.10) if(zones_count > 10) return; // can't be received from real client or broken packet // recheck CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4); for(uint32 i = 0; i < zones_count; i++) { uint32 temp; recv_data >> temp; // zone id, 0 if zone is unknown... zoneids[i] = temp; sLog.outDebug("Zone %u: %u", i, zoneids[i]); } recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10) if(str_count > 4) return; // can't be received from real client or broken packet // recheck CHECK_PACKET_SIZE(recv_data,4+4+(player_name.size()+1)+(guild_name.size()+1)+4+4+4+(4*zones_count)+4+(1*str_count)); sLog.outDebug("Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count); std::wstring str[4]; // 4 is client limit for(uint32 i = 0; i < str_count; i++) { // recheck (have one more byte) CHECK_PACKET_SIZE(recv_data,recv_data.rpos()); std::string temp; recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)? if(!Utf8toWStr(temp,str[i])) continue; wstrToLower(str[i]); sLog.outDebug("String %u: %s", i, temp.c_str()); } std::wstring wplayer_name; std::wstring wguild_name; if(!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name))) return; wstrToLower(wplayer_name); wstrToLower(wguild_name); // client send in case not set max level value 100 but mangos support 255 max level, // update it to show GMs with characters after 100 level if(level_max >= 100) level_max = 255; uint32 team = _player->GetTeam(); uint32 security = GetSecurity(); bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST); bool gmInWhoList = sWorld.getConfig(CONFIG_GM_IN_WHO_LIST); WorldPacket data( SMSG_WHO, 50 ); // guess size data << clientcount; // clientcount place holder data << clientcount; // clientcount place holder //TODO: Guard Player map HashMapHolder<Player>::MapType& m = ObjectAccessor::Instance().GetPlayers(); for(HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr) { if (security == SEC_PLAYER) { // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST if (itr->second->GetTeam() != team && !allowTwoSideWhoList ) continue; // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST if ((itr->second->GetSession()->GetSecurity() > SEC_PLAYER && !gmInWhoList)) continue; } // check if target is globally visible for player if (!(itr->second->IsVisibleGloballyFor(_player))) continue; // check if target's level is in level range uint32 lvl = itr->second->getLevel(); if (lvl < level_min || lvl > level_max) continue; // check if class matches classmask uint32 class_ = itr->second->getClass(); if (!(classmask & (1 << class_))) continue; // check if race matches racemask uint32 race = itr->second->getRace(); if (!(racemask & (1 << race))) continue; uint32 pzoneid = itr->second->GetZoneId(); bool z_show = true; for(uint32 i = 0; i < zones_count; i++) { if(zoneids[i] == pzoneid) { z_show = true; break; } z_show = false; } if (!z_show) continue; std::string pname = itr->second->GetName(); std::wstring wpname; if(!Utf8toWStr(pname,wpname)) continue; wstrToLower(wpname); if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos)) continue; std::string gname = objmgr.GetGuildNameById(itr->second->GetGuildId()); std::wstring wgname; if(!Utf8toWStr(gname,wgname)) continue; wstrToLower(wgname); if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos)) continue; std::string aname; if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId())) aname = areaEntry->area_name[GetSessionDbcLocale()]; bool s_show = true; for(uint32 i = 0; i < str_count; i++) { if (!str[i].empty()) { if (wgname.find(str[i]) != std::wstring::npos || wpname.find(str[i]) != std::wstring::npos || Utf8FitTo(aname, str[i]) ) { s_show = true; break; } s_show = false; } } if (!s_show) continue; data << pname; // player name data << gname; // guild name data << uint32( lvl ); // player level data << uint32( class_ ); // player class data << uint32( race ); // player race data << uint8(0); // new 2.4.0 data << uint32( pzoneid ); // player zone id // 49 is maximum player count sent to client if ((++clientcount) == 49) break; } data.put( 0, clientcount ); //insert right count data.put( sizeof(uint32), clientcount ); //insert right count SendPacket(&data); sLog.outDebug( "WORLD: Send SMSG_WHO Message" ); }
void WorldSession::BuildListAuctionItems(std::list<AuctionEntry*> &auctions, WorldPacket& data, std::wstring const& wsearchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& count, uint32& totalcount, bool isFull) { int loc_idx = _player->GetSession()->GetSessionDbLocaleIndex(); for (std::list<AuctionEntry*>::const_iterator itr = auctions.begin(); itr != auctions.end();++itr) { AuctionEntry *Aentry = *itr; if (Aentry->moneyDeliveryTime) continue; Item *item = sAuctionMgr.GetAItem(Aentry->itemGuidLow); if (!item) continue; if (isFull) { ++count; Aentry->BuildAuctionInfo(data); } else { ItemPrototype const *proto = item->GetProto(); if (itemClass != 0xffffffff && proto->Class != itemClass) continue; if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType) continue; if (quality != 0xffffffff && proto->Quality < quality) continue; if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; if (usable != 0x00 && _player->CanUseItem(item) != EQUIP_ERR_OK) continue; std::string name = proto->Name1; if (name.empty()) continue; // local name if (loc_idx >= 0) { ItemLocale const *il = sObjectMgr.GetItemLocale(proto->ItemId); if (il) { if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) name = il->Name[loc_idx]; } } if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname)) continue; if (count < 50 && totalcount >= listfrom) { ++count; Aentry->BuildAuctionInfo(data); } } ++totalcount; } }
static bool HandleLookupSpellCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // can be NULL 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); bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in Spell.dbc for (uint32 id = 0; id < sSpellMgr->GetSpellInfoStoreSize(); id++) { SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id); if (spellInfo) { std::string name = spellInfo->SpellName; if (name.empty()) continue; if (!Utf8FitTo(name, wNamePart)) continue; if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); 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; if (handler->GetSession()) ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; else ss << id << " - " << name; // include rank in link name if (rank) ss << handler->GetTrinityString(LANG_SPELL_RANK) << rank; if (handler->GetSession()) ss << "]|h|r"; if (talent) ss << handler->GetTrinityString(LANG_TALENT); if (passive) ss << handler->GetTrinityString(LANG_PASSIVE); if (learn) ss << handler->GetTrinityString(LANG_LEARN); if (known) ss << handler->GetTrinityString(LANG_KNOWN); if (active) ss << handler->GetTrinityString(LANG_ACTIVE); handler->SendSysMessage(ss.str().c_str()); if (!found) found = true; } } if (!found) handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); return true; }
static bool HandleLookupObjectCommand(ChatHandler* handler, char const* args) { 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); bool found = false; 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) { uint8 localeIndex = handler->GetSessionDbLocaleIndex(); if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(itr->second.entry)) { if (objectLocalte->Name.size() > localeIndex && !objectLocalte->Name[localeIndex].empty()) { std::string name = objectLocalte->Name[localeIndex]; if (Utf8FitTo(name, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } if (handler->GetSession()) handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str()); else handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str()); if (!found) found = true; continue; } } } std::string name = itr->second.name; if (name.empty()) continue; if (Utf8FitTo(name, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } if (handler->GetSession()) handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str()); else handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str()); if (!found) found = true; } } if (!found) handler->SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND); return true; }
void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player, std::wstring const& wsearchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& count, uint32& totalcount) { int loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); int locdbc_idx = player->GetSession()->GetSessionDbcLocale(); for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) { AuctionEntry *Aentry = itr->second; Item *item = sAuctionMgr->GetAItem(Aentry->item_guidlow); if (!item) continue; ItemPrototype const *proto = item->GetProto(); if (itemClass != 0xffffffff && proto->Class != itemClass) continue; if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType) continue; if (quality != 0xffffffff && proto->Quality != quality) continue; if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; if (usable != 0x00 && player->CanUseItem(item) != EQUIP_ERR_OK) continue; // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey) // No need to do any of this if no search term was entered if (!wsearchedname.empty()) { std::string name = proto->Name1; if (name.empty()) continue; // local name if (loc_idx >= 0) if (ItemLocale const *il = sObjectMgr->GetItemLocale(proto->ItemId)) sObjectMgr->GetLocaleString(il->Name, loc_idx, name); // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result // that matches the search but it may not equal item->GetItemRandomPropertyId() // used in BuildAuctionInfo() which then causes wrong items to be listed int32 propRefID = item->GetItemRandomPropertyId(); if (propRefID) { // Append the suffix to the name (ie: of the Monkey) if one exists // These are found in ItemRandomProperties.dbc, not ItemRandomSuffix.dbc // even though the DBC names seem misleading const ItemRandomPropertiesEntry *itemRandProp = sItemRandomPropertiesStore.LookupEntry(propRefID); if (itemRandProp) { char* const* temp = itemRandProp->nameSuffix; //char* temp = itemRandProp->nameSuffix; // dbc local name if (temp) { if (locdbc_idx >= 0) { // Append the suffix (ie: of the Monkey) to the name using localization name += " "; name += temp[locdbc_idx]; } else { // Invalid localization? Append the suffix using default enUS name += " "; name += temp[LOCALE_enUS]; } } } } // Perform the search (with or without suffix) if (!Utf8FitTo(name, wsearchedname)) continue; } // Add the item if no search term or if entered search term was found if (count < 50 && totalcount >= listfrom) { ++count; Aentry->BuildAuctionInfo(data); } ++totalcount; } }
static bool HandleLookupFactionCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // Can be NULL 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); bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); for (uint32 id = 0; id < sFactionStore.GetNumRows(); ++id) { if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(id)) { FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL; std::string name = factionEntry->name; if (name.empty()) continue; if (!Utf8FitTo(name, wNamePart)) continue; 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 << id << " - |cffffffff|Hfaction:" << id << "|h[" << name << "]|h|r"; else ss << id << " - " << name; if (factionState) // and then target != NULL also { uint32 index = target->GetReputationMgr().GetReputationRankStrIndex(factionEntry); std::string rankName = handler->GetTrinityString(index); ss << ' ' << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ')'; if (factionState->Flags & FACTION_FLAG_VISIBLE) ss << handler->GetTrinityString(LANG_FACTION_VISIBLE); if (factionState->Flags & FACTION_FLAG_AT_WAR) ss << handler->GetTrinityString(LANG_FACTION_ATWAR); if (factionState->Flags & FACTION_FLAG_PEACE_FORCED) ss << handler->GetTrinityString(LANG_FACTION_PEACE_FORCED); if (factionState->Flags & FACTION_FLAG_HIDDEN) ss << handler->GetTrinityString(LANG_FACTION_HIDDEN); if (factionState->Flags & FACTION_FLAG_INVISIBLE_FORCED) ss << handler->GetTrinityString(LANG_FACTION_INVISIBLE_FORCED); if (factionState->Flags & FACTION_FLAG_INACTIVE) ss << handler->GetTrinityString(LANG_FACTION_INACTIVE); } else ss << handler->GetTrinityString(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) { 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); bool found = false; uint32 count = 0; 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) { int localeIndex = handler->GetSessionDbLocaleIndex(); if (localeIndex >= 0) { uint8 ulocaleIndex = uint8(localeIndex); if (ItemLocale const* il = sObjectMgr->GetItemLocale(itr->second.ItemId)) { if (il->Name.size() > ulocaleIndex && !il->Name[ulocaleIndex].empty()) { std::string name = il->Name[ulocaleIndex]; if (Utf8FitTo(name, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } if (handler->GetSession()) handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str()); else handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str()); if (!found) found = true; continue; } } } } std::string name = itr->second.Name1; if (name.empty()) continue; if (Utf8FitTo(name, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } if (handler->GetSession()) handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str()); else handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str()); if (!found) found = true; } } if (!found) handler->SendSysMessage(LANG_COMMAND_NOITEMFOUND); return true; }
static bool HandleLookupMapCommand(ChatHandler* handler, char const* args) { if (!*args) return false; std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) return false; wstrToLower(wNamePart); uint32 counter = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); uint8 locale = handler->GetSession() ? handler->GetSession()->GetSessionDbcLocale() : sWorld->GetDefaultDbcLocale(); // search in Map.dbc for (uint32 id = 0; id < sMapStore.GetNumRows(); id++) { if (MapEntry const* mapInfo = sMapStore.LookupEntry(id)) { std::string name = mapInfo->name; if (name.empty()) continue; if (Utf8FitTo(name, wNamePart) && locale < TOTAL_LOCALES) { 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->GetTrinityString(LANG_CONTINENT); switch (mapInfo->map_type) { case MAP_INSTANCE: ss << handler->GetTrinityString(LANG_INSTANCE); break; case MAP_RAID: ss << handler->GetTrinityString(LANG_RAID); break; case MAP_BATTLEGROUND: ss << handler->GetTrinityString(LANG_BATTLEGROUND); break; case MAP_ARENA: ss << handler->GetTrinityString(LANG_ARENA); break; } handler->SendSysMessage(ss.str().c_str()); ++counter; } } } if (!counter) handler->SendSysMessage(LANG_COMMAND_NOMAPFOUND); return true; }
//this void is called when player clicks on search button void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1); std::string searchedname, name; uint8 levelmin, levelmax, usable, location; uint32 count, totalcount, listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality; uint64 guid; recv_data >> guid; recv_data >> listfrom; // start, used for page control listing by 50 elements recv_data >> searchedname; // recheck with known string size CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1); recv_data >> levelmin >> levelmax; recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory; recv_data >> quality >> usable; Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER); if (!pCreature) { sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); location = AuctioneerFactionToLocation(pCreature->getFaction()); AuctionHouseObject * mAuctions; mAuctions = objmgr.GetAuctionsMap( location ); //sLog.outDebug("Auctionhouse search guid: " I64FMTD ", list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", guid, listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable); WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) ); count = 0; totalcount = 0; data << (uint32) 0; // converting string that we try to find to lower case std::wstring wsearchedname; if(!Utf8toWStr(searchedname,wsearchedname)) return; wstrToLower(wsearchedname); for (AuctionHouseObject::AuctionEntryMap::iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr) { AuctionEntry *Aentry = itr->second; Item *item = objmgr.GetAItem(Aentry->item_guidlow); if( item ) { ItemPrototype const *proto = item->GetProto(); if( proto ) { if( auctionMainCategory == (0xffffffff) || proto->Class == auctionMainCategory ) { if( auctionSubCategory == (0xffffffff) || proto->SubClass == auctionSubCategory ) { if( auctionSlotID == (0xffffffff) || proto->InventoryType == auctionSlotID ) { if( quality == (0xffffffff) || proto->Quality == quality ) { if( usable == (0x00) || _player->CanUseItem( item ) == EQUIP_ERR_OK ) { if( ( levelmin == (0x00) || proto->RequiredLevel >= levelmin ) && ( levelmax == (0x00) || proto->RequiredLevel <= levelmax ) ) { name = proto->Name1; // local name int loc_idx = GetSessionDbLocaleIndex(); if ( loc_idx >= 0 ) { ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId); if (il) { if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) name = il->Name[loc_idx]; } } if(name.empty()) continue; if( wsearchedname.empty() || Utf8FitTo(name, wsearchedname) ) { if ((count < 50) && (totalcount >= listfrom)) { ++count; SendAuctionInfo( data, Aentry); } ++totalcount; } } } } } } } } } } data.put<uint32>(0, count); data << (uint32) totalcount; data << (uint32) 300; // unk 2.3.0 const? SendPacket(&data); }
void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player, std::wstring const& wsearchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& count, uint32& totalcount, bool getall) { int loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); int locdbc_idx = player->GetSession()->GetSessionDbcLocale(); time_t curTime = GameTime::GetGameTime(); PlayerGetAllThrottleMap::const_iterator itr = GetAllThrottleMap.find(player->GetGUID()); time_t throttleTime = itr != GetAllThrottleMap.end() ? itr->second : curTime; if (getall && throttleTime <= curTime) { for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) { AuctionEntry* Aentry = itr->second; // Skip expired auctions if (Aentry->expire_time < curTime) continue; Item* item = sAuctionMgr->GetAItem(Aentry->itemGUIDLow); if (!item) continue; ++count; ++totalcount; Aentry->BuildAuctionInfo(data, item); if (count >= MAX_GETALL_RETURN) break; } GetAllThrottleMap[player->GetGUID()] = curTime + sWorld->getIntConfig(CONFIG_AUCTION_GETALL_DELAY); return; } for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) { AuctionEntry* Aentry = itr->second; // Skip expired auctions if (Aentry->expire_time < curTime) continue; Item* item = sAuctionMgr->GetAItem(Aentry->itemGUIDLow); if (!item) continue; ItemTemplate const* proto = item->GetTemplate(); if (itemClass != 0xffffffff && proto->Class != itemClass) continue; if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType) continue; if (quality != 0xffffffff && proto->Quality != quality) continue; if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) continue; if (usable != 0x00 && player->CanUseItem(item) != EQUIP_ERR_OK) continue; // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey) // No need to do any of this if no search term was entered if (!wsearchedname.empty()) { std::string name = proto->Name1; if (name.empty()) continue; // local name if (loc_idx >= 0) if (ItemLocale const* il = sObjectMgr->GetItemLocale(proto->ItemId)) ObjectMgr::GetLocaleString(il->Name, loc_idx, name); // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result // that matches the search but it may not equal item->GetItemRandomPropertyId() // used in BuildAuctionInfo() which then causes wrong items to be listed int32 propRefID = item->GetItemRandomPropertyId(); if (propRefID) { // Append the suffix to the name (ie: of the Monkey) if one exists // These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc // even though the DBC names seem misleading char* const* suffix = nullptr; if (propRefID < 0) { const ItemRandomSuffixEntry* itemRandSuffix = sItemRandomSuffixStore.LookupEntry(-propRefID); if (itemRandSuffix) suffix = itemRandSuffix->nameSuffix; } else { const ItemRandomPropertiesEntry* itemRandProp = sItemRandomPropertiesStore.LookupEntry(propRefID); if (itemRandProp) suffix = itemRandProp->nameSuffix; } // dbc local name if (suffix) { // Append the suffix (ie: of the Monkey) to the name using localization // or default enUS if localization is invalid name += ' '; name += suffix[locdbc_idx >= 0 ? locdbc_idx : LOCALE_enUS]; } } // Perform the search (with or without suffix) if (!Utf8FitTo(name, wsearchedname)) continue; } // Add the item if no search term or if entered search term was found if (count < 50 && totalcount >= listfrom) { ++count; Aentry->BuildAuctionInfo(data, item); } ++totalcount; } }
void WorldSession::HandleWhoOpcode(WorldPacket& recv_data) { DEBUG_LOG("WORLD: Received opcode CMSG_WHO"); // recv_data.hexlike(); uint32 clientcount = 0; uint32 level_min, level_max, racemask, classmask, zones_count, str_count; uint32 zoneids[10]; // 10 is client limit std::string player_name, guild_name; recv_data >> level_min; // maximal player level, default 0 recv_data >> level_max; // minimal player level, default 100 (MAX_LEVEL) recv_data >> player_name; // player name, case sensitive... recv_data >> guild_name; // guild name, case sensitive... recv_data >> racemask; // race mask recv_data >> classmask; // class mask recv_data >> zones_count; // zones count, client limit=10 (2.0.10) if (zones_count > 10) return; // can't be received from real client or broken packet for (uint32 i = 0; i < zones_count; ++i) { uint32 temp; recv_data >> temp; // zone id, 0 if zone is unknown... zoneids[i] = temp; DEBUG_LOG("Zone %u: %u", i, zoneids[i]); } recv_data >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10) if (str_count > 4) return; // can't be received from real client or broken packet DEBUG_LOG("Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count); std::wstring str[4]; // 4 is client limit for (uint32 i = 0; i < str_count; ++i) { std::string temp; recv_data >> temp; // user entered string, it used as universal search pattern(guild+player name)? if (!Utf8toWStr(temp, str[i])) continue; wstrToLower(str[i]); DEBUG_LOG("String %u: %s", i, temp.c_str()); } std::wstring wplayer_name; std::wstring wguild_name; if (!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name))) return; wstrToLower(wplayer_name); wstrToLower(wguild_name); // client send in case not set max level value 100 but mangos support 255 max level, // update it to show GMs with characters after 100 level if (level_max >= MAX_LEVEL) level_max = STRONG_MAX_LEVEL; Team team = _player->GetTeam(); uint32 security = GetSecurity(); bool allowTwoSideWhoList = sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST); AccountTypes gmLevelInWhoList = (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_WHO_LIST); WorldPacket data(SMSG_WHO, 50); // guess size data << uint32(clientcount); // clientcount place holder, listed count data << uint32(clientcount); // clientcount place holder, online count // TODO: Guard Player map HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { Player* pl = itr->second; if (security == SEC_PLAYER) { // player can see member of other team only if CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST if (pl->GetTeam() != team && !allowTwoSideWhoList) continue; // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST if (pl->GetSession()->GetSecurity() > gmLevelInWhoList) continue; } // do not process players which are not in world if (!pl->IsInWorld()) continue; // check if target is globally visible for player if (!pl->IsVisibleGloballyFor(_player)) continue; // check if target's level is in level range uint32 lvl = pl->getLevel(); if (lvl < level_min || lvl > level_max) continue; // check if class matches classmask uint32 class_ = pl->getClass(); if (!(classmask & (1 << class_))) continue; // check if race matches racemask uint32 race = pl->getRace(); if (!(racemask & (1 << race))) continue; uint32 pzoneid = pl->GetZoneId(); uint8 gender = pl->getGender(); bool z_show = true; for (uint32 i = 0; i < zones_count; ++i) { if (zoneids[i] == pzoneid) { z_show = true; break; } z_show = false; } if (!z_show) continue; std::string pname = pl->GetName(); std::wstring wpname; if (!Utf8toWStr(pname, wpname)) continue; wstrToLower(wpname); if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos)) continue; std::string gname = sGuildMgr.GetGuildNameById(pl->GetGuildId()); std::wstring wgname; if (!Utf8toWStr(gname, wgname)) continue; wstrToLower(wgname); if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos)) continue; std::string aname; if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid)) aname = areaEntry->area_name[GetSessionDbcLocale()]; bool s_show = true; for (uint32 i = 0; i < str_count; ++i) { if (!str[i].empty()) { if (wgname.find(str[i]) != std::wstring::npos || wpname.find(str[i]) != std::wstring::npos || Utf8FitTo(aname, str[i])) { s_show = true; break; } s_show = false; } } if (!s_show) continue; data << pname; // player name data << gname; // guild name data << uint32(lvl); // player level data << uint32(class_); // player class data << uint32(race); // player race data << uint8(gender); // player gender data << uint32(pzoneid); // player zone id // 50 is maximum player count sent to client if ((++clientcount) == 50) break; } uint32 count = m.size(); data.put(0, clientcount); // insert right count, listed count data.put(4, count > 50 ? count : clientcount); // insert right count, online count SendPacket(&data); DEBUG_LOG("WORLD: Send SMSG_WHO Message"); }
static bool HandleLookupQuestCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // can be NULL 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); bool found = false; 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) { Quest* qInfo = iter->second; int localeIndex = handler->GetSessionDbLocaleIndex(); if (localeIndex >= 0) { uint8 ulocaleIndex = uint8(localeIndex); if (QuestLocale const* questLocale = sObjectMgr->GetQuestLocale(qInfo->GetQuestId())) { if (questLocale->Title.size() > ulocaleIndex && !questLocale->Title[ulocaleIndex].empty()) { std::string title = questLocale->Title[ulocaleIndex]; if (Utf8FitTo(title, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } char const* statusStr = ""; if (target) { QuestStatus status = target->GetQuestStatus(qInfo->GetQuestId()); switch (status) { case QUEST_STATUS_COMPLETE: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); break; case QUEST_STATUS_INCOMPLETE: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); break; case QUEST_STATUS_REWARDED: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_REWARDED); break; default: break; } } 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; } } } } std::string title = qInfo->GetTitle(); if (title.empty()) continue; if (Utf8FitTo(title, wNamePart)) { if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } char const* statusStr = ""; if (target) { QuestStatus status = target->GetQuestStatus(qInfo->GetQuestId()); switch (status) { case QUEST_STATUS_COMPLETE: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); break; case QUEST_STATUS_INCOMPLETE: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); break; case QUEST_STATUS_REWARDED: statusStr = handler->GetTrinityString(LANG_COMMAND_QUEST_REWARDED); break; default: break; } } 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 HandleLearnAllRecipesCommand(ChatHandler* handler, char const* args) { // Learns all recipes of specified profession and sets skill to max // Example: .learn all_recipes enchanting Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_PLAYER_NOT_FOUND); return false; } if (!*args) return false; std::wstring namePart; if (!Utf8toWStr(args, namePart)) return false; // converting string that we try to find to lower case wstrToLower(namePart); std::string name; SkillLineEntry const* targetSkillInfo = NULL; for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i) { SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i); if (!skillInfo) continue; if ((skillInfo->categoryId != SKILL_CATEGORY_PROFESSION && skillInfo->categoryId != SKILL_CATEGORY_SECONDARY) || !skillInfo->canLink) // only prof with recipes have set continue; int loc = handler->GetSessionDbcLocale(); name = skillInfo->name[loc]; if (name.empty()) continue; if (!Utf8FitTo(name, namePart)) { loc = 0; for (; loc < TOTAL_LOCALES; ++loc) { if (loc == handler->GetSessionDbcLocale()) continue; name = skillInfo->name[loc]; if (name.empty()) continue; if (Utf8FitTo(name, namePart)) break; } } if (loc < TOTAL_LOCALES) { targetSkillInfo = skillInfo; break; } } if (!targetSkillInfo) return false; HandleLearnSkillRecipesHelper(target, targetSkillInfo->id); uint16 maxLevel = target->GetPureMaxSkillValue(targetSkillInfo->id); target->SetSkill(targetSkillInfo->id, target->GetSkillStep(targetSkillInfo->id), maxLevel, maxLevel); handler->PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, name.c_str()); return true; }
static bool HandleLookupSkillCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // can be NULL 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); bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in SkillLine.dbc for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++) { SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id); if (skillInfo) { std::string name = skillInfo->name; if (name.empty()) continue; if (!Utf8FitTo(name, wNamePart)) continue; if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } char valStr[50] = ""; char const* knownStr = ""; if (target && target->HasSkill(id)) { knownStr = handler->GetTrinityString(LANG_KNOWN); uint32 curValue = target->GetPureSkillValue(id); uint32 maxValue = target->GetPureMaxSkillValue(id); uint32 permValue = target->GetSkillPermBonusValue(id); uint32 tempValue = target->GetSkillTempBonusValue(id); char const* valFormat = handler->GetTrinityString(LANG_SKILL_VALUES); snprintf(valStr, 50, valFormat, curValue, maxValue, permValue, tempValue); } // send skill in "id - [namedlink locale]" format if (handler->GetSession()) handler->PSendSysMessage(LANG_SKILL_LIST_CHAT, id, id, name.c_str(), "", knownStr, valStr); else handler->PSendSysMessage(LANG_SKILL_LIST_CONSOLE, id, name.c_str(), "", knownStr, valStr); if (!found) found = true; } } if (!found) handler->SendSysMessage(LANG_COMMAND_NOSKILLFOUND); return true; }
bool ChatHandler::HandleLookupTitleCommand(const char* args) { if (!*args) return false; // can be NULL in console call Player* target = getSelectedPlayer(); // title name have single string arg for player name char const* targetName = target ? target->GetName() : "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); uint32 counter = 0; // Counter for figure out that we found smth. uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in CharTitles.dbc for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++) { CharTitlesEntry const *titleInfo = sCharTitlesStore.LookupEntry(id); if (titleInfo) { int loc = GetSessionDbcLocale(); std::string name = titleInfo->name[loc]; if (name.empty()) continue; if (!Utf8FitTo(name, wnamepart)) { loc = 0; for (; loc < TOTAL_LOCALES; ++loc) { if (loc == GetSessionDbcLocale()) continue; name = titleInfo->name[loc]; if (name.empty()) continue; if (Utf8FitTo(name, wnamepart)) break; } } if (loc < TOTAL_LOCALES) { if (maxResults && counter == maxResults) { PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } char const* knownStr = target && target->HasTitle(titleInfo) ? GetTrinityString(LANG_KNOWN) : ""; char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index ? GetTrinityString(LANG_ACTIVE) : ""; char titleNameStr[80]; snprintf(titleNameStr, 80, name.c_str(), targetName); // send title in "id (idx:idx) - [namedlink locale]" format if (m_session) PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr); else PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr); ++counter; } } } if (counter == 0) // if counter == 0 then we found nth SendSysMessage(LANG_COMMAND_NOTITLEFOUND); return true; }
void AuctionHouseObject::BuildListAuctionItems(WorldPackets::AuctionHouse::AuctionListItemsResult& packet, Player* player, std::wstring const& wsearchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& totalcount) { time_t curTime = sWorld->GetGameTime(); for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) { AuctionEntry* Aentry = itr->second; // Skip expired auctions if (Aentry->expire_time < curTime) continue; Item* item = sAuctionMgr->GetAItem(Aentry->itemGUIDLow); if (!item) continue; ItemTemplate const* proto = item->GetTemplate(); if (itemClass != 0xffffffff && proto->GetClass() != itemClass) continue; if (itemSubClass != 0xffffffff && proto->GetSubClass() != itemSubClass) continue; if (inventoryType != 0xffffffff && proto->GetInventoryType() != InventoryType(inventoryType)) continue; if (quality != 0xffffffff && proto->GetQuality() != quality) continue; if (levelmin != 0 && (proto->GetBaseRequiredLevel() < levelmin || (levelmax != 0 && proto->GetBaseRequiredLevel() > levelmax))) continue; if (usable != 0 && player->CanUseItem(item) != EQUIP_ERR_OK) continue; // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey) // No need to do any of this if no search term was entered if (!wsearchedname.empty()) { std::string name = proto->GetName(player->GetSession()->GetSessionDbcLocale()); if (name.empty()) continue; // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result // that matches the search but it may not equal item->GetItemRandomPropertyId() // used in BuildAuctionInfo() which then causes wrong items to be listed int32 propRefID = item->GetItemRandomPropertyId(); if (propRefID) { // Append the suffix to the name (ie: of the Monkey) if one exists // These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc // even though the DBC names seem misleading const char* suffix = nullptr; if (propRefID < 0) { const ItemRandomSuffixEntry* itemRandSuffix = sItemRandomSuffixStore.LookupEntry(-propRefID); if (itemRandSuffix) suffix = itemRandSuffix->Name_lang; } else { const ItemRandomPropertiesEntry* itemRandProp = sItemRandomPropertiesStore.LookupEntry(propRefID); if (itemRandProp) suffix = itemRandProp->Name_lang; } // dbc local name if (suffix) { // Append the suffix (ie: of the Monkey) to the name using localization // or default enUS if localization is invalid name += ' '; name += suffix; } } // Perform the search (with or without suffix) if (!Utf8FitTo(name, wsearchedname)) continue; } // Add the item if no search term or if entered search term was found if (packet.Items.size() < 50 && totalcount >= listfrom) Aentry->BuildAuctionInfo(packet.Items, true); ++totalcount; } }