feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -48,11 +48,11 @@ class LoginQueryHolder : public SQLQueryHolder
{
private:
uint32 m_accountId;
uint64 m_guid;
ObjectGuid m_guid;
public:
LoginQueryHolder(uint32 accountId, uint64 guid)
LoginQueryHolder(uint32 accountId, ObjectGuid guid)
: m_accountId(accountId), m_guid(guid) { }
uint64 GetGuid() const { return m_guid; }
ObjectGuid GetGuid() const { return m_guid; }
uint32 GetAccountId() const { return m_accountId; }
bool Initialize();
};
@@ -62,7 +62,7 @@ bool LoginQueryHolder::Initialize()
SetSize(MAX_PLAYER_LOGIN_QUERY);
bool res = true;
uint32 lowGuid = GUID_LOPART(m_guid);
ObjectGuid::LowType lowGuid = m_guid.GetCounter();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER);
stmt->setUInt32(0, lowGuid);
@@ -193,6 +193,10 @@ bool LoginQueryHolder::Initialize()
stmt->setUInt32(0, m_accountId);
res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_INSTANCE_LOCK_TIMES, stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CORPSE_LOCATION);
stmt->setUInt64(0, lowGuid);
res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_CORPSE_LOCATION, stmt);
return res;
}
@@ -209,13 +213,13 @@ void WorldSession::HandleCharEnum(PreparedQueryResult result)
{
do
{
uint32 guidlow = (*result)[0].GetUInt32();
ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>((*result)[0].GetUInt32());
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "Loading char guid %u from account %u.", guidlow, GetAccountId());
LOG_DEBUG("server", "Loading char %s from account %u.", guid.ToString().c_str(), GetAccountId());
#endif
if (Player::BuildEnumData(result, &data))
{
_legitCharacters.insert(guidlow);
_legitCharacters.insert(guid);
++num;
}
} while (result->NextRow());
@@ -617,7 +621,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
Player newChar(this);
newChar.GetMotionMaster()->Initialize();
if (!newChar.Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PLAYER), createInfo))
if (!newChar.Create(sObjectMgr->GetGenerator<HighGuid::Player>().Generate(), createInfo))
{
// Player not create (race/class/etc problem?)
newChar.CleanupsBeforeDelete();
@@ -660,11 +664,11 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
std::string IP_str = GetRemoteAddress();
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "Account: %d (IP: %s) Create Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUIDLow());
LOG_DEBUG("server", "Account: %d (IP: %s) Create Character:[%s] (%s)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUID().ToString().c_str());
#endif
LOG_INFO("entities.player", "Account: %d (IP: %s) Create Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUIDLow());
LOG_INFO("entities.player", "Account: %d (IP: %s) Create Character:[%s] (%s)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUID().ToString().c_str());
sScriptMgr->OnPlayerCreate(&newChar);
sWorld->AddGlobalPlayerData(newChar.GetGUIDLow(), GetAccountId(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel(), 0, 0);
sWorld->AddGlobalPlayerData(newChar.GetGUID().GetCounter(), GetAccountId(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel(), 0, 0);
newChar.CleanupsBeforeDelete();
delete createInfo;
@@ -676,13 +680,14 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
{
uint64 guid;
ObjectGuid guid;
recvData >> guid;
// Initiating
uint32 initAccountId = GetAccountId();
// can't delete loaded character
if (ObjectAccessor::FindPlayerInOrOutOfWorld(guid) || sWorld->FindOfflineSessionForCharacterGUID(GUID_LOPART(guid)))
if (ObjectAccessor::FindConnectedPlayer(guid) || sWorld->FindOfflineSessionForCharacterGUID(guid.GetCounter()))
{
sScriptMgr->OnPlayerFailedDelete(guid, initAccountId);
WorldPacket data(SMSG_CHAR_DELETE, 1);
@@ -714,7 +719,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
return;
}
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid)))
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
{
accountId = playerData->accountId;
name = playerData->name;
@@ -729,9 +734,9 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
std::string IP_str = GetRemoteAddress();
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "Account: %d (IP: %s) Delete Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), name.c_str(), GUID_LOPART(guid));
LOG_DEBUG("server", "Account: %d (IP: %s) Delete Character:[%s] (%s)", GetAccountId(), IP_str.c_str(), name.c_str(), guid.ToString().c_str());
#endif
LOG_INFO("entities.player", "Account: %d (IP: %s) Delete Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), name.c_str(), GUID_LOPART(guid));
LOG_INFO("entities.player", "Account: %d (IP: %s) Delete Character:[%s] (%s)", GetAccountId(), IP_str.c_str(), name.c_str(), guid.ToString().c_str());
// To prevent hook failure, place hook before removing reference from DB
sScriptMgr->OnPlayerDelete(guid, initAccountId); // To prevent race conditioning, but as it also makes sense, we hand the accountId over for successful delete.
@@ -740,15 +745,14 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
if (sLog->ShouldLog("entities.player.dump", LogLevel::LOG_LEVEL_INFO)) // optimize GetPlayerDump call
{
std::string dump;
if (PlayerDumpWriter().GetDump(GUID_LOPART(guid), dump))\
LOG_CHAR_DUMP(dump.c_str(), GetAccountId(), GUID_LOPART(guid), name.c_str());
if (PlayerDumpWriter().GetDump(guid.GetCounter(), dump))
LOG_CHAR_DUMP(dump.c_str(), GetAccountId(), guid.GetCounter(), name.c_str());
}
sCalendarMgr->RemoveAllPlayerEventsAndInvites(guid);
Player::DeleteFromDB(guid, GetAccountId(), true, false);
Player::DeleteFromDB(guid.GetCounter(), GetAccountId(), true, false);
sWorld->DeleteGlobalPlayerData(GUID_LOPART(guid), name);
sWorld->DeleteGlobalPlayerData(guid.GetCounter(), name);
WorldPacket data(SMSG_CHAR_DELETE, 1);
data << (uint8)CHAR_DELETE_SUCCESS;
SendPacket(&data);
@@ -763,18 +767,18 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
return;
}
uint64 playerGuid = 0;
ObjectGuid playerGuid;
recvData >> playerGuid;
if (!IsLegitCharacterForAccount(GUID_LOPART(playerGuid)))
if (!playerGuid.IsPlayer() || !IsLegitCharacterForAccount(playerGuid))
{
LOG_ERROR("server", "Account (%u) can't login with that character (%u).", GetAccountId(), GUID_LOPART(playerGuid));
LOG_ERROR("server", "Account (%u) can't login with that character (%s).", GetAccountId(), playerGuid.ToString().c_str());
KickPlayer("Account can't login with this character");
return;
}
// pussywizard:
if (WorldSession* sess = sWorld->FindOfflineSessionForCharacterGUID(GUID_LOPART(playerGuid)))
if (WorldSession* sess = sWorld->FindOfflineSessionForCharacterGUID(playerGuid.GetCounter()))
if (sess->GetAccountId() != GetAccountId())
{
WorldPacket data(SMSG_CHARACTER_LOGIN_FAILED, 1);
@@ -835,7 +839,7 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
if (!plMover)
break;
WorldPacket pkt(MSG_MOVE_TELEPORT_ACK, 20);
pkt.append(plMover->GetPackGUID());
pkt << plMover->GetPackGUID();
pkt << uint32(0); // flags
pkt << uint32(0); // time
sess->HandleMoveTeleportAck(pkt);
@@ -874,14 +878,14 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
{
uint64 playerGuid = holder->GetGuid();
ObjectGuid playerGuid = holder->GetGuid();
Player* pCurrChar = new Player(this);
// for send server info and strings (config)
ChatHandler chH = ChatHandler(this);
// "GetAccountId() == db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
if (!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder))
if (!pCurrChar->LoadFromDB(playerGuid, holder))
{
SetPlayer(nullptr);
KickPlayer("HandlePlayerLoginFromDB"); // disconnect client, player no set to session and it will not deleted or saved at kick
@@ -924,7 +928,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
#endif
}
if (uint32 guildId = Player::GetGuildIdFromStorage(pCurrChar->GetGUIDLow()))
if (uint32 guildId = Player::GetGuildIdFromStorage(pCurrChar->GetGUID().GetCounter()))
{
Guild* guild = sGuildMgr->GetGuildById(guildId);
Guild::Member const* member = guild ? guild->GetMember(pCurrChar->GetGUID()) : nullptr;
@@ -936,7 +940,8 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
}
else
{
LOG_ERROR("server", "Player %s (GUID: %u) marked as member of not existing guild (id: %u), removing guild membership for player.", pCurrChar->GetName().c_str(), pCurrChar->GetGUIDLow(), guildId);
LOG_ERROR("server", "Player %s (%s) marked as member of not existing guild (id: %u), removing guild membership for player.",
pCurrChar->GetName().c_str(), pCurrChar->GetGUID().ToString().c_str(), guildId);
pCurrChar->SetInGuild(0);
pCurrChar->SetRank(0);
}
@@ -973,7 +978,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
}
// Xinef: moved this from below
sObjectAccessor->AddObject(pCurrChar);
ObjectAccessor::AddObject(pCurrChar);
if (!pCurrChar->GetMap()->AddPlayerToMap(pCurrChar) || !pCurrChar->CheckInstanceLoginValid())
{
@@ -984,15 +989,10 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
pCurrChar->TeleportTo(pCurrChar->m_homebindMapId, pCurrChar->m_homebindX, pCurrChar->m_homebindY, pCurrChar->m_homebindZ, pCurrChar->GetOrientation());
}
// pussywizard: optimization
std::string charName = pCurrChar->GetName();
std::transform(charName.begin(), charName.end(), charName.begin(), ::tolower);
sObjectAccessor->playerNameToPlayerPointer[charName] = pCurrChar;
pCurrChar->SendInitialPacketsAfterAddToMap();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_ONLINE);
stmt->setUInt32(0, pCurrChar->GetGUIDLow());
stmt->setUInt32(0, pCurrChar->GetGUID().GetCounter());
CharacterDatabase.Execute(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_ONLINE);
@@ -1030,10 +1030,10 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
}
// friend status
sSocialMgr->SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), true);
sSocialMgr->SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUID(), true);
// Place character in world (and load zone) before some object loading
pCurrChar->LoadCorpse();
pCurrChar->LoadCorpse(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_CORPSE_LOCATION));
// setting Ghost+speed if dead
if (pCurrChar->m_deathState != ALIVE)
@@ -1128,8 +1128,8 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
SendNotification(LANG_GM_ON);
std::string IP_str = GetRemoteAddress();
LOG_INFO("entities.player", "Account: %d (IP: %s) Login Character:[%s] (GUID: %u) Level: %d",
GetAccountId(), IP_str.c_str(), pCurrChar->GetName().c_str(), pCurrChar->GetGUIDLow(), pCurrChar->getLevel());
LOG_INFO("entities.player", "Account: %d (IP: %s) Login Character:[%s] (%s) Level: %d",
GetAccountId(), IP_str.c_str(), pCurrChar->GetName().c_str(), pCurrChar->GetGUID().ToString().c_str(), pCurrChar->getLevel());
if (!pCurrChar->IsStandState() && !pCurrChar->HasUnitState(UNIT_STATE_STUNNED))
pCurrChar->SetStandState(UNIT_STAND_STATE_STAND);
@@ -1423,7 +1423,7 @@ void WorldSession::HandleShowingCloakOpcode(WorldPacket& recvData)
void WorldSession::HandleCharRenameOpcode(WorldPacket& recvData)
{
uint64 guid;
ObjectGuid guid;
std::string newName;
recvData >> guid;
@@ -1443,7 +1443,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recvData)
{
WorldPacket data(SMSG_CHAR_RENAME, 1 + 8 + (newName.size() + 1));
data << uint8(res);
data << uint64(guid);
data << guid;
data << newName;
SendPacket(&data);
return;
@@ -1464,7 +1464,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recvData)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_FREE_NAME);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt32(1, GetAccountId());
stmt->setUInt16(2, AT_LOGIN_RENAME);
stmt->setUInt16(3, AT_LOGIN_RENAME);
@@ -1485,13 +1485,13 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult resu
Field* fields = result->Fetch();
uint32 guidLow = fields[0].GetUInt32();
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
std::string oldName = fields[1].GetString();
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
ObjectGuid guid = ObjectGuid::Create<HighGuid::Player>(guidLow);
// pussywizard:
if (ObjectAccessor::FindPlayerInOrOutOfWorld(guid) || sWorld->FindOfflineSessionForCharacterGUID(guidLow))
if (ObjectAccessor::FindConnectedPlayer(guid) || sWorld->FindOfflineSessionForCharacterGUID(guidLow))
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << uint8(CHAR_CREATE_ERROR);
@@ -1522,7 +1522,7 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult resu
WorldPacket data(SMSG_CHAR_RENAME, 1 + 8 + (newName.size() + 1));
data << uint8(RESPONSE_SUCCESS);
data << uint64(guid);
data << guid;
data << newName;
SendPacket(&data);
@@ -1537,17 +1537,17 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
if (!sWorld->getBoolConfig(CONFIG_DECLINED_NAMES_USED))
return;
uint64 guid;
ObjectGuid guid;
recvData >> guid;
// not accept declined names for unsupported languages
std::string name;
if (!sObjectMgr->GetPlayerNameByGUID(guid, name))
if (!sObjectMgr->GetPlayerNameByGUID(guid.GetCounter(), name))
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1557,7 +1557,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1566,7 +1566,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1580,7 +1580,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1592,7 +1592,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1602,7 +1602,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(1);
data << uint64(guid);
data << guid;
SendPacket(&data);
return;
}
@@ -1613,11 +1613,11 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_DECLINED_NAME);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_DECLINED_NAME);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
for (uint8 i = 0; i < 5; i++)
stmt->setString(i + 1, declinedname.name[i]);
@@ -1628,7 +1628,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4 + 8);
data << uint32(0); // OK
data << uint64(guid);
data << guid;
SendPacket(&data);
}
@@ -1732,21 +1732,21 @@ void WorldSession::HandleRemoveGlyph(WorldPacket& recvData)
void WorldSession::HandleCharCustomize(WorldPacket& recvData)
{
uint64 guid;
ObjectGuid guid;
std::string newName;
recvData >> guid;
if (!IsLegitCharacterForAccount(GUID_LOPART(guid)))
if (!IsLegitCharacterForAccount(guid))
{
LOG_ERROR("server", "Account %u, IP: %s tried to customise character %u, but it does not belong to their account!",
GetAccountId(), GetRemoteAddress().c_str(), GUID_LOPART(guid));
LOG_ERROR("server", "Account %u, IP: %s tried to customise character %s, but it does not belong to their account!",
GetAccountId(), GetRemoteAddress().c_str(), guid.ToString().c_str());
recvData.rfinish();
KickPlayer("HandleCharCustomize");
return;
}
// pussywizard:
if (ObjectAccessor::FindPlayerInOrOutOfWorld(guid) || sWorld->FindOfflineSessionForCharacterGUID(GUID_LOPART(guid)))
if (ObjectAccessor::FindConnectedPlayer(guid) || sWorld->FindOfflineSessionForCharacterGUID(guid.GetCounter()))
{
recvData.rfinish();
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
@@ -1763,7 +1763,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
// xinef: zomg! sync query
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_AT_LOGIN);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
@@ -1776,7 +1776,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
}
// get the players old (at this moment current) race
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid));
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter());
if (!playerData)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
@@ -1824,7 +1824,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
}
// character with this name already exist
if (uint64 newguid = sObjectMgr->GetPlayerGUIDByName(newName))
if (ObjectGuid newguid = sObjectMgr->GetPlayerGUIDByName(newName))
{
if (newguid != guid)
{
@@ -1835,7 +1835,8 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
}
}
LOG_INFO("entities.player", "Account: %d (IP: %s), Character [%s] (guid: %u) Customized to: %s", GetAccountId(), GetRemoteAddress().c_str(), playerData->name.c_str(), GUID_LOPART(guid), newName.c_str());
LOG_INFO("entities.player", "Account: %d (IP: %s), Character [%s] (%s) Customized to: %s",
GetAccountId(), GetRemoteAddress().c_str(), playerData->name.c_str(), guid.ToString().c_str(), newName.c_str());
Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
@@ -1843,7 +1844,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
stmt->setString(0, newName);
stmt->setUInt16(1, uint16(AT_LOGIN_CUSTOMIZE));
stmt->setUInt32(2, GUID_LOPART(guid));
stmt->setUInt32(2, guid.GetCounter());
CharacterDatabase.Execute(stmt);
@@ -1851,18 +1852,18 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
CharacterDatabase.Execute(stmt);
}
// xinef: update global data
sWorld->UpdateGlobalNameData(GUID_LOPART(guid), playerData->name, newName);
sWorld->UpdateGlobalPlayerData(GUID_LOPART(guid), PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_GENDER, newName, 0, gender);
sWorld->UpdateGlobalNameData(guid.GetCounter(), playerData->name, newName);
sWorld->UpdateGlobalPlayerData(guid.GetCounter(), PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_GENDER, newName, 0, gender);
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1 + 8 + (newName.size() + 1) + 6);
data << uint8(RESPONSE_SUCCESS);
data << uint64(guid);
data << guid;
data << newName;
data << uint8(gender);
data << uint8(skin);
@@ -1902,18 +1903,18 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket& recvData)
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
uint64 itemGuid;
recvData.readPackGUID(itemGuid);
ObjectGuid itemGuid;
recvData >> itemGuid.ReadAsPacked();
// xinef: if client sends 0, it means empty slot
if (itemGuid == 0)
if (!itemGuid)
{
eqSet.Items[i] = 0;
eqSet.Items[i].Clear();
continue;
}
// equipment manager sends "1" (as raw GUID) for slots set to "ignore" (don't touch slot at equip set)
if (itemGuid == 1)
if (itemGuid.GetRawValue() == 1)
{
// ignored slots saved as bit mask because we have no free special values for Items[i]
eqSet.IgnoreMask |= 1 << i;
@@ -1924,11 +1925,11 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket& recvData)
Item* item = _player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
if (!item || item->GetGUID() != itemGuid)
{
eqSet.Items[i] = 0;
eqSet.Items[i].Clear();
continue;
}
eqSet.Items[i] = GUID_LOPART(itemGuid);
eqSet.Items[i] = itemGuid;
}
_player->SetEquipmentSet(index, eqSet);
@@ -1954,18 +1955,18 @@ void WorldSession::HandleEquipmentSetUse(WorldPacket& recvData)
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
uint64 itemGuid;
recvData.readPackGUID(itemGuid);
ObjectGuid itemGuid;
recvData >> itemGuid.ReadAsPacked();
uint8 srcbag, srcslot;
recvData >> srcbag >> srcslot;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("entities.player.items", "Item " UI64FMTD ": srcbag %u, srcslot %u", itemGuid, srcbag, srcslot);
LOG_DEBUG("entities.player.items", "Item %s: srcbag %u, srcslot %u", itemGuid.ToString().c_str(), srcbag, srcslot);
#endif
// check if item slot is set to "ignored" (raw value == 1), must not be unequipped then
if (itemGuid == 1)
if (itemGuid.GetRawValue() == 1)
continue;
// Only equip weapons in combat
@@ -1973,7 +1974,7 @@ void WorldSession::HandleEquipmentSetUse(WorldPacket& recvData)
continue;
Item* item = nullptr;
if (itemGuid > 0)
if (itemGuid)
item = _player->GetItemByGuid(itemGuid);
uint16 dstpos = i | (INVENTORY_SLOT_BAG_0 << 8);
@@ -2036,22 +2037,22 @@ void WorldSession::HandleEquipmentSetUse(WorldPacket& recvData)
void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
{
uint64 guid;
ObjectGuid guid;
std::string newname;
uint8 gender, skin, face, hairStyle, hairColor, facialHair, race;
recvData >> guid;
if (!IsLegitCharacterForAccount(GUID_LOPART(guid)))
if (!IsLegitCharacterForAccount(guid))
{
LOG_ERROR("server", "Account %u, IP: %s tried to factionchange character %u, but it does not belong to their account!",
GetAccountId(), GetRemoteAddress().c_str(), GUID_LOPART(guid));
LOG_ERROR("server", "Account %u, IP: %s tried to factionchange character %s, but it does not belong to their account!",
GetAccountId(), GetRemoteAddress().c_str(), guid.ToString().c_str());
recvData.rfinish();
KickPlayer("HandleCharFactionOrRaceChange");
return;
}
// pussywizard:
if (ObjectAccessor::FindPlayerInOrOutOfWorld(guid) || sWorld->FindOfflineSessionForCharacterGUID(GUID_LOPART(guid)))
if (ObjectAccessor::FindConnectedPlayer(guid) || sWorld->FindOfflineSessionForCharacterGUID(guid.GetCounter()))
{
recvData.rfinish();
WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1);
@@ -2063,7 +2064,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
recvData >> newname;
recvData >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face >> race;
uint32 lowGuid = GUID_LOPART(guid);
ObjectGuid::LowType lowGuid = guid.GetCounter();
// get the players old (at this moment current) race
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(lowGuid);
@@ -2115,7 +2116,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
for (; itr != _end; ++itr)
{
AuctionEntry* Aentry = itr->second;
if (Aentry && (Aentry->owner == lowGuid || Aentry->bidder == lowGuid))
if (Aentry && (Aentry->owner == guid || Aentry->bidder == guid))
{
has_auctions = true;
break;
@@ -2239,7 +2240,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
}
// character with this name already exist
if (uint64 newguid = sObjectMgr->GetPlayerGUIDByName(newname))
if (ObjectGuid newguid = sObjectMgr->GetPlayerGUIDByName(newname))
{
if (newguid != guid)
{
@@ -2252,8 +2253,12 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
CharacterDatabase.EscapeString(newname);
Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
// resurrect the character in case he's dead
Player::OfflineResurrect(guid, trans);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_FACTION_OR_RACE);
stmt->setString(0, newname);
stmt->setUInt8(1, race);
@@ -2268,9 +2273,8 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
LOG_INFO("entities.player", "Account: %d (IP: %s), Character [%s] (guid: %u) Changed Race/Faction to: %s", GetAccountId(), GetRemoteAddress().c_str(), playerData->name.c_str(), lowGuid, newname.c_str());
// xinef: update global data
sWorld->UpdateGlobalNameData(GUID_LOPART(guid), playerData->name, newname);
sWorld->UpdateGlobalPlayerData(GUID_LOPART(guid),
PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_RACE | PLAYER_UPDATE_DATA_GENDER, newname, 0, gender, race);
sWorld->UpdateGlobalNameData(lowGuid, playerData->name, newname);
sWorld->UpdateGlobalPlayerData(lowGuid, PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_RACE | PLAYER_UPDATE_DATA_GENDER, newname, 0, gender, race);
if (oldRace != race)
{
@@ -2404,7 +2408,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
{
if (uint32 guildId = playerData->guildId)
if (Guild* guild = sGuildMgr->GetGuildById(guildId))
guild->DeleteMember(MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER), false, false, true);
guild->DeleteMember(guid, false, false, true);
}
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND))
@@ -2436,7 +2440,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
stmt->setFloat (3, -8867.68f);
stmt->setFloat (4, 673.373f);
stmt->setFloat (5, 97.9034f);
Player::SavePositionInDB(0, -8867.68f, 673.373f, 97.9034f, 0.0f, 1519, lowGuid);
Player::SavePositionInDB(0, -8867.68f, 673.373f, 97.9034f, 0.0f, 1519, guid);
}
else
{
@@ -2445,7 +2449,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
stmt->setFloat (3, 1633.33f);
stmt->setFloat (4, -4439.11f);
stmt->setFloat (5, 15.7588f);
Player::SavePositionInDB(1, 1633.33f, -4439.11f, 15.7588f, 0.0f, 1637, lowGuid);
Player::SavePositionInDB(1, 1633.33f, -4439.11f, 15.7588f, 0.0f, 1637, guid);
}
trans->Append(stmt);
@@ -2480,13 +2484,13 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INVENTORY_FACTION_CHANGE);
stmt->setUInt32(0, new_entry);
stmt->setUInt32(1, old_entry);
stmt->setUInt32(2, guid);
stmt->setUInt32(2, guid.GetCounter());
trans->Append(stmt);
}
// Delete all current quests
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS);
stmt->setUInt32(0, GUID_LOPART(guid));
stmt->setUInt32(0, guid.GetCounter());
trans->Append(stmt);
// Quest conversion
@@ -2675,7 +2679,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1 + 8 + (newname.size() + 1) + 1 + 1 + 1 + 1 + 1 + 1 + 1);
data << uint8(RESPONSE_SUCCESS);
data << uint64(guid);
data << guid;
data << newname;
data << uint8(gender);
data << uint8(skin);