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

@@ -38,8 +38,8 @@ Copied events should probably have a new owner
void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/)
{
uint64 guid = _player->GetGUID();
LOG_DEBUG("network", "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid);
ObjectGuid guid = _player->GetGUID();
LOG_DEBUG("network", "CMSG_CALENDAR_GET_CALENDAR [%s]", guid.ToString().c_str());
time_t currTime = time(nullptr);
@@ -57,12 +57,12 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/)
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId()))
{
data << uint8(calendarEvent->IsGuildEvent());
data.appendPackGUID(calendarEvent->GetCreatorGUID());
data << calendarEvent->GetCreatorGUID().WriteAsPacked();
}
else
{
data << uint8(0);
data.appendPackGUID((*itr)->GetSenderGUID());
data << (*itr)->GetSenderGUID().WriteAsPacked();
}
}
@@ -78,7 +78,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/)
data.AppendPackedTime(calendarEvent->GetEventTime());
data << uint32(calendarEvent->GetFlags());
data << int32(calendarEvent->GetDungeonId());
data.appendPackGUID(calendarEvent->GetCreatorGUID());
data << calendarEvent->GetCreatorGUID().WriteAsPacked();
}
data << uint32(currTime); // server time
@@ -88,7 +88,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/)
uint32 boundCounter = 0;
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(_player->GetGUIDLow(), Difficulty(i));
BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(_player->GetGUID(), Difficulty(i));
for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr)
{
if (itr->second.perm)
@@ -98,7 +98,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/)
dataBuffer << uint32(save->GetMapId());
dataBuffer << uint32(save->GetDifficulty());
dataBuffer << uint32(resetTime >= currTime ? resetTime - currTime : 0);
dataBuffer << uint64(MAKE_NEW_GUID(save->GetInstanceId(), 0, HIGHGUID_INSTANCE)); // instance save id as unique instance copy id
dataBuffer << ObjectGuid::Create<HighGuid::Instance>(save->GetInstanceId()); // instance save id as unique instance copy id
++boundCounter;
}
}
@@ -171,8 +171,7 @@ void WorldSession::HandleCalendarGetEvent(WorldPacket& recvData)
uint64 eventId;
recvData >> eventId;
LOG_DEBUG("network", "CMSG_CALENDAR_GET_EVENT. Player ["
UI64FMTD "] Event [" UI64FMTD "]", _player->GetGUID(), eventId);
LOG_DEBUG("network", "CMSG_CALENDAR_GET_EVENT. Player [%s] Event [" UI64FMTD "]", _player->GetGUID().ToString().c_str(), eventId);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
sCalendarMgr->SendCalendarEvent(_player->GetGUID(), *calendarEvent, CALENDAR_SENDTYPE_GET);
@@ -182,7 +181,7 @@ void WorldSession::HandleCalendarGetEvent(WorldPacket& recvData)
void WorldSession::HandleCalendarGuildFilter(WorldPacket& recvData)
{
LOG_DEBUG("network", "CMSG_CALENDAR_GUILD_FILTER [" UI64FMTD "]", _player->GetGUID());
LOG_DEBUG("network", "CMSG_CALENDAR_GUILD_FILTER [%s]", _player->GetGUID().ToString().c_str());
uint32 minLevel;
uint32 maxLevel;
@@ -198,7 +197,7 @@ void WorldSession::HandleCalendarGuildFilter(WorldPacket& recvData)
void WorldSession::HandleCalendarArenaTeam(WorldPacket& recvData)
{
LOG_DEBUG("network", "CMSG_CALENDAR_ARENA_TEAM [" UI64FMTD "]", _player->GetGUID());
LOG_DEBUG("network", "CMSG_CALENDAR_ARENA_TEAM [%s]", _player->GetGUID().ToString().c_str());
uint32 arenaTeamId;
recvData >> arenaTeamId;
@@ -207,11 +206,12 @@ void WorldSession::HandleCalendarArenaTeam(WorldPacket& recvData)
team->MassInviteToEvent(this);
}
bool validUtf8String(WorldPacket& recvData, std::string& s, std::string action, uint64 playerGUID)
bool validUtf8String(WorldPacket& recvData, std::string& s, std::string action, ObjectGuid playerGUID)
{
if (!utf8::is_valid(s.begin(), s.end()))
{
LOG_INFO("server", "CalendarHandler: Player with guid %llu attempt to %s an event with invalid name or description (packet modification)", (unsigned long long)playerGUID, action.c_str());
LOG_INFO("server", "CalendarHandler: Player (%s) attempt to %s an event with invalid name or description (packet modification)",
playerGUID.ToString().c_str(), action.c_str());
recvData.rfinish();
return false;
}
@@ -220,7 +220,7 @@ bool validUtf8String(WorldPacket& recvData, std::string& s, std::string action,
void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
std::string title;
std::string description;
@@ -293,23 +293,22 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
time_t(eventPackedTime), flags, time_t(unkPackedTime), title, description);
if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement())
if (Player* creator = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
if (Player* creator = ObjectAccessor::FindConnectedPlayer(guid))
calendarEvent->SetGuildId(creator->GetGuildId());
if (calendarEvent->IsGuildAnnouncement())
{
// 946684800 is 01/01/2000 00:00:00 - default response time
CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), 0, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, "");
CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), ObjectGuid::Empty, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, "");
sCalendarMgr->AddInvite(calendarEvent, invite);
}
else
{
uint32 inviteCount;
uint64 invitee[CALENDAR_MAX_INVITES];
ObjectGuid invitee[CALENDAR_MAX_INVITES];
uint8 status[CALENDAR_MAX_INVITES];
uint8 rank[CALENDAR_MAX_INVITES];
memset(invitee, 0, sizeof(invitee));
memset(status, 0, sizeof(status));
memset(rank, 0, sizeof(rank));
@@ -319,7 +318,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
for (uint32 i = 0; i < inviteCount && i < CALENDAR_MAX_INVITES; ++i)
{
recvData.readPackGUID(invitee[i]);
recvData >> invitee[i].ReadAsPacked();
recvData >> status[i] >> rank[i];
}
}
@@ -350,7 +349,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
time_t oldEventTime;
uint64 eventId;
@@ -382,10 +381,10 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData)
return;
}
LOG_DEBUG("network", "CMSG_CALENDAR_UPDATE_EVENT [" UI64FMTD "] EventId [" UI64FMTD
LOG_DEBUG("network", "CMSG_CALENDAR_UPDATE_EVENT [%s] EventId [" UI64FMTD
"], InviteId [" UI64FMTD "] Title %s, Description %s, type %u "
"Repeatable %u, MaxInvites %u, Dungeon ID %d, Time %u "
"Time2 %u, Flags %u", guid, eventId, inviteId, title.c_str(),
"Time2 %u, Flags %u", guid.ToString().c_str(), eventId, inviteId, title.c_str(),
description.c_str(), type, repetitionType, maxInvites, dungeonId,
eventPackedTime, timeZoneTime, flags);
@@ -410,7 +409,7 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData)
void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint64 eventId;
recvData >> eventId;
@@ -421,15 +420,15 @@ void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recvData)
void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint64 eventId;
uint64 inviteId;
uint32 eventTime;
recvData >> eventId >> inviteId;
recvData.ReadPackedTime(eventTime);
LOG_DEBUG("network", "CMSG_CALENDAR_COPY_EVENT [" UI64FMTD "], EventId [" UI64FMTD
"] inviteId [" UI64FMTD "] Time: %u", guid, eventId, inviteId, eventTime);
LOG_DEBUG("network", "CMSG_CALENDAR_COPY_EVENT [%s], EventId [" UI64FMTD
"] inviteId [" UI64FMTD "] Time: %u", guid.ToString().c_str(), eventId, inviteId, eventTime);
// prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack
@@ -509,7 +508,7 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
{
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_INVITE");
uint64 playerGuid = _player->GetGUID();
ObjectGuid playerGuid = _player->GetGUID();
uint64 eventId;
uint64 inviteId;
@@ -517,7 +516,7 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
bool isPreInvite;
bool isGuildEvent;
uint64 inviteeGuid = 0;
ObjectGuid inviteeGuid;
uint32 inviteeTeamId = TEAM_NEUTRAL;
uint32 inviteeGuildId = 0;
@@ -533,11 +532,11 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
else
{
// xinef: Get Data From global storage
if (uint32 guidLow = sWorld->GetGlobalPlayerGUID(name))
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guidLow))
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
{
inviteeGuid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
inviteeGuid = guid;
inviteeTeamId = Player::TeamIdForRace(playerData->race);
inviteeGuildId = playerData->guildId;
}
@@ -557,7 +556,7 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
}
// xinef: zomg! sync query
if (QueryResult result = CharacterDatabase.PQuery("SELECT flags FROM character_social WHERE guid = " UI64FMTD " AND friend = " UI64FMTD, inviteeGuid, playerGuid))
if (QueryResult result = CharacterDatabase.PQuery("SELECT flags FROM character_social WHERE guid = %u AND friend = %u", inviteeGuid.GetCounter(), playerGuid.GetCounter()))
{
Field* fields = result->Fetch();
if (fields[0].GetUInt8() & SOCIAL_FLAG_IGNORED)
@@ -601,12 +600,12 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
void WorldSession::HandleCalendarEventSignup(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint64 eventId;
bool tentative;
recvData >> eventId >> tentative;
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_SIGNUP [" UI64FMTD "] EventId [" UI64FMTD "] Tentative %u", guid, eventId, tentative);
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_SIGNUP [%s] EventId [" UI64FMTD "] Tentative %u", guid.ToString().c_str(), eventId, tentative);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
{
@@ -627,14 +626,14 @@ void WorldSession::HandleCalendarEventSignup(WorldPacket& recvData)
void WorldSession::HandleCalendarEventRsvp(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint64 eventId;
uint64 inviteId;
uint32 status;
recvData >> eventId >> inviteId >> status;
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_RSVP [" UI64FMTD"] EventId ["
UI64FMTD "], InviteId [" UI64FMTD "], status %u", guid, eventId,
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_RSVP [%s] EventId ["
UI64FMTD "], InviteId [" UI64FMTD "], status %u", guid.ToString().c_str(), eventId,
inviteId, status);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
@@ -664,19 +663,17 @@ void WorldSession::HandleCalendarEventRsvp(WorldPacket& recvData)
void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
uint64 invitee;
ObjectGuid guid = _player->GetGUID();
ObjectGuid invitee;
uint64 eventId;
uint64 ownerInviteId; // isn't it sender's inviteId?
uint64 inviteId;
recvData.readPackGUID(invitee);
recvData>> invitee.ReadAsPacked();
recvData >> inviteId >> ownerInviteId >> eventId;
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_REMOVE_INVITE ["
UI64FMTD "] EventId [" UI64FMTD "], ownerInviteId ["
UI64FMTD "], Invitee ([" UI64FMTD "] id: [" UI64FMTD "])",
guid, eventId, ownerInviteId, invitee, inviteId);
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_REMOVE_INVITE [%s] EventId [" UI64FMTD "], ownerInviteId [" UI64FMTD "], Invitee ([%s] id: [" UI64FMTD "])",
guid.ToString().c_str(), eventId, ownerInviteId, invitee.ToString().c_str(), inviteId);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
{
@@ -694,18 +691,17 @@ void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recvData)
void WorldSession::HandleCalendarEventStatus(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
uint64 invitee;
ObjectGuid guid = _player->GetGUID();
ObjectGuid invitee;
uint64 eventId;
uint64 inviteId;
uint64 ownerInviteId; // isn't it sender's inviteId?
uint8 status;
recvData.readPackGUID(invitee);
recvData >> invitee.ReadAsPacked();
recvData >> eventId >> inviteId >> ownerInviteId >> status;
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_STATUS [" UI64FMTD"] EventId ["
UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: ["
UI64FMTD "], status %u", guid, eventId, ownerInviteId, invitee, inviteId, status);
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_STATUS [%s] EventId [" UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee (%s) id: [" UI64FMTD "], status %u",
guid.ToString().c_str(), eventId, ownerInviteId, invitee.ToString().c_str(), inviteId, status);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
{
@@ -728,18 +724,18 @@ void WorldSession::HandleCalendarEventStatus(WorldPacket& recvData)
void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
uint64 invitee;
ObjectGuid guid = _player->GetGUID();
ObjectGuid invitee;
uint64 eventId;
uint64 inviteId;
uint64 ownerInviteId; // isn't it sender's inviteId?
uint8 rank;
recvData.readPackGUID(invitee);
recvData>> invitee.ReadAsPacked();
recvData >> eventId >> inviteId >> ownerInviteId >> rank;
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_MODERATOR_STATUS [" UI64FMTD "] EventId ["
UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: ["
UI64FMTD "], rank %u", guid, eventId, ownerInviteId, invitee, inviteId, rank);
LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_MODERATOR_STATUS [%s] EventId ["
UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee ([%s] id: ["
UI64FMTD "], rank %u", guid.ToString().c_str(), eventId, ownerInviteId, invitee.ToString().c_str(), inviteId, rank);
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
{
@@ -758,24 +754,23 @@ void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recvData)
void WorldSession::HandleCalendarComplain(WorldPacket& recvData)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint64 eventId;
uint64 complainGUID;
ObjectGuid complainGUID;
recvData >> eventId >> complainGUID;
LOG_DEBUG("network", "CMSG_CALENDAR_COMPLAIN [" UI64FMTD "] EventId ["
UI64FMTD "] guid [" UI64FMTD "]", guid, eventId, complainGUID);
LOG_DEBUG("network", "CMSG_CALENDAR_COMPLAIN [%s] EventId ["
UI64FMTD "] guid [%s]", guid.ToString().c_str(), eventId, complainGUID.ToString().c_str());
// what to do with complains?
}
void WorldSession::HandleCalendarGetNumPending(WorldPacket& /*recvData*/)
{
uint64 guid = _player->GetGUID();
ObjectGuid guid = _player->GetGUID();
uint32 pending = sCalendarMgr->GetPlayerNumPending(guid);
LOG_DEBUG("network", "CMSG_CALENDAR_GET_NUM_PENDING: [" UI64FMTD
"] Pending: %u", guid, pending);
LOG_DEBUG("network", "CMSG_CALENDAR_GET_NUM_PENDING: [%s] Pending: %u", guid.ToString().c_str(), pending);
WorldPacket data(SMSG_CALENDAR_SEND_NUM_PENDING, 4);
data << uint32(pending);
@@ -792,7 +787,7 @@ void WorldSession::HandleSetSavedInstanceExtend(WorldPacket& recvData)
if (!entry || !entry->IsRaid())
return;
InstancePlayerBind* instanceBind = sInstanceSaveMgr->PlayerGetBoundInstance(GetPlayer()->GetGUIDLow(), mapId, Difficulty(difficulty));
InstancePlayerBind* instanceBind = sInstanceSaveMgr->PlayerGetBoundInstance(GetPlayer()->GetGUID(), mapId, Difficulty(difficulty));
if (!instanceBind || !instanceBind->perm || (bool)toggleExtendOn == instanceBind->extended)
return;
@@ -801,7 +796,7 @@ void WorldSession::HandleSetSavedInstanceExtend(WorldPacket& recvData)
// update in db
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INSTANCE_EXTENDED);
stmt->setUInt8(0, toggleExtendOn ? 1 : 0);
stmt->setUInt32(1, GetPlayer()->GetGUIDLow());
stmt->setUInt32(1, GetPlayer()->GetGUID().GetCounter());
stmt->setUInt32(2, instanceBind->save->GetInstanceId());
CharacterDatabase.Execute(stmt);
@@ -825,7 +820,7 @@ void WorldSession::SendCalendarRaidLockout(InstanceSave const* save, bool add)
data << uint32(save->GetMapId());
data << uint32(save->GetDifficulty());
data << uint32(save->GetResetTime() >= currTime ? save->GetResetTime() - currTime : 0);
data << uint64(MAKE_NEW_GUID(save->GetInstanceId(), 0, HIGHGUID_INSTANCE));
data << ObjectGuid::Create<HighGuid::Instance>(save->GetInstanceId());
SendPacket(&data);
}