diff --git a/Code/client/Services/CalendarService.h b/Code/client/Services/CalendarService.h index dd442b601..5c57d41a8 100644 --- a/Code/client/Services/CalendarService.h +++ b/Code/client/Services/CalendarService.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -32,13 +32,13 @@ class CalendarService final : public BSTEventSink entt::scoped_connection m_updateConnection; entt::scoped_connection m_disconnectedConnection; - DateTime m_onlineTime; - DateTime m_offlineTime; + TimeModel m_onlineTime; + TimeModel m_offlineTime; float m_fadeTimer = 0.f; + bool m_switchToOffline = false; static bool s_gameClockLocked; uint64_t m_lastTick = 0; - uint64_t m_lastLogTick = 0; World& m_world; TransportService& m_transport; }; diff --git a/Code/client/Services/Generic/CalendarService.cpp b/Code/client/Services/Generic/CalendarService.cpp index ef744924c..608eb5427 100644 --- a/Code/client/Services/Generic/CalendarService.cpp +++ b/Code/client/Services/Generic/CalendarService.cpp @@ -1,13 +1,13 @@ #include -#include +#include #include +#include #include -#include -#include -#include #include +#include +#include constexpr float kTransitionSpeed = 5.f; @@ -19,7 +19,8 @@ bool CalendarService::AllowGameTick() noexcept } CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, TransportService& aTransport) - : m_world(aWorld), m_transport(aTransport) + : m_world(aWorld) + , m_transport(aTransport) { m_timeUpdateConnection = aDispatcher.sink().connect<&CalendarService::OnTimeUpdate>(this); m_updateConnection = aDispatcher.sink().connect<&CalendarService::HandleUpdate>(this); @@ -29,29 +30,16 @@ CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher, T void CalendarService::OnTimeUpdate(const ServerTimeSettings& acMessage) noexcept { // disable the game clock + m_onlineTime.TimeScale = acMessage.TimeScale; + m_onlineTime.Time = acMessage.Time; ToggleGameClock(false); - m_onlineTime.m_timeModel.TimeScale = acMessage.timeModel.TimeScale; - m_onlineTime.m_timeModel.Time = acMessage.timeModel.Time; - - if (m_world.GetServerSettings().SyncPlayerCalendar) - { - m_onlineTime.m_timeModel.Day = acMessage.timeModel.Day; - m_onlineTime.m_timeModel.Month = acMessage.timeModel.Month; - m_onlineTime.m_timeModel.Year = acMessage.timeModel.Year; - } - else - { - m_onlineTime.m_timeModel.Day = m_offlineTime.m_timeModel.Day; - m_onlineTime.m_timeModel.Month = m_offlineTime.m_timeModel.Month; - m_onlineTime.m_timeModel.Year = m_offlineTime.m_timeModel.Year; - } } void CalendarService::OnDisconnected(const DisconnectedEvent&) noexcept { // signal a time transition m_fadeTimer = 0.f; - ToggleGameClock(true); + m_switchToOffline = true; } float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) const @@ -72,11 +60,24 @@ float CalendarService::TimeInterpolate(const TimeModel& aFrom, TimeModel& aTo) c void CalendarService::ToggleGameClock(bool aEnable) { auto* pGameTime = TimeData::Get(); - m_offlineTime.m_timeModel.Day = pGameTime->GameDay->f; - m_offlineTime.m_timeModel.Month = pGameTime->GameMonth->f; - m_offlineTime.m_timeModel.Year = pGameTime->GameYear->f; - m_offlineTime.m_timeModel.Time = pGameTime->GameHour->f; - m_offlineTime.m_timeModel.TimeScale = pGameTime->TimeScale->f; + if (aEnable) + { + pGameTime->GameDay->i = m_offlineTime.Day; + pGameTime->GameMonth->i = m_offlineTime.Month; + pGameTime->GameYear->i = m_offlineTime.Year; + pGameTime->TimeScale->f = m_offlineTime.TimeScale; + pGameTime->GameDaysPassed->f = (m_offlineTime.Time * (1.f / 24.f)) + m_offlineTime.Day; + pGameTime->GameHour->f = m_offlineTime.Time; + m_switchToOffline = false; + } + else + { + m_offlineTime.Day = pGameTime->GameDay->i; + m_offlineTime.Month = pGameTime->GameMonth->i; + m_offlineTime.Year = pGameTime->GameYear->i; + m_offlineTime.Time = pGameTime->GameHour->f; + m_offlineTime.TimeScale = pGameTime->TimeScale->f; + } s_gameClockLocked = !aEnable; } @@ -93,6 +94,23 @@ void CalendarService::HandleUpdate(const UpdateEvent& aEvent) noexcept const auto now = m_world.GetTick(); + if (m_switchToOffline) + { + // time transition out + if (m_fadeTimer < kTransitionSpeed) + { + pGameTime->GameHour->f = TimeInterpolate(m_onlineTime, m_offlineTime); + // before we quit here we fire this event + if ((m_fadeTimer + updateDelta) > kTransitionSpeed) + { + m_fadeTimer += updateDelta; + ToggleGameClock(true); + } + else + m_fadeTimer += updateDelta; + } + } + // we got disconnected or the client got ahead of us if (now < m_lastTick) return; @@ -101,19 +119,19 @@ void CalendarService::HandleUpdate(const UpdateEvent& aEvent) noexcept m_lastTick = now; m_onlineTime.Update(delta); - pGameTime->TimeScale->f = m_onlineTime.m_timeModel.TimeScale; - pGameTime->GameDay->f = m_onlineTime.m_timeModel.Day; - pGameTime->GameMonth->f = m_onlineTime.m_timeModel.Month; - pGameTime->GameYear->f = m_onlineTime.m_timeModel.Year; - pGameTime->GameDaysPassed->f += m_onlineTime.GetDeltaTime(delta); + pGameTime->GameDay->i = m_onlineTime.Day; + pGameTime->GameMonth->i = m_onlineTime.Month; + pGameTime->GameYear->i = m_onlineTime.Year; + pGameTime->TimeScale->f = m_onlineTime.TimeScale; + pGameTime->GameDaysPassed->f = (m_onlineTime.Time * (1.f / 24.f)) + m_onlineTime.Day; // time transition in if (m_fadeTimer < kTransitionSpeed) { - pGameTime->GameHour->f = TimeInterpolate(m_offlineTime.m_timeModel, m_onlineTime.m_timeModel); + pGameTime->GameHour->f = TimeInterpolate(m_offlineTime, m_onlineTime); m_fadeTimer += updateDelta; } else - pGameTime->GameHour->f = m_onlineTime.m_timeModel.Time; + pGameTime->GameHour->f = m_onlineTime.Time; } } diff --git a/Code/client/Services/Generic/TransportService.cpp b/Code/client/Services/Generic/TransportService.cpp index 1b48c29f9..81ad8b25d 100644 --- a/Code/client/Services/Generic/TransportService.cpp +++ b/Code/client/Services/Generic/TransportService.cpp @@ -11,8 +11,6 @@ #include #include -#include - #include #include #include @@ -153,13 +151,6 @@ void TransportService::OnConnected() request.Level = pPlayer->GetLevel(); - auto* pGameTime = TimeData::Get(); - request.PlayerTime.TimeScale = pGameTime->TimeScale->f; - request.PlayerTime.Time = pGameTime->GameHour->f; - request.PlayerTime.Year = pGameTime->GameYear->f; - request.PlayerTime.Month = pGameTime->GameMonth->f; - request.PlayerTime.Day = pGameTime->GameDay->f; - Send(request); } diff --git a/Code/common/DateTime.cpp b/Code/common/DateTime.cpp deleted file mode 100644 index b091ef615..000000000 --- a/Code/common/DateTime.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "DateTime.h" -#include - -bool DateTime::operator==(const DateTime& other) const -{ - return m_timeModel == other.m_timeModel; -} - -const uint32_t cDayLengthArray[12] = {31u, 28u, 31u, 30u, 31u, 30u, 31u, 31u, 30u, 31u, 30u, 31u}; - -uint32_t DateTime::GetNumberOfDaysByMonthIndex(int aIndex) -{ - return cDayLengthArray[aIndex % 12]; -} - -void DateTime::Update(uint64_t aDeltaTick) -{ - m_timeModel.Time += GetDeltaTime(aDeltaTick); - - m_timeModel.Day += static_cast(m_timeModel.Time / 24.f); - m_timeModel.Time = std::fmod(m_timeModel.Time, 24.f); - - while (m_timeModel.Day > GetNumberOfDaysByMonthIndex(m_timeModel.Month)) - { - m_timeModel.Day -= GetNumberOfDaysByMonthIndex(m_timeModel.Month); - m_timeModel.Month++; - } - m_timeModel.Year += m_timeModel.Month / 12; - m_timeModel.Month %= 12; -} - -float DateTime::GetDeltaTime(uint64_t aDeltaTick) const noexcept -{ - float deltaSeconds = static_cast(aDeltaTick) / 1000.f; - return (deltaSeconds * (m_timeModel.TimeScale * 0.00027777778f)); -} - -float DateTime::GetTimeInDays() const noexcept -{ - float totalDays = static_cast(m_timeModel.Year) * 365.f; - for (uint32_t i = 0u; i < m_timeModel.Month; i++) - totalDays += GetNumberOfDaysByMonthIndex(i); - totalDays += m_timeModel.Day; - totalDays += (m_timeModel.Time / 24.f); - return totalDays; -} diff --git a/Code/common/DateTime.h b/Code/common/DateTime.h deleted file mode 100644 index e5e7a758a..000000000 --- a/Code/common/DateTime.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include - -struct DateTime -{ - [[nodiscard]] static uint32_t GetNumberOfDaysByMonthIndex(int index); - - DateTime() = default; - DateTime(TimeModel aTimeModel) - : m_timeModel(aTimeModel) - {} - - bool operator==(const DateTime& other) const; - void Update(uint64_t aDeltaTick); - float GetDeltaTime(uint64_t aDeltaTick) const noexcept; - float GetTimeInDays() const noexcept; - - TimeModel m_timeModel; -}; diff --git a/Code/common/Structs/TimeModel.cpp b/Code/common/Structs/TimeModel.cpp new file mode 100644 index 000000000..e5d57e2d5 --- /dev/null +++ b/Code/common/Structs/TimeModel.cpp @@ -0,0 +1,43 @@ + +#include + +const int cDayLengthArray[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +int TimeModel::GetNumerOfDaysByMonthIndex(int aIndex) +{ + if (aIndex < 12) + { + return cDayLengthArray[aIndex]; + } + + return 0; +} + +void TimeModel::Update(uint64_t aDelta) +{ + float deltaSeconds = static_cast(aDelta) / 1000.f; + Time += (deltaSeconds * (TimeScale * 0.00027777778f)); + + if (Time > 24.f) + { + int maxDays = GetNumerOfDaysByMonthIndex(Month); + + while (Time > 24.f) + { + Time = Time + -24.f; + Day++; + } + + if (Day > maxDays) + { + Month++; + Day = Day - maxDays; + + if (Month > 12) + { + Month = Month + -12; + Year++; + } + } + } +} diff --git a/Code/common/Structs/TimeModel.h b/Code/common/Structs/TimeModel.h new file mode 100644 index 000000000..c56eabb76 --- /dev/null +++ b/Code/common/Structs/TimeModel.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +struct TimeModel +{ + // Default time: 01/01/01 at 12:00 + float TimeScale = 20.f; + float Time = 12.f; + int Year = 1; + int Month = 1; + int Day = 1; + + void Update(uint64_t aDelta); + [[nodiscard]] static int GetNumerOfDaysByMonthIndex(int index); +}; diff --git a/Code/encoding/Messages/AuthenticationRequest.cpp b/Code/encoding/Messages/AuthenticationRequest.cpp index 97d1fb712..f1a5d64f1 100644 --- a/Code/encoding/Messages/AuthenticationRequest.cpp +++ b/Code/encoding/Messages/AuthenticationRequest.cpp @@ -12,7 +12,6 @@ void AuthenticationRequest::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) WorldSpaceId.Serialize(aWriter); CellId.Serialize(aWriter); Serialization::WriteVarInt(aWriter, Level); - PlayerTime.Serialize(aWriter); } void AuthenticationRequest::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept @@ -29,5 +28,4 @@ void AuthenticationRequest::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReade WorldSpaceId.Deserialize(aReader); CellId.Deserialize(aReader); Level = Serialization::ReadVarInt(aReader) & 0xFFFF; - PlayerTime.Deserialize(aReader); } diff --git a/Code/encoding/Messages/AuthenticationRequest.h b/Code/encoding/Messages/AuthenticationRequest.h index 8fbec27dc..54ec7c5d0 100644 --- a/Code/encoding/Messages/AuthenticationRequest.h +++ b/Code/encoding/Messages/AuthenticationRequest.h @@ -4,7 +4,6 @@ #include #include #include -#include struct AuthenticationRequest final : ClientMessage { @@ -23,8 +22,7 @@ struct AuthenticationRequest final : ClientMessage bool operator==(const AuthenticationRequest& achRhs) const noexcept { return GetOpcode() == achRhs.GetOpcode() && DiscordId == achRhs.DiscordId && SKSEActive == achRhs.SKSEActive && MO2Active == achRhs.MO2Active && Token == achRhs.Token && Version == achRhs.Version && UserMods == achRhs.UserMods && Username == achRhs.Username && - WorldSpaceId == achRhs.WorldSpaceId && CellId == achRhs.CellId && Level == achRhs.Level - && PlayerTime == achRhs.PlayerTime; + WorldSpaceId == achRhs.WorldSpaceId && CellId == achRhs.CellId && Level == achRhs.Level; } uint64_t DiscordId{}; @@ -37,5 +35,4 @@ struct AuthenticationRequest final : ClientMessage GameId WorldSpaceId{}; GameId CellId{}; uint16_t Level{}; - TimeModel PlayerTime{}; }; diff --git a/Code/encoding/Messages/ServerTimeSettings.cpp b/Code/encoding/Messages/ServerTimeSettings.cpp index d99940394..6d7312a5a 100644 --- a/Code/encoding/Messages/ServerTimeSettings.cpp +++ b/Code/encoding/Messages/ServerTimeSettings.cpp @@ -2,10 +2,21 @@ void ServerTimeSettings::SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept { - timeModel.Serialize(aWriter); + // poor man's std::bitcast + aWriter.WriteBits(*reinterpret_cast(&TimeScale), 32); + aWriter.WriteBits(*reinterpret_cast(&Time), 32); } void ServerTimeSettings::DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept { - timeModel.Deserialize(aReader); + uint64_t tmp = 0; + uint32_t cVal = 0; + + aReader.ReadBits(tmp, 32); + cVal = tmp & 0xFFFFFFFF; + TimeScale = *reinterpret_cast(&cVal); + + aReader.ReadBits(tmp, 32); + cVal = tmp & 0xFFFFFFFF; + Time = *reinterpret_cast(&cVal); } diff --git a/Code/encoding/Messages/ServerTimeSettings.h b/Code/encoding/Messages/ServerTimeSettings.h index 2ada7b7ee..4b4d1f04f 100644 --- a/Code/encoding/Messages/ServerTimeSettings.h +++ b/Code/encoding/Messages/ServerTimeSettings.h @@ -1,7 +1,6 @@ #pragma once #include "Message.h" -#include "Structs/TimeModel.h" struct ServerTimeSettings final : ServerMessage { @@ -15,15 +14,8 @@ struct ServerTimeSettings final : ServerMessage void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override; void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override; - bool operator==(const ServerTimeSettings& achRhs) const noexcept - { - return GetOpcode() == achRhs.GetOpcode() && timeModel == achRhs.timeModel; - } - - bool operator!=(const ServerTimeSettings& achRhs) const noexcept - { - return !this->operator==(achRhs); - } + bool operator==(const ServerTimeSettings& achRhs) const noexcept { return Time == achRhs.Time && TimeScale == achRhs.TimeScale && GetOpcode() == achRhs.GetOpcode(); } - TimeModel timeModel; + float Time; + float TimeScale; }; diff --git a/Code/encoding/Structs/ServerSettings.cpp b/Code/encoding/Structs/ServerSettings.cpp index bdf8f77ad..88a309d19 100644 --- a/Code/encoding/Structs/ServerSettings.cpp +++ b/Code/encoding/Structs/ServerSettings.cpp @@ -20,7 +20,6 @@ void ServerSettings::Serialize(TiltedPhoques::Buffer::Writer& aWriter) const noe Serialization::WriteBool(aWriter, PvpEnabled); Serialization::WriteBool(aWriter, SyncPlayerHomes); Serialization::WriteBool(aWriter, DeathSystemEnabled); - Serialization::WriteBool(aWriter, SyncPlayerCalendar); Serialization::WriteBool(aWriter, AutoPartyJoin); } @@ -31,6 +30,5 @@ void ServerSettings::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcep PvpEnabled = Serialization::ReadBool(aReader); SyncPlayerHomes = Serialization::ReadBool(aReader); DeathSystemEnabled = Serialization::ReadBool(aReader); - SyncPlayerCalendar = Serialization::ReadBool(aReader); AutoPartyJoin = Serialization::ReadBool(aReader); } diff --git a/Code/encoding/Structs/ServerSettings.h b/Code/encoding/Structs/ServerSettings.h index 02a49302f..944472251 100644 --- a/Code/encoding/Structs/ServerSettings.h +++ b/Code/encoding/Structs/ServerSettings.h @@ -15,6 +15,5 @@ struct ServerSettings bool PvpEnabled{}; bool SyncPlayerHomes{}; bool DeathSystemEnabled{}; - bool SyncPlayerCalendar{}; bool AutoPartyJoin{}; }; diff --git a/Code/encoding/Structs/TimeModel.cpp b/Code/encoding/Structs/TimeModel.cpp deleted file mode 100644 index 09e80544c..000000000 --- a/Code/encoding/Structs/TimeModel.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -using TiltedPhoques::Serialization; - -void TimeModel::Serialize(TiltedPhoques::Buffer::Writer& aWriter) const noexcept -{ - Serialization::WriteFloat(aWriter, TimeScale); - Serialization::WriteFloat(aWriter, Time); - Serialization::WriteVarInt(aWriter, Day); - Serialization::WriteVarInt(aWriter, Month); - Serialization::WriteVarInt(aWriter, Year); -} - -void TimeModel::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept -{ - TimeScale = Serialization::ReadFloat(aReader); - Time = Serialization::ReadFloat(aReader); - Day = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF; - Month = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF; - Year = Serialization::ReadVarInt(aReader) & 0xFFFFFFFF; -} diff --git a/Code/encoding/Structs/TimeModel.h b/Code/encoding/Structs/TimeModel.h deleted file mode 100644 index f9fc6df47..000000000 --- a/Code/encoding/Structs/TimeModel.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -#include - -using TiltedPhoques::Buffer; - -struct TimeModel -{ - // Default time: 01/01/01 at 12:00 - float TimeScale = 20.f; - float Time = 12.f; - uint32_t Year = 1; - uint32_t Month = 1; - uint32_t Day = 1; - - void Serialize(TiltedPhoques::Buffer::Writer& aWriter) const noexcept; - void Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept; - - bool operator==(const TimeModel& achRhs) const noexcept { return TimeScale == achRhs.TimeScale && Time == achRhs.Time && Day == achRhs.Day && Month == achRhs.Month && Year == achRhs.Year; } - bool operator!=(const TimeModel& achRhs) const noexcept { return !this->operator==(achRhs); } -}; diff --git a/Code/server/Events/PlayerJoinEvent.h b/Code/server/Events/PlayerJoinEvent.h index 19bc543ae..eebff7b20 100644 --- a/Code/server/Events/PlayerJoinEvent.h +++ b/Code/server/Events/PlayerJoinEvent.h @@ -1,7 +1,6 @@ #pragma once #include -#include struct Player; @@ -22,16 +21,7 @@ struct PlayerJoinEvent { } - PlayerJoinEvent(Player* apPlayer, GameId aWorldSpaceId, GameId aCellId, DateTime aDateTime) - : pPlayer(apPlayer) - , WorldSpaceId(aWorldSpaceId) - , CellId(aCellId) - , PlayerTime(aDateTime) - { - } - Player* pPlayer; GameId WorldSpaceId{}; GameId CellId{}; - DateTime PlayerTime; }; diff --git a/Code/server/GameServer.cpp b/Code/server/GameServer.cpp index f2350c581..f9e36153a 100644 --- a/Code/server/GameServer.cpp +++ b/Code/server/GameServer.cpp @@ -49,9 +49,6 @@ Console::Setting bEnableDeathSystem{"Gameplay:bEnableDeathSystem", "Enables the Console::Setting uTimeScale{ "Gameplay:uTimeScale", "How many seconds pass ingame for every real second (0 to 1000). Changing this can make the game unstable", 20u}; -Console::Setting bSyncPlayerCalendar{ - "Gameplay:bSyncPlayerCalendar", - "Syncs up all player calendars to be the same day, month, and year. This uses the date of the player with the furthest ahead date at connection.", false}; Console::Setting bAutoPartyJoin{ "Gameplay:bAutoPartyJoin", "Join parties automatically, as long as there is only one party in the server", true}; @@ -120,12 +117,6 @@ constexpr char kMopoRecordsMissing[]{ "to join! Please create a Data/ directory, and put a \"loadorder.txt\" file in there." "Check the wiki, which can be found on skyrim-together.com, for more details."}; -constexpr char kCalendarSyncWarning[]{ - "Calendar sync is enabled. We generally do not recommend that you use this feature." - "Calendar sync can cause the calendar to jump ahead or behind, which might mess up the timing of quests." - "If you disable this feature again (which is the default setting), the days will still progress, but the" - "exact date will differ slightly between clients (which has no impact on gameplay)."}; - static uint16_t GetUserTickRate() { return bPremiumTickrate ? 60 : 30; @@ -144,7 +135,6 @@ ServerSettings GetSettings() settings.PvpEnabled = bEnablePvp; settings.SyncPlayerHomes = bSyncPlayerHomes; settings.DeathSystemEnabled = bEnableDeathSystem; - settings.SyncPlayerCalendar = bSyncPlayerCalendar; settings.AutoPartyJoin = bAutoPartyJoin; return settings; } @@ -209,9 +199,6 @@ void GameServer::Initialize() if (!CheckMoPo()) return; - if (bSyncPlayerCalendar) - spdlog::warn(kCalendarSyncWarning); - BindServerCommands(); m_pWorld->GetScriptService().Initialize(*m_pResources); } @@ -363,26 +350,6 @@ void GameServer::BindServerCommands() out->error("Hour must be between 0-23 and minute must be between 0-59"); } }); - - m_commands.RegisterCommand( - "SetDate", "Set ingame day, month, and year", [&](Console::ArgStack& aStack) { - auto out = spdlog::get("ConOut"); - - auto day = aStack.Pop(); - auto month = aStack.Pop(); - auto year = aStack.Pop(); - - bool time_set_successfully = m_pWorld->GetCalendarService().SetDate(day, month, year); - - if (time_set_successfully) - { - out->info("Time set to {:02}/{:02}:{:02}", month, day, year); - } - else - { - out->error("Day must be between 0 and 31, month must be between 0 and 11, and year must be between 0 and 999."); - } - }); } /* Update Info fields from user facing CVARS.*/ @@ -880,7 +847,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, Send(pPlayer->GetConnectionId(), notify); } - m_pWorld->GetDispatcher().trigger(PlayerJoinEvent(pPlayer, acRequest->WorldSpaceId, acRequest->CellId, acRequest->PlayerTime)); + m_pWorld->GetDispatcher().trigger(PlayerJoinEvent(pPlayer, acRequest->WorldSpaceId, acRequest->CellId)); } /* else if (acRequest->Token == sAdminPassword.value() && !sAdminPassword.empty()) diff --git a/Code/server/Services/CalendarService.cpp b/Code/server/Services/CalendarService.cpp index dc2ef40e0..f44b06ac7 100644 --- a/Code/server/Services/CalendarService.cpp +++ b/Code/server/Services/CalendarService.cpp @@ -3,14 +3,15 @@ #include #include -#include #include +#include #include #include "Game/Player.h" -CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher) : m_world(aWorld) +CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher) + : m_world(aWorld) { m_updateConnection = aDispatcher.sink().connect<&CalendarService::OnUpdate>(this); m_joinConnection = aDispatcher.sink().connect<&CalendarService::OnPlayerJoin>(this); @@ -29,88 +30,43 @@ void CalendarService::OnUpdate(const UpdateEvent&) noexcept auto delta = now - m_lastTick; m_lastTick = now; - m_dateTime.Update(delta); + m_timeModel.Update(delta); } -void CalendarService::OnPlayerJoin(const PlayerJoinEvent& acEvent) noexcept +void CalendarService::OnPlayerJoin(const PlayerJoinEvent& acEvent) const noexcept { ServerTimeSettings timeMsg; - // the player with the furthest date is used - bool playerHasFurthestTime = acEvent.PlayerTime.GetTimeInDays() > m_dateTime.GetTimeInDays(); - - if (playerHasFurthestTime) - { - // Note that this doesn't set timescale because the server config should set that. - if (!m_timeSetFromFirstPlayer) - { - m_dateTime.m_timeModel.Time = acEvent.PlayerTime.m_timeModel.Time; - m_timeSetFromFirstPlayer = true; - } - m_dateTime.m_timeModel.Day = acEvent.PlayerTime.m_timeModel.Day; - m_dateTime.m_timeModel.Month = acEvent.PlayerTime.m_timeModel.Month; - m_dateTime.m_timeModel.Year = acEvent.PlayerTime.m_timeModel.Year; - } - timeMsg.timeModel.TimeScale = m_dateTime.m_timeModel.TimeScale; - timeMsg.timeModel.Time = m_dateTime.m_timeModel.Time; - timeMsg.timeModel.Day = m_dateTime.m_timeModel.Day; - timeMsg.timeModel.Month = m_dateTime.m_timeModel.Month; - timeMsg.timeModel.Year = m_dateTime.m_timeModel.Year; + timeMsg.TimeScale = m_timeModel.TimeScale; + timeMsg.Time = m_timeModel.Time; - if (playerHasFurthestTime) - GameServer::Get()->SendToPlayers(timeMsg); - else - acEvent.pPlayer->Send(timeMsg); + acEvent.pPlayer->Send(timeMsg); } bool CalendarService::SetTime(int aHours, int aMinutes, float aScale) noexcept { - m_dateTime.m_timeModel.TimeScale = aScale; + m_timeModel.TimeScale = aScale; if (aHours >= 0 && aHours <= 23 && aMinutes >= 0 && aMinutes <= 59) { // encode time as skyrim time auto minutes = static_cast(aMinutes) * 0.17f; minutes = floor(minutes * 100) / 1000; - m_dateTime.m_timeModel.Time = static_cast(aHours) + minutes; + m_timeModel.Time = static_cast(aHours) + minutes; - SendTimeResync(); + ServerTimeSettings timeMsg; + timeMsg.TimeScale = m_timeModel.TimeScale; + timeMsg.Time = m_timeModel.Time; + GameServer::Get()->SendToLoaded(timeMsg); return true; } - return false; -} -bool CalendarService::SetDate(int aDay, int aMonth, float aYear) noexcept -{ - if (aMonth >= 0 && aMonth < 12 && aYear >= 0 && aYear <= 999) - { - auto maxDays = m_dateTime.GetNumberOfDaysByMonthIndex(aMonth); - if (aDay >= 0 && aDay < maxDays) - { - m_dateTime.m_timeModel.Day = aDay; - m_dateTime.m_timeModel.Month = aMonth; - m_dateTime.m_timeModel.Year = aYear; - SendTimeResync(); - return true; - } - } return false; } -void CalendarService::SendTimeResync() noexcept -{ - ServerTimeSettings timeMsg; - timeMsg.timeModel.TimeScale = m_dateTime.m_timeModel.TimeScale; - timeMsg.timeModel.Time = m_dateTime.m_timeModel.Time; - timeMsg.timeModel.Day = m_dateTime.m_timeModel.Day; - timeMsg.timeModel.Month = m_dateTime.m_timeModel.Month; - timeMsg.timeModel.Year = m_dateTime.m_timeModel.Year; - GameServer::Get()->SendToLoaded(timeMsg); -} - CalendarService::TTime CalendarService::GetTime() const noexcept { - const auto hour = floor(m_dateTime.m_timeModel.Time); - const auto minutes = (m_dateTime.m_timeModel.Time - hour) / 17.f; + const auto hour = floor(m_timeModel.Time); + const auto minutes = (m_timeModel.Time - hour) / 17.f; const auto flatMinutes = static_cast(ceil((minutes * 100.f) * 10.f)); return {static_cast(hour), flatMinutes}; @@ -126,21 +82,18 @@ CalendarService::TTime CalendarService::GetRealTime() noexcept CalendarService::TDate CalendarService::GetDate() const noexcept { - return {m_dateTime.m_timeModel.Day, m_dateTime.m_timeModel.Month, m_dateTime.m_timeModel.Year}; + return {m_timeModel.Day, m_timeModel.Month, m_timeModel.Year}; } bool CalendarService::SetTimeScale(float aScale) noexcept { if (aScale >= 0.f && aScale <= 1000.f) { - m_dateTime.m_timeModel.TimeScale = aScale; + m_timeModel.TimeScale = aScale; ServerTimeSettings timeMsg; - timeMsg.timeModel.TimeScale = m_dateTime.m_timeModel.TimeScale; - timeMsg.timeModel.Time = m_dateTime.m_timeModel.Time; - timeMsg.timeModel.Day = m_dateTime.m_timeModel.Day; - timeMsg.timeModel.Month = m_dateTime.m_timeModel.Month; - timeMsg.timeModel.Year = m_dateTime.m_timeModel.Year; + timeMsg.TimeScale = m_timeModel.TimeScale; + timeMsg.Time = m_timeModel.Time; GameServer::Get()->SendToPlayers(timeMsg); return true; } diff --git a/Code/server/Services/CalendarService.h b/Code/server/Services/CalendarService.h index 438049044..3f2a234d4 100644 --- a/Code/server/Services/CalendarService.h +++ b/Code/server/Services/CalendarService.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include struct World; @@ -23,7 +23,6 @@ class CalendarService using TDate = std::tuple; bool SetTime(int aHour, int aMinutes, float aScale) noexcept; - bool SetDate(int aDay, int aMonth, float aYear) noexcept; // returns hours, minutes TTime GetTime() const noexcept; @@ -32,17 +31,15 @@ class CalendarService // returns dd/mm/yy TDate GetDate() const noexcept; - float GetTimeScale() const noexcept { return m_dateTime.m_timeModel.TimeScale; } + float GetTimeScale() const noexcept { return m_timeModel.TimeScale; } bool SetTimeScale(float aScale) noexcept; private: void OnUpdate(const UpdateEvent&) noexcept; - void OnPlayerJoin(const PlayerJoinEvent&) noexcept; - void SendTimeResync() noexcept; + void OnPlayerJoin(const PlayerJoinEvent&) const noexcept; - DateTime m_dateTime; + TimeModel m_timeModel; uint64_t m_lastTick = 0; - bool m_timeSetFromFirstPlayer = false; World& m_world; diff --git a/MakeVSXMakeLatestProjects.cmd b/MakeVSXMakeLatestProjects.cmd deleted file mode 100644 index b27aa5016..000000000 --- a/MakeVSXMakeLatestProjects.cmd +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -xmake project -k vsxmake \ No newline at end of file