aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers/CharacterHandler.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-09-14 16:14:12 +0200
committerShauren <shauren.trinity@gmail.com>2014-09-14 16:14:12 +0200
commita0e50ea35fca61447bf07fc45d93c98234ba59f7 (patch)
treeb4ee69a63866f42e466a3c03fc031ce0710ac762 /src/server/game/Handlers/CharacterHandler.cpp
parentce67a097bf3c0c3241f4441a808e32639ddbaafb (diff)
Core/Entities: Use ObjectGuid class in game project
Diffstat (limited to 'src/server/game/Handlers/CharacterHandler.cpp')
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index b2507877111..be8c4916e7c 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -52,11 +52,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();
};
@@ -66,7 +66,7 @@ bool LoginQueryHolder::Initialize()
SetSize(MAX_PLAYER_LOGIN_QUERY);
bool res = true;
- uint32 lowGuid = GUID_LOPART(m_guid);
+ uint32 lowGuid = m_guid.GetCounter();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER);
stmt->setUInt32(0, lowGuid);
@@ -220,16 +220,16 @@ void WorldSession::HandleCharEnum(PreparedQueryResult result)
{
do
{
- uint32 guidlow = (*result)[0].GetUInt32();
- TC_LOG_INFO("network", "Loading char guid %u from account %u.", guidlow, GetAccountId());
+ ObjectGuid guid(HIGHGUID_PLAYER, (*result)[0].GetUInt32());
+ TC_LOG_INFO("network", "Loading %s from account %u.", guid.ToString().c_str(), GetAccountId());
if (Player::BuildEnumData(result, &data))
{
// Do not allow banned characters to log in
if (!(*result)[20].GetUInt32())
- _legitCharacters.insert(guidlow);
+ _legitCharacters.insert(guid);
- if (!sWorld->HasCharacterNameData(guidlow)) // This can happen if characters are inserted into the database manually. Core hasn't loaded name data yet.
- sWorld->AddCharacterNameData(guidlow, (*result)[1].GetString(), (*result)[4].GetUInt8(), (*result)[2].GetUInt8(), (*result)[3].GetUInt8(), (*result)[7].GetUInt8());
+ if (!sWorld->HasCharacterNameData(guid)) // This can happen if characters are inserted into the database manually. Core hasn't loaded name data yet.
+ sWorld->AddCharacterNameData(guid, (*result)[1].GetString(), (*result)[4].GetUInt8(), (*result)[2].GetUInt8(), (*result)[3].GetUInt8(), (*result)[7].GetUInt8());
++num;
}
}
@@ -682,7 +682,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
std::string IP_str = GetRemoteAddress();
TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Create Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUIDLow());
sScriptMgr->OnPlayerCreate(&newChar);
- sWorld->AddCharacterNameData(newChar.GetGUIDLow(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel());
+ sWorld->AddCharacterNameData(newChar.GetGUID(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel());
newChar.CleanupsBeforeDelete();
delete createInfo;
@@ -694,7 +694,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
{
- uint64 guid;
+ ObjectGuid guid;
recvData >> guid;
// Initiating
uint32 initAccountId = GetAccountId();
@@ -731,7 +731,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_DATA_BY_GUID);
- stmt->setUInt32(0, GUID_LOPART(guid));
+ stmt->setUInt32(0, guid.GetCounter());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
{
@@ -749,7 +749,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
}
std::string IP_str = GetRemoteAddress();
- TC_LOG_INFO("entities.player.character", "Account: %d, IP: %s deleted character: %s, GUID: %u, Level: %u", accountId, IP_str.c_str(), name.c_str(), GUID_LOPART(guid), level);
+ TC_LOG_INFO("entities.player.character", "Account: %d, IP: %s deleted character: %s, %s, Level: %u", accountId, IP_str.c_str(), name.c_str(), guid.ToString().c_str(), level);
// 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.
@@ -758,8 +758,8 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
if (sLog->ShouldLog("entities.player.dump", LOG_LEVEL_INFO)) // optimize GetPlayerDump call
{
std::string dump;
- if (PlayerDumpWriter().GetDump(GUID_LOPART(guid), dump))
- sLog->outCharDump(dump.c_str(), accountId, GUID_LOPART(guid), name.c_str());
+ if (PlayerDumpWriter().GetDump(guid.GetCounter(), dump))
+ sLog->outCharDump(dump.c_str(), accountId, guid.GetCounter(), name.c_str());
}
sCalendarMgr->RemoveAllPlayerEventsAndInvites(guid);
@@ -780,15 +780,15 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
}
m_playerLoading = true;
- uint64 playerGuid = 0;
+ ObjectGuid playerGuid;
TC_LOG_DEBUG("network", "WORLD: Recvd Player Logon Message");
recvData >> playerGuid;
- if (!IsLegitCharacterForAccount(GUID_LOPART(playerGuid)))
+ if (!IsLegitCharacterForAccount(playerGuid))
{
- TC_LOG_ERROR("network", "Account (%u) can't login with that character (%u).", GetAccountId(), GUID_LOPART(playerGuid));
+ TC_LOG_ERROR("network", "Account (%u) can't login with that character (%s).", GetAccountId(), playerGuid.ToString().c_str());
KickPlayer();
return;
}
@@ -801,19 +801,19 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recvData)
return;
}
- _charLoginCallback = CharacterDatabase.DelayQueryHolder((SQLQueryHolder*)holder);
+ _charLoginCallback = CharacterDatabase.DelayQueryHolder(holder);
}
void WorldSession::HandlePlayerLogin(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(pCurrChar->GetSession());
// "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(NULL);
KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
@@ -1127,7 +1127,7 @@ void WorldSession::HandleShowingCloakOpcode(WorldPacket& recvData)
void WorldSession::HandleCharRenameOpcode(WorldPacket& recvData)
{
- uint64 guid;
+ ObjectGuid guid;
std::string newName;
recvData >> guid;
@@ -1168,7 +1168,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);
@@ -1192,7 +1192,7 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult resu
uint32 guidLow = fields[0].GetUInt32();
std::string oldName = fields[1].GetString();
- uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
+ ObjectGuid guid = ObjectGuid(HIGHGUID_PLAYER, guidLow);
// Update name and at_login flag in the db
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_NAME);
@@ -1210,7 +1210,7 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult resu
CharacterDatabase.Execute(stmt);
- TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldName.c_str(), guidLow, newName.c_str());
+ TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Character:[%s] (%s) Changed name to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldName.c_str(), guid.ToString().c_str(), newName.c_str());
WorldPacket data(SMSG_CHAR_RENAME, 1+8+(newName.size()+1));
data << uint8(RESPONSE_SUCCESS);
@@ -1218,12 +1218,12 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult resu
data << newName;
SendPacket(&data);
- sWorld->UpdateCharacterNameData(guidLow, newName);
+ sWorld->UpdateCharacterNameData(guid, newName);
}
void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
{
- uint64 guid;
+ ObjectGuid guid;
recvData >> guid;
@@ -1299,11 +1299,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]);
@@ -1414,14 +1414,14 @@ 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))
{
- TC_LOG_ERROR("network", "Account %u, IP: %s tried to customise character %u, but it does not belong to their account!",
- GetAccountId(), GetRemoteAddress().c_str(), GUID_LOPART(guid));
+ TC_LOG_ERROR("network", "Account %u, IP: %s tried to customise %s, but it does not belong to their account!",
+ GetAccountId(), GetRemoteAddress().c_str(), guid.ToString().c_str());
recvData.rfinish();
KickPlayer();
return;
@@ -1434,7 +1434,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_AT_LOGIN);
- stmt->setUInt32(0, GUID_LOPART(guid));
+ stmt->setUInt32(0, guid.GetCounter());
// TODO: Make async with callback
PreparedQueryResult result = CharacterDatabase.Query(stmt);
@@ -1485,7 +1485,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)
{
@@ -1497,13 +1497,13 @@ void WorldSession::HandleCharCustomize(WorldPacket& recvData)
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_NAME);
- stmt->setUInt32(0, GUID_LOPART(guid));
+ stmt->setUInt32(0, guid.GetCounter());
result = CharacterDatabase.Query(stmt);
if (result)
{
std::string oldname = result->Fetch()[0].GetString();
- TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldname.c_str(), GUID_LOPART(guid), newName.c_str());
+ TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s), Character[%s] (%s) Customized to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldname.c_str(), guid.ToString().c_str(), newName.c_str());
}
Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
@@ -1512,17 +1512,17 @@ 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);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME);
- stmt->setUInt32(0, GUID_LOPART(guid));
+ stmt->setUInt32(0, guid.GetCounter());
CharacterDatabase.Execute(stmt);
- sWorld->UpdateCharacterNameData(GUID_LOPART(guid), newName, gender);
+ sWorld->UpdateCharacterNameData(guid, newName, gender);
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1+8+(newName.size()+1)+6);
data << uint8(RESPONSE_SUCCESS);
@@ -1564,11 +1564,11 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket &recvData)
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
- uint64 itemGuid;
- recvData.readPackGUID(itemGuid);
+ ObjectGuid itemGuid;
+ recvData >> itemGuid.ReadAsPacked();
// 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;
@@ -1583,7 +1583,7 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket &recvData)
if (item && item->GetGUID() != itemGuid) // cheating check 2
return;
- eqSet.Items[i] = GUID_LOPART(itemGuid);
+ eqSet.Items[i] = itemGuid.GetCounter();
}
_player->SetEquipmentSet(index, eqSet);
@@ -1605,16 +1605,16 @@ 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;
- TC_LOG_DEBUG("entities.player.items", "Item " UI64FMTD ": srcbag %u, srcslot %u", itemGuid, srcbag, srcslot);
+ TC_LOG_DEBUG("entities.player.items", "%s: srcbag %u, srcslot %u", itemGuid.ToString().c_str(), srcbag, srcslot);
// 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
@@ -1657,15 +1657,15 @@ 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))
{
- TC_LOG_ERROR("network", "Account %u, IP: %s tried to factionchange character %u, but it does not belong to their account!",
- GetAccountId(), GetRemoteAddress().c_str(), GUID_LOPART(guid));
+ TC_LOG_ERROR("network", "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();
return;
@@ -1674,10 +1674,10 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
recvData >> newname;
recvData >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face >> race;
- uint32 lowGuid = GUID_LOPART(guid);
+ uint32 lowGuid = guid.GetCounter();
// get the players old (at this moment current) race
- CharacterNameData const* nameData = sWorld->GetCharacterNameData(lowGuid);
+ CharacterNameData const* nameData = sWorld->GetCharacterNameData(guid);
if (!nameData)
{
WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1);
@@ -1764,7 +1764,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)
{
@@ -1793,7 +1793,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
stmt->setUInt32(0, lowGuid);
trans->Append(stmt);
- sWorld->UpdateCharacterNameData(GUID_LOPART(guid), newname, gender, race);
+ sWorld->UpdateCharacterNameData(guid, newname, gender, race);
if (oldRace != race)
{
@@ -1932,7 +1932,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
if (Guild* guild = sGuildMgr->GetGuildById((result->Fetch()[0]).GetUInt32()))
- guild->DeleteMember(MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER), false, false, true);
+ guild->DeleteMember(guid, false, false, true);
Player::LeaveAllArenaTeams(guid);
}
@@ -1963,7 +1963,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
{
@@ -1972,7 +1972,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);
@@ -2003,13 +2003,13 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INVENTORY_FACTION_CHANGE);
stmt->setUInt32(0, (team == TEAM_ALLIANCE ? item_alliance : item_horde));
stmt->setUInt32(1, (team == TEAM_ALLIANCE ? item_horde : item_alliance));
- stmt->setUInt32(2, guid);
+ stmt->setUInt32(2, lowGuid);
trans->Append(stmt);
}
// Delete all current quests
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS);
- stmt->setUInt32(0, GUID_LOPART(guid));
+ stmt->setUInt32(0, lowGuid);
trans->Append(stmt);
// Quest conversion