Few small optimizations here and there
This commit is contained in:
1 parent
0f9c7106ce
commit
8bb777ef5c
35 files changed
+366
-373
No files matched your search
@@ -32,6 +32,7 @@
|
||||
#include "SpellAuraEffects.h"
|
||||
#include "Player.h"
|
||||
#include "Config.h"
|
||||
#include "QueryCallback.h"
|
||||
|
||||
void WorldSession::HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets& targets)
|
||||
{
|
||||
@@ -188,38 +189,44 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
|
||||
{
|
||||
TC_LOG_DEBUG("network", "WORLD: CMSG_OPEN_ITEM packet, data length = %i", (uint32)recvPacket.size());
|
||||
|
||||
Player* pUser = _player;
|
||||
Player* player = GetPlayer();
|
||||
|
||||
// ignore for remote control state
|
||||
if (pUser->m_unitMovedByMe != pUser)
|
||||
if (player->m_unitMovedByMe != player)
|
||||
return;
|
||||
|
||||
uint8 bagIndex, slot;
|
||||
// additional check, client outputs message on its own
|
||||
if (!player->IsAlive())
|
||||
{
|
||||
player->SendEquipError(EQUIP_ERR_YOU_ARE_DEAD, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8 bagIndex, slot;
|
||||
recvPacket >> bagIndex >> slot;
|
||||
|
||||
TC_LOG_INFO("network", "bagIndex: %u, slot: %u", bagIndex, slot);
|
||||
|
||||
Item* item = pUser->GetItemByPos(bagIndex, slot);
|
||||
Item* item = player->GetItemByPos(bagIndex, slot);
|
||||
if (!item)
|
||||
{
|
||||
pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
|
||||
player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemTemplate const* proto = item->GetTemplate();
|
||||
if (!proto)
|
||||
{
|
||||
pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL);
|
||||
player->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify that the bag is an actual bag or wrapped item that can be used "normally"
|
||||
if (!(proto->Flags & ITEM_FLAG_HAS_LOOT) && !item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED))
|
||||
{
|
||||
pUser->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, NULL);
|
||||
player->SendEquipError(EQUIP_ERR_CLIENT_LOCKED_OUT, item, NULL);
|
||||
TC_LOG_INFO("entities.player.cheat", "Possible hacking attempt: Player %s [guid: %u] tried to open item [guid: %u, entry: %u] which is not openable!",
|
||||
pUser->GetName().c_str(), pUser->GetGUID().GetCounter(), item->GetGUID().GetCounter(), proto->ItemId);
|
||||
player->GetName().c_str(), player->GetGUID().GetCounter(), item->GetGUID().GetCounter(), proto->ItemId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -231,7 +238,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
|
||||
|
||||
if (!lockInfo)
|
||||
{
|
||||
pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL);
|
||||
player->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, nullptr);
|
||||
TC_LOG_ERROR("network", "WORLD::OpenItem: item [guid = %u] has an unknown lockId: %u!", item->GetGUID().GetCounter(), lockId);
|
||||
return;
|
||||
}
|
||||
@@ -239,7 +246,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
|
||||
// was not unlocked yet
|
||||
if (item->IsLocked())
|
||||
{
|
||||
pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL);
|
||||
player->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -249,35 +256,50 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_GIFT_BY_ITEM);
|
||||
|
||||
stmt->setUInt32(0, item->GetGUID().GetCounter());
|
||||
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
uint32 flags = fields[1].GetUInt32();
|
||||
|
||||
item->SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid::Empty);
|
||||
item->SetEntry(entry);
|
||||
item->SetUInt32Value(ITEM_FIELD_FLAGS, flags);
|
||||
item->SetState(ITEM_CHANGED, pUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
TC_LOG_ERROR("network", "Wrapped item %u don't have record in character_gifts table and will deleted", item->GetGUID().GetCounter());
|
||||
pUser->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
|
||||
|
||||
stmt->setUInt32(0, item->GetGUID().GetCounter());
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
_queryProcessor.AddQuery(CharacterDatabase.AsyncQuery(stmt)
|
||||
.WithPreparedCallback(std::bind(&WorldSession::HandleOpenWrappedItemCallback, this, item->GetPos(), item->GetGUID(), std::placeholders::_1)));
|
||||
}
|
||||
else
|
||||
pUser->SendLoot(item->GetGUID(), LOOT_CORPSE);
|
||||
player->SendLoot(item->GetGUID(), LOOT_CORPSE);
|
||||
}
|
||||
|
||||
void WorldSession::HandleOpenWrappedItemCallback(uint16 pos, ObjectGuid itemGuid, PreparedQueryResult result)
|
||||
{
|
||||
if (!GetPlayer())
|
||||
return;
|
||||
|
||||
Item* item = GetPlayer()->GetItemByPos(pos);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
if (item->GetGUID() != itemGuid || !item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED)) // during getting result, gift was swapped with another item
|
||||
return;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
TC_LOG_ERROR("network", "Wrapped item %u don't have record in character_gifts table and will deleted", itemGuid.GetCounter());
|
||||
GetPlayer()->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
uint32 flags = fields[1].GetUInt32();
|
||||
|
||||
item->SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid::Empty);
|
||||
item->SetEntry(entry);
|
||||
item->SetUInt32Value(ITEM_FIELD_FLAGS, flags);
|
||||
item->SetState(ITEM_CHANGED, GetPlayer());
|
||||
|
||||
GetPlayer()->SaveInventoryAndGoldToDB(trans);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
|
||||
stmt->setUInt32(0, itemGuid.GetCounter());
|
||||
trans->Append(stmt);
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recvData)
|
||||
|
||||
Reference in new issue
Block a user