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

@@ -55,7 +55,7 @@ void CalendarMgr::LoadFromDB()
Field* fields = result->Fetch();
uint64 eventId = fields[0].GetUInt64();
uint64 creatorGUID = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER);
ObjectGuid creatorGUID = ObjectGuid::Create<HighGuid::Player>(fields[1].GetUInt32());
std::string title = fields[2].GetString();
std::string description = fields[3].GetString();
CalendarEventType type = CalendarEventType(fields[4].GetUInt8());
@@ -66,7 +66,7 @@ void CalendarMgr::LoadFromDB()
uint32 guildId = 0;
if (flags & CALENDAR_FLAG_GUILD_EVENT || flags & CALENDAR_FLAG_WITHOUT_INVITES)
guildId = Player::GetGuildIdFromStorage(GUID_LOPART(creatorGUID));
guildId = Player::GetGuildIdFromStorage(creatorGUID.GetCounter());
CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID, guildId, type, dungeonId, time_t(eventTime), flags, time_t(timezoneTime), title, description);
_events.insert(calendarEvent);
@@ -87,8 +87,8 @@ void CalendarMgr::LoadFromDB()
uint64 inviteId = fields[0].GetUInt64();
uint64 eventId = fields[1].GetUInt64();
uint64 invitee = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER);
uint64 senderGUID = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER);
ObjectGuid invitee = ObjectGuid::Create<HighGuid::Player>(fields[2].GetUInt32());
ObjectGuid senderGUID = ObjectGuid::Create<HighGuid::Player>(fields[3].GetUInt32());
CalendarInviteStatus status = CalendarInviteStatus(fields[4].GetUInt8());
uint32 statusTime = fields[5].GetUInt32();
CalendarModerationRank rank = CalendarModerationRank(fields[6].GetUInt8());
@@ -142,7 +142,7 @@ void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite
}
}
void CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover)
void CalendarMgr::RemoveEvent(uint64 eventId, ObjectGuid remover)
{
CalendarEvent* calendarEvent = GetEvent(eventId);
@@ -155,7 +155,7 @@ void CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover)
RemoveEvent(calendarEvent, remover);
}
void CalendarMgr::RemoveEvent(CalendarEvent* calendarEvent, uint64 remover)
void CalendarMgr::RemoveEvent(CalendarEvent* calendarEvent, ObjectGuid remover)
{
if (!calendarEvent)
{
@@ -180,7 +180,7 @@ void CalendarMgr::RemoveEvent(CalendarEvent* calendarEvent, uint64 remover)
// guild events only? check invite status here?
// When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki)
if (remover && invite->GetInviteeGUID() != remover)
mail.SendMailTo(trans, MailReceiver(invite->GetInviteeGUID()), calendarEvent, MAIL_CHECK_MASK_COPIED);
mail.SendMailTo(trans, MailReceiver(invite->GetInviteeGUID().GetCounter()), calendarEvent, MAIL_CHECK_MASK_COPIED);
delete invite;
}
@@ -197,7 +197,7 @@ void CalendarMgr::RemoveEvent(CalendarEvent* calendarEvent, uint64 remover)
return;
}
void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, uint64 /*remover*/)
void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, ObjectGuid /*remover*/)
{
CalendarEvent* calendarEvent = GetEvent(eventId);
@@ -236,7 +236,7 @@ void CalendarMgr::UpdateEvent(CalendarEvent* calendarEvent)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_EVENT);
stmt->setUInt64(0, calendarEvent->GetEventId());
stmt->setUInt32(1, GUID_LOPART(calendarEvent->GetCreatorGUID()));
stmt->setUInt32(1, calendarEvent->GetCreatorGUID().GetCounter());
stmt->setString(2, calendarEvent->GetTitle());
stmt->setString(3, calendarEvent->GetDescription());
stmt->setUInt8(4, calendarEvent->GetType());
@@ -258,8 +258,8 @@ void CalendarMgr::UpdateInvite(CalendarInvite* invite, SQLTransaction& trans)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_INVITE);
stmt->setUInt64(0, invite->GetInviteId());
stmt->setUInt64(1, invite->GetEventId());
stmt->setUInt32(2, GUID_LOPART(invite->GetInviteeGUID()));
stmt->setUInt32(3, GUID_LOPART(invite->GetSenderGUID()));
stmt->setUInt32(2, invite->GetInviteeGUID().GetCounter());
stmt->setUInt32(3, invite->GetSenderGUID().GetCounter());
stmt->setUInt8(4, invite->GetStatus());
stmt->setUInt32(5, uint32(invite->GetStatusTime()));
stmt->setUInt8(6, invite->GetRank());
@@ -267,7 +267,7 @@ void CalendarMgr::UpdateInvite(CalendarInvite* invite, SQLTransaction& trans)
CharacterDatabase.ExecuteOrAppend(trans, stmt);
}
void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
void CalendarMgr::RemoveAllPlayerEventsAndInvites(ObjectGuid guid)
{
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end();)
{
@@ -275,7 +275,7 @@ void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
++itr;
if (event->GetCreatorGUID() == guid)
{
RemoveEvent(event, 0);
RemoveEvent(event, ObjectGuid::Empty);
continue;
}
}
@@ -285,7 +285,7 @@ void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid);
}
void CalendarMgr::RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId)
void CalendarMgr::RemovePlayerGuildEventsAndSignups(ObjectGuid guid, uint32 guildId)
{
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
if ((*itr)->GetCreatorGUID() == guid && ((*itr)->IsGuildEvent() || (*itr)->IsGuildAnnouncement()))
@@ -365,11 +365,11 @@ void CalendarMgr::DeleteOldEvents()
CalendarEvent* event = *itr;
++itr;
if (event->GetEventTime() < oldEventsTime)
RemoveEvent(event, 0);
RemoveEvent(event, ObjectGuid::Empty);
}
}
CalendarEventStore CalendarMgr::GetEventsCreatedBy(uint64 guid, bool includeGuildEvents)
CalendarEventStore CalendarMgr::GetEventsCreatedBy(ObjectGuid guid, bool includeGuildEvents)
{
CalendarEventStore result;
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
@@ -394,7 +394,7 @@ CalendarEventStore CalendarMgr::GetGuildEvents(uint32 guildId)
return result;
}
CalendarEventStore CalendarMgr::GetPlayerEvents(uint64 guid)
CalendarEventStore CalendarMgr::GetPlayerEvents(ObjectGuid guid)
{
CalendarEventStore events;
@@ -404,7 +404,7 @@ CalendarEventStore CalendarMgr::GetPlayerEvents(uint64 guid)
if (CalendarEvent* event = GetEvent(itr->first)) // nullptr check added as attempt to fix #11512
events.insert(event);
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
if (player->GetGuildId())
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
if ((*itr)->GetGuildId() == player->GetGuildId())
@@ -418,7 +418,7 @@ CalendarInviteStore const& CalendarMgr::GetEventInvites(uint64 eventId)
return _invites[eventId];
}
CalendarInviteStore CalendarMgr::GetPlayerInvites(uint64 guid)
CalendarInviteStore CalendarMgr::GetPlayerInvites(ObjectGuid guid)
{
CalendarInviteStore invites;
@@ -430,7 +430,7 @@ CalendarInviteStore CalendarMgr::GetPlayerInvites(uint64 guid)
return invites;
}
uint32 CalendarMgr::GetPlayerNumPending(uint64 guid)
uint32 CalendarMgr::GetPlayerNumPending(ObjectGuid guid)
{
CalendarInviteStore const& invites = GetPlayerInvites(guid);
@@ -452,10 +452,10 @@ uint32 CalendarMgr::GetPlayerNumPending(uint64 guid)
return pendingNum;
}
std::string CalendarEvent::BuildCalendarMailSubject(uint64 remover) const
std::string CalendarEvent::BuildCalendarMailSubject(ObjectGuid remover) const
{
std::ostringstream strm;
strm << remover << ':' << _title;
strm << remover.ToString().c_str() << ':' << _title;
return strm.str();
}
@@ -478,13 +478,13 @@ void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite)
time_t statusTime = invite.GetStatusTime();
bool hasStatusTime = statusTime != 946684800; // 01/01/2000 00:00:00
uint64 invitee = invite.GetInviteeGUID();
Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(invitee);
ObjectGuid invitee = invite.GetInviteeGUID();
Player* player = ObjectAccessor::FindConnectedPlayer(invitee);
uint8 level = player ? player->getLevel() : Player::GetLevelFromStorage(invitee);
uint8 level = player ? player->getLevel() : Player::GetLevelFromStorage(invitee.GetCounter());
WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (statusTime ? 4 : 0) + 1);
data.appendPackGUID(invitee);
data << invitee.WriteAsPacked();
data << uint64(invite.GetEventId());
data << uint64(invite.GetInviteId());
data << uint8(level);
@@ -496,7 +496,7 @@ void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite)
if (!calendarEvent) // Pre-invite
{
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(invite.GetSenderGUID()))
if (Player* player = ObjectAccessor::FindConnectedPlayer(invite.GetSenderGUID()))
player->SendDirectMessage(&data);
}
else
@@ -529,7 +529,7 @@ void CalendarMgr::SendCalendarEventUpdateAlert(CalendarEvent const& calendarEven
void CalendarMgr::SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite)
{
WorldPacket data(SMSG_CALENDAR_EVENT_STATUS, 8 + 8 + 4 + 4 + 1 + 1 + 4);
data.appendPackGUID(invite.GetInviteeGUID());
data << invite.GetInviteeGUID().WriteAsPacked();
data << uint64(calendarEvent.GetEventId());
data.AppendPackedTime(calendarEvent.GetEventTime());
data << uint32(calendarEvent.GetFlags());
@@ -553,7 +553,7 @@ void CalendarMgr::SendCalendarEventRemovedAlert(CalendarEvent const& calendarEve
void CalendarMgr::SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags)
{
WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED, 8 + 4 + 4 + 1);
data.appendPackGUID(invite.GetInviteeGUID());
data<< invite.GetInviteeGUID().WriteAsPacked();
data << uint64(invite.GetEventId());
data << uint32(flags);
data << uint8(1); // FIXME
@@ -564,7 +564,7 @@ void CalendarMgr::SendCalendarEventInviteRemove(CalendarEvent const& calendarEve
void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite)
{
WorldPacket data(SMSG_CALENDAR_EVENT_MODERATOR_STATUS_ALERT, 8 + 8 + 1 + 1);
data.appendPackGUID(invite.GetInviteeGUID());
data << invite.GetInviteeGUID().WriteAsPacked();
data << uint64(invite.GetEventId());
data << uint8(invite.GetRank());
data << uint8(1); // Unk boolean - Display to client?
@@ -584,21 +584,21 @@ void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEven
data << uint64(invite.GetInviteId());
data << uint8(invite.GetStatus());
data << uint8(invite.GetRank());
data.appendPackGUID(calendarEvent.GetCreatorGUID());
data.appendPackGUID(invite.GetSenderGUID());
data << calendarEvent.GetCreatorGUID().WriteAsPacked();
data << invite.GetSenderGUID().WriteAsPacked();
if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
{
if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId()))
guild->BroadcastPacket(&data);
}
else if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(invite.GetInviteeGUID()))
else if (Player* player = ObjectAccessor::FindConnectedPlayer(invite.GetInviteeGUID()))
player->SendDirectMessage(&data);
}
void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType)
void CalendarMgr::SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType)
{
Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid);
Player* player = ObjectAccessor::FindConnectedPlayer(guid);
if (!player)
return;
@@ -606,7 +606,7 @@ void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEv
WorldPacket data(SMSG_CALENDAR_SEND_EVENT, 60 + eventInviteeList.size() * 32);
data << uint8(sendType);
data.appendPackGUID(calendarEvent.GetCreatorGUID());
data << calendarEvent.GetCreatorGUID().WriteAsPacked();
data << uint64(calendarEvent.GetEventId());
data << calendarEvent.GetTitle();
data << calendarEvent.GetDescription();
@@ -623,13 +623,13 @@ void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEv
for (CalendarInviteStore::const_iterator itr = eventInviteeList.begin(); itr != eventInviteeList.end(); ++itr)
{
CalendarInvite const* calendarInvite = (*itr);
uint64 inviteeGuid = calendarInvite->GetInviteeGUID();
Player* invitee = ObjectAccessor::FindPlayerInOrOutOfWorld(inviteeGuid);
ObjectGuid inviteeGuid = calendarInvite->GetInviteeGUID();
Player* invitee = ObjectAccessor::FindConnectedPlayer(inviteeGuid);
uint8 inviteeLevel = invitee ? invitee->getLevel() : Player::GetLevelFromStorage(inviteeGuid);
uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : Player::GetGuildIdFromStorage(GUID_LOPART(inviteeGuid));
uint8 inviteeLevel = invitee ? invitee->getLevel() : Player::GetLevelFromStorage(inviteeGuid.GetCounter());
uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : Player::GetGuildIdFromStorage(inviteeGuid.GetCounter());
data.appendPackGUID(inviteeGuid);
data << inviteeGuid.WriteAsPacked();
data << uint8(inviteeLevel);
data << uint8(calendarInvite->GetStatus());
data << uint8(calendarInvite->GetRank());
@@ -642,9 +642,9 @@ void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEv
player->SendDirectMessage(&data);
}
void CalendarMgr::SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status)
void CalendarMgr::SendCalendarEventInviteRemoveAlert(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status)
{
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
{
WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED_ALERT, 8 + 4 + 4 + 1);
data << uint64(calendarEvent.GetEventId());
@@ -656,18 +656,18 @@ void CalendarMgr::SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent
}
}
void CalendarMgr::SendCalendarClearPendingAction(uint64 guid)
void CalendarMgr::SendCalendarClearPendingAction(ObjectGuid guid)
{
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
{
WorldPacket data(SMSG_CALENDAR_CLEAR_PENDING_ACTION, 0);
player->SendDirectMessage(&data);
}
}
void CalendarMgr::SendCalendarCommandResult(uint64 guid, CalendarError err, char const* param /*= nullptr*/)
void CalendarMgr::SendCalendarCommandResult(ObjectGuid guid, CalendarError err, char const* param /*= nullptr*/)
{
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
{
WorldPacket data(SMSG_CALENDAR_COMMAND_RESULT, 0);
data << uint32(0);
@@ -700,7 +700,7 @@ void CalendarMgr::SendPacketToAllEventRelatives(WorldPacket packet, CalendarEven
// Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them)
CalendarInviteStore invites = _invites[calendarEvent.GetEventId()];
for (CalendarInviteStore::iterator itr = invites.begin(); itr != invites.end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld((*itr)->GetInviteeGUID()))
if (Player* player = ObjectAccessor::FindConnectedPlayer((*itr)->GetInviteeGUID()))
if (!calendarEvent.IsGuildEvent() || player->GetGuildId() != calendarEvent.GetGuildId())
player->SendDirectMessage(&packet);
}