aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers/CalendarHandler.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-11-21 12:25:22 +0100
committerShauren <shauren.trinity@gmail.com>2023-11-21 12:25:22 +0100
commitb888b1b09f71a8b8b4a9d45c804a1f164fb65ac3 (patch)
treeba507c4c1c5e8487bd223afbde44ecf9eeac162e /src/server/game/Handlers/CalendarHandler.cpp
parent8c072b93af3a4efcbde21cc85fedcf7fa48fa7b4 (diff)
Core/Calendar: Implement different timezone support for ingame calendar
Closes #8390 Closes #29427
Diffstat (limited to 'src/server/game/Handlers/CalendarHandler.cpp')
-rw-r--r--src/server/game/Handlers/CalendarHandler.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp
index 209babfec10..ab512f54eec 100644
--- a/src/server/game/Handlers/CalendarHandler.cpp
+++ b/src/server/game/Handlers/CalendarHandler.cpp
@@ -39,7 +39,6 @@ Copied events should probably have a new owner
#include "CalendarPackets.h"
#include "CharacterCache.h"
#include "DatabaseEnv.h"
-#include "DB2Stores.h"
#include "GameTime.h"
#include "Guild.h"
#include "GuildMgr.h"
@@ -49,16 +48,14 @@ Copied events should probably have a new owner
#include "ObjectMgr.h"
#include "Player.h"
#include "SocialMgr.h"
-#include "Util.h"
#include "World.h"
void WorldSession::HandleCalendarGetCalendar(WorldPackets::Calendar::CalendarGetCalendar& /*calendarGetCalendar*/)
{
ObjectGuid guid = _player->GetGUID();
- time_t currTime = GameTime::GetGameTime();
WorldPackets::Calendar::CalendarSendCalendar packet;
- packet.ServerTime = currTime;
+ packet.ServerTime = *GameTime::GetWowTime();
CalendarInviteStore playerInvites = sCalendarMgr->GetPlayerInvites(guid);
for (CalendarInvite const* invite : playerInvites)
@@ -78,7 +75,8 @@ void WorldSession::HandleCalendarGetCalendar(WorldPackets::Calendar::CalendarGet
{
WorldPackets::Calendar::CalendarSendCalendarEventInfo& eventInfo = packet.Events.emplace_back();
eventInfo.EventID = event->GetEventId();
- eventInfo.Date = event->GetDate();
+ eventInfo.Date.SetUtcTimeFromUnixTime(event->GetDate());
+ eventInfo.Date += GetTimezoneOffset();
eventInfo.EventClubID = event->GetGuildId();
eventInfo.EventName = event->GetTitle();
eventInfo.EventType = event->GetType();
@@ -117,11 +115,10 @@ void WorldSession::HandleCalendarAddEvent(WorldPackets::Calendar::CalendarAddEve
{
ObjectGuid guid = _player->GetGUID();
- calendarAddEvent.EventInfo.Time = uint32(LocalTimeToUTCTime(calendarAddEvent.EventInfo.Time));
+ calendarAddEvent.EventInfo.Time -= GetTimezoneOffset();
// prevent events in the past
- // To Do: properly handle timezones and remove the "- time_t(86400L)" hack
- if (calendarAddEvent.EventInfo.Time < (GameTime::GetGameTime() - time_t(86400L)))
+ if (calendarAddEvent.EventInfo.Time < *GameTime::GetUtcWowTime())
{
sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_PASSED);
return;
@@ -163,7 +160,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPackets::Calendar::CalendarAddEve
SetCalendarEventCreationCooldown(GameTime::GetGameTime() + CALENDAR_CREATE_EVENT_COOLDOWN);
CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, UI64LIT(0), CalendarEventType(calendarAddEvent.EventInfo.EventType), calendarAddEvent.EventInfo.TextureID,
- calendarAddEvent.EventInfo.Time, calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, time_t(0));
+ calendarAddEvent.EventInfo.Time.GetUnixTimeFromUtcTime(), calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, time_t(0));
if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement())
calendarEvent->SetGuildId(_player->GetGuildId());
@@ -201,11 +198,10 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPackets::Calendar::CalendarUpd
ObjectGuid guid = _player->GetGUID();
time_t oldEventTime = time_t(0);
- calendarUpdateEvent.EventInfo.Time = uint32(LocalTimeToUTCTime(calendarUpdateEvent.EventInfo.Time));
+ calendarUpdateEvent.EventInfo.Time -= GetTimezoneOffset();
// prevent events in the past
- // To Do: properly handle timezones and remove the "- time_t(86400L)" hack
- if (calendarUpdateEvent.EventInfo.Time < (GameTime::GetGameTime() - time_t(86400L)))
+ if (calendarUpdateEvent.EventInfo.Time < *GameTime::GetUtcWowTime())
return;
if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(calendarUpdateEvent.EventInfo.EventID))
@@ -214,7 +210,7 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPackets::Calendar::CalendarUpd
calendarEvent->SetType(CalendarEventType(calendarUpdateEvent.EventInfo.EventType));
calendarEvent->SetFlags(calendarUpdateEvent.EventInfo.Flags);
- calendarEvent->SetDate(calendarUpdateEvent.EventInfo.Time);
+ calendarEvent->SetDate(calendarUpdateEvent.EventInfo.Time.GetUnixTimeFromUtcTime());
calendarEvent->SetTextureId(calendarUpdateEvent.EventInfo.TextureID);
calendarEvent->SetTitle(calendarUpdateEvent.EventInfo.Title);
calendarEvent->SetDescription(calendarUpdateEvent.EventInfo.Description);
@@ -236,11 +232,10 @@ void WorldSession::HandleCalendarCopyEvent(WorldPackets::Calendar::CalendarCopyE
{
ObjectGuid guid = _player->GetGUID();
- calendarCopyEvent.Date = uint32(LocalTimeToUTCTime(calendarCopyEvent.Date));
+ calendarCopyEvent.Date -= GetTimezoneOffset();
// prevent events in the past
- // To Do: properly handle timezones and remove the "- time_t(86400L)" hack
- if (calendarCopyEvent.Date < (GameTime::GetGameTime() - time_t(86400L)))
+ if (calendarCopyEvent.Date < *GameTime::GetUtcWowTime())
{
sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_PASSED);
return;
@@ -292,7 +287,7 @@ void WorldSession::HandleCalendarCopyEvent(WorldPackets::Calendar::CalendarCopyE
SetCalendarEventCreationCooldown(GameTime::GetGameTime() + CALENDAR_CREATE_EVENT_COOLDOWN);
CalendarEvent* newEvent = new CalendarEvent(*oldEvent, sCalendarMgr->GetFreeEventId());
- newEvent->SetDate(calendarCopyEvent.Date);
+ newEvent->SetDate(calendarCopyEvent.Date.GetUnixTimeFromUtcTime());
sCalendarMgr->AddEvent(newEvent, CALENDAR_SENDTYPE_COPY);
CalendarInviteStore invites = sCalendarMgr->GetEventInvites(calendarCopyEvent.EventID);
@@ -550,7 +545,7 @@ void WorldSession::HandleSetSavedInstanceExtend(WorldPackets::Calendar::SetSaved
return;
WorldPackets::Calendar::CalendarRaidLockoutUpdated calendarRaidLockoutUpdated;
- calendarRaidLockoutUpdated.ServerTime = GameTime::GetGameTime();
+ calendarRaidLockoutUpdated.ServerTime = *GameTime::GetWowTime();
calendarRaidLockoutUpdated.MapID = setSavedInstanceExtend.MapID;
calendarRaidLockoutUpdated.DifficultyID = setSavedInstanceExtend.DifficultyID;
calendarRaidLockoutUpdated.OldTimeRemaining = std::max(std::chrono::duration_cast<Seconds>(expiryTimes.first - GameTime::GetSystemTime()).count(), SI64LIT(0));