aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2019-04-19 23:45:07 +0200
committerjackpoz <giacomopoz@gmail.com>2019-04-19 23:45:07 +0200
commitb33934f6ce9b0227597c712dd6a76b7ed49deea3 (patch)
treef64ecc410dd4282ddc145f5f0527ef3b841f8a02 /src
parent3d3b7f438c6638aed998f4233b809826a3cf0f54 (diff)
Core/Calendar: Improve calendar timezone handling
Improve calendar timezone handling by at least creating events with the correct time if both client and server are in the same timezone. There is currently no information received from the client about in which timezone it is.
Diffstat (limited to 'src')
-rw-r--r--src/common/Utilities/Util.cpp9
-rw-r--r--src/common/Utilities/Util.h1
-rw-r--r--src/server/game/Handlers/CalendarHandler.cpp6
3 files changed, 16 insertions, 0 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index 668b1a9dce7..53365373eb4 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -77,6 +77,15 @@ struct tm* localtime_r(time_t const* time, struct tm *result)
}
#endif
+time_t LocalTimeToUTCTime(time_t time)
+{
+#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
+ return time + _timezone;
+#else
+ return time + timezone;
+#endif
+}
+
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
{
uint64 secs = timeInSecs % MINUTE;
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index 78019885d99..193981e31ae 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -58,6 +58,7 @@ private:
TC_COMMON_API int32 MoneyStringToMoney(std::string const& moneyString);
TC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm *result);
+TC_COMMON_API time_t LocalTimeToUTCTime(time_t time);
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
TC_COMMON_API uint32 TimeStringToSecs(std::string const& timestring);
diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp
index 9fb058dff0d..45afefda920 100644
--- a/src/server/game/Handlers/CalendarHandler.cpp
+++ b/src/server/game/Handlers/CalendarHandler.cpp
@@ -238,6 +238,8 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
recvData.ReadPackedTime(unkPackedTime);
recvData >> flags;
+ eventPackedTime = uint32(LocalTimeToUTCTime(eventPackedTime));
+
// prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack
if (time_t(eventPackedTime) < (GameTime::GetGameTime() - time_t(86400L)))
@@ -331,6 +333,8 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData)
recvData.ReadPackedTime(timeZoneTime);
recvData >> flags;
+ eventPackedTime = uint32(LocalTimeToUTCTime(eventPackedTime));
+
// prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack
if (time_t(eventPackedTime) < (GameTime::GetGameTime() - time_t(86400L)))
@@ -388,6 +392,8 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData)
TC_LOG_DEBUG("network", "CMSG_CALENDAR_COPY_EVENT [%s], EventId [" UI64FMTD
"] inviteId [" UI64FMTD "] Time: %u", guid.ToString().c_str(), eventId, inviteId, eventTime);
+ eventTime = uint32(LocalTimeToUTCTime(eventTime));
+
// prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack
if (time_t(eventTime) < (GameTime::GetGameTime() - time_t(86400L)))