diff --git a/src/game/Group/Group.cpp b/src/game/Group/Group.cpp index ae1de2976..1b2a4a812 100644 --- a/src/game/Group/Group.cpp +++ b/src/game/Group/Group.cpp @@ -948,8 +948,8 @@ bool Group::CountRollVote(ObjectGuid const& playerGUID, Rolls::iterator& rollI, if (itr == roll->playerVote.end()) return true; // result used for need iterator ++, so avoid for end of list - if (roll->getLoot()) - if (roll->getLoot()->items.empty()) + if (Loot* pLoot = roll->getLoot()) + if (pLoot->items.empty()) return false; switch (vote) diff --git a/src/game/Handlers/ItemHandler.cpp b/src/game/Handlers/ItemHandler.cpp index e984b410e..efd81eb11 100644 --- a/src/game/Handlers/ItemHandler.cpp +++ b/src/game/Handlers/ItemHandler.cpp @@ -289,8 +289,8 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket& recv_data) ItemPrototype const* pProto = sObjectMgr.GetItemPrototype(item); if (pProto && (pProto->Discovered || (GetSecurity() > SEC_PLAYER))) { - std::string Name = pProto->Name1; - std::string Description = pProto->Description; + char const* name = pProto->Name1; + char const* description = pProto->Description; int loc_idx = GetSessionDbLocaleIndex(); if (loc_idx >= 0) @@ -299,9 +299,9 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket& recv_data) if (il) { if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) - Name = il->Name[loc_idx]; + name = il->Name[loc_idx].c_str(); if (il->Description.size() > size_t(loc_idx) && !il->Description[loc_idx].empty()) - Description = il->Description[loc_idx]; + description = il->Description[loc_idx].c_str(); } } // guess size @@ -310,7 +310,7 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket& recv_data) data << pProto->Class; // client known only 0 subclass (and 1-2 obsolute subclasses) data << (pProto->Class == ITEM_CLASS_CONSUMABLE ? uint32(0) : pProto->SubClass); - data << Name; // max length of any of 4 names: 256 bytes + data << name; // max length of any of 4 names: 256 bytes data << uint8(0x00); //pProto->Name2; // blizz not send name there, just uint8(0x00); <-- \0 = empty string = empty name... data << uint8(0x00); //pProto->Name3; // blizz not send name there, just uint8(0x00); data << uint8(0x00); //pProto->Name4; // blizz not send name there, just uint8(0x00); @@ -407,7 +407,7 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket& recv_data) } } data << pProto->Bonding; - data << Description; + data << description; data << pProto->PageText; data << pProto->LanguageID; data << pProto->PageMaterial; diff --git a/src/game/Handlers/LootHandler.cpp b/src/game/Handlers/LootHandler.cpp index 209767178..060231e16 100644 --- a/src/game/Handlers/LootHandler.cpp +++ b/src/game/Handlers/LootHandler.cpp @@ -200,7 +200,7 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recv_data*/) if (!guid) return; - Loot *pLoot = nullptr; + Loot* pLoot = nullptr; Item* pItem = nullptr; bool shareMoneyWithGroup = true; @@ -261,24 +261,25 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recv_data*/) Group* group = player->GetGroup(); std::vector playersNear; + playersNear.reserve(group->GetMembersCount()); for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) { Player* playerGroup = itr->getSource(); if (!playerGroup) continue; - //if (player->IsWithinDistInMap(playerGroup, sWorld.getConfig(CONFIG_FLOAT_GROUP_XP_DISTANCE), false)) + if (player->IsWithinLootXPDist(playerGroup)) playersNear.push_back(playerGroup); } - uint32 money_per_player = uint32((pLoot->gold) / (playersNear.size())); + uint32 moneyPerPlayer = uint32((pLoot->gold) / (playersNear.size())); for (const auto i : playersNear) { - i->LootMoney(money_per_player, pLoot); - //Offset surely incorrect, but works + i->LootMoney(moneyPerPlayer, pLoot); + WorldPacket data(SMSG_LOOT_MONEY_NOTIFY, 4); - data << uint32(money_per_player); + data << uint32(moneyPerPlayer); i->GetSession()->SendPacket(&data); } } diff --git a/src/game/Handlers/MailHandler.cpp b/src/game/Handlers/MailHandler.cpp index fa9d5e90a..7ed7bf51d 100644 --- a/src/game/Handlers/MailHandler.cpp +++ b/src/game/Handlers/MailHandler.cpp @@ -743,15 +743,36 @@ void WorldSession::HandleGetMailList(WorldPacket& recv_data) MasterPlayer* pl = GetMasterPlayer(); ASSERT(pl); - // client can't work with packets > max int16 value - // uint32 const maxPacketSize = 32767; + constexpr uint32 averageSizePerMail = + sizeof(uint32) /*Message Id*/ + + sizeof(uint8) /*Message Type*/ + + sizeof(uint64) /*Sender Guid*/ + + 32 /*Subject (max 64)*/ + + sizeof(uint32) /*Item Text Id*/ + + sizeof(uint32) /*Unknown*/ + + sizeof(uint32) /*Stationery*/ + + sizeof(uint32) /*Item Entry*/ + + sizeof(uint32) /*Item Enchantment Id*/ + + sizeof(uint32) /*Item Random Property Id*/ + + sizeof(uint32) /*Item Suffix Factor*/ + + sizeof(uint8) /*Item Count*/ + + sizeof(uint32) /*Item Spell Charges*/ + + sizeof(uint32) /*Item Max Durability*/ + + sizeof(uint32) /*Item Durability*/ + + sizeof(uint32) /*Money*/ + + sizeof(uint32) /*Cod*/ + + sizeof(uint32) /*Checked*/ + + sizeof(float) /*Expire Time*/ +#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_9_4 + + sizeof(uint32) /*Mail Template Id*/ +#endif + ; - uint32 mailsCount = 0; // real send to client mails amount - - WorldPacket data(SMSG_MAIL_LIST_RESULT, (200)); // guess size + WorldPacket data(SMSG_MAIL_LIST_RESULT, 1 + std::min(pl->GetMailSize(), 253u) * averageSizePerMail); data << uint8(0); // mail's count time_t cur_time = time(nullptr); + uint32 mailsCount = 0; // real send to client mails amount for (PlayerMails::iterator itr = pl->GetMailBegin(); itr != pl->GetMailEnd(); ++itr) { // packet send mail count as uint8, prevent overflow @@ -762,13 +783,6 @@ void WorldSession::HandleGetMailList(WorldPacket& recv_data) if ((*itr)->state == MAIL_STATE_DELETED || cur_time < (*itr)->deliver_time || cur_time > (*itr)->expire_time) continue; - /*[-ZERO] TODO recheck this - size_t next_mail_size = 4+1+8+((*itr)->subject.size()+1)+4*7+1+item_count*(1+4+4+6*3*4+4+4+1+4+4+4); - - if (data.wpos()+next_mail_size > maxPacketSize) - break; - */ - data << uint32((*itr)->messageID); // Message ID data << uint8((*itr)->messageType); // Message Type diff --git a/src/game/Handlers/MovementHandler.cpp b/src/game/Handlers/MovementHandler.cpp index d72b89518..4a233a63f 100644 --- a/src/game/Handlers/MovementHandler.cpp +++ b/src/game/Handlers/MovementHandler.cpp @@ -840,10 +840,7 @@ void WorldSession::HandleMoveSplineDoneOpcode(WorldPacket& recvData) if (pMover->HasPendingSplineDone()) pMover->SetSplineDonePending(false); else - { - sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "HandleMoveSplineDoneOpcode: client sent unexpected spline done for %s", pMover->GetGuidStr().c_str()); return; - } if (Player* pPlayerMover = pMover->ToPlayer()) { diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index 31daaf75d..cef82fb2b 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -1364,7 +1364,10 @@ void Object::ExecuteDelayedActions() bool WorldObject::IsWithinLootXPDist(WorldObject const* objToLoot) const { - if (objToLoot && IsInMap(objToLoot) && objToLoot->GetMap()->IsRaid()) + if (!IsInMap(objToLoot)) + return false; + + if (objToLoot->GetMap()->IsRaid()) return true; // Bosses have increased loot distance. @@ -1372,7 +1375,7 @@ bool WorldObject::IsWithinLootXPDist(WorldObject const* objToLoot) const if (objToLoot->IsCreature() && (static_cast(objToLoot)->GetCreatureInfo()->rank == CREATURE_ELITE_WORLDBOSS)) lootDistance += 150.0f; - return objToLoot && IsInMap(objToLoot) && _IsWithinDist(objToLoot, lootDistance, false); + return _IsWithinDist(objToLoot, lootDistance, false); } float WorldObject::GetVisibilityModifier() const @@ -1579,7 +1582,7 @@ bool WorldObject::IsWithinDist2d(float x, float y, float dist2compare, SizeFacto bool WorldObject::IsInMap(WorldObject const* obj) const { - return IsInWorld() && obj->IsInWorld() && (GetMap() == obj->GetMap()); + return IsInWorld() && obj->IsInWorld() && (FindMap() == obj->FindMap()); } bool WorldObject::_IsWithinDist(WorldObject const* obj, float const dist2compare, const bool is3D, SizeFactor distcalc) const diff --git a/src/game/Objects/Player.cpp b/src/game/Objects/Player.cpp index f220730c9..66f559ba0 100644 --- a/src/game/Objects/Player.cpp +++ b/src/game/Objects/Player.cpp @@ -2855,7 +2855,7 @@ Creature* Player::FindNearestInteractableNpcWithFlag(uint32 npcFlags) const Creature* Player::GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask) const { // some basic checks - if (!guid || !IsInWorld() || IsTaxiFlying()) + if (!guid || !IsInWorld()) return nullptr; // exist (we need look pets also for some interaction (quest/etc) @@ -2929,7 +2929,7 @@ bool Player::CanInteractWithNPC(Creature const* pCreature, uint32 npcflagmask) c GameObject* Player::GetGameObjectIfCanInteractWith(ObjectGuid guid, uint32 gameobject_type) const { // some basic checks - if (!guid || !IsInWorld() || IsTaxiFlying()) + if (!guid || !IsInWorld()) return nullptr; GameObject* pGo = GetMap()->GetGameObject(guid); @@ -2956,9 +2956,6 @@ bool Player::CanInteractWithGameObject(GameObject const* pGo, uint32 gameobject_ { if (pGo->IsAtInteractDistance(this) && pGo->isSpawned()) return true; - - sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "CanInteractWithGameObject: GameObject '%s' [GUID: %u] is too far away from player %s [GUID: %u] to be used by him", - pGo->GetGOInfo()->name, pGo->GetGUIDLow(), GetName(), GetGUIDLow()); } return false;