Created
August 27, 2024 13:57
-
-
Save walkline/1382a2542cb2e2ba5e1dd64a710d7c6e to your computer and use it in GitHub Desktop.
Add time fast forward command (.debug timeff 1200 - forwards for 20 minutes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp | |
index 253aeb9f6..b57812142 100644 | |
--- a/src/server/game/Server/WorldSession.cpp | |
+++ b/src/server/game/Server/WorldSession.cpp | |
@@ -291,8 +291,8 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) | |
///- Before we process anything: | |
/// If necessary, kick the player because the client didn't send anything for too long | |
/// (or they've been idling in character select) | |
- if (sWorld->getBoolConfig(CONFIG_CLOSE_IDLE_CONNECTIONS) && IsConnectionIdle() && m_Socket) | |
- m_Socket->CloseSocket(); | |
+// if (sWorld->getBoolConfig(CONFIG_CLOSE_IDLE_CONNECTIONS) && IsConnectionIdle() && m_Socket) | |
+// m_Socket->CloseSocket(); | |
if (updater.ProcessUnsafe()) | |
UpdateTimeOutTime(diff); | |
diff --git a/src/server/game/Time/GameTime.cpp b/src/server/game/Time/GameTime.cpp | |
index 3dbcbc0f2..fa2935ad8 100644 | |
--- a/src/server/game/Time/GameTime.cpp | |
+++ b/src/server/game/Time/GameTime.cpp | |
@@ -26,10 +26,12 @@ namespace GameTime | |
Seconds GameTime = GetEpochTime(); | |
Milliseconds GameMSTime = 0ms; | |
+ Milliseconds injectedTime = 0ms; | |
SystemTimePoint GameTimeSystemPoint = SystemTimePoint::min(); | |
TimePoint GameTimeSteadyPoint = TimePoint::min(); | |
+ | |
Seconds GetStartTime() | |
{ | |
return StartTime; | |
@@ -37,12 +39,12 @@ namespace GameTime | |
Seconds GetGameTime() | |
{ | |
- return GameTime; | |
+ return std::chrono::duration_cast<std::chrono::seconds>(GameTime+injectedTime); | |
} | |
Milliseconds GetGameTimeMS() | |
{ | |
- return GameMSTime; | |
+ return GameMSTime+injectedTime; | |
} | |
SystemTimePoint GetSystemTime() | |
@@ -57,7 +59,12 @@ namespace GameTime | |
Seconds GetUptime() | |
{ | |
- return GameTime - StartTime; | |
+ return GetGameTime() - StartTime; | |
+ } | |
+ | |
+ void AddInjectedTimeMs(uint64 ms) | |
+ { | |
+ injectedTime += std::chrono::milliseconds(ms); | |
} | |
void UpdateGameTimers() | |
diff --git a/src/server/game/Time/GameTime.h b/src/server/game/Time/GameTime.h | |
index 3350a14d4..818c30a55 100644 | |
--- a/src/server/game/Time/GameTime.h | |
+++ b/src/server/game/Time/GameTime.h | |
@@ -41,6 +41,9 @@ namespace GameTime | |
/// Uptime | |
AC_GAME_API Seconds GetUptime(); | |
+ AC_GAME_API void AddInjectedTimeMs(uint64 ms); | |
+ | |
+ | |
/// Update all timers | |
void UpdateGameTimers(); | |
} | |
diff --git a/src/server/game/World/IWorld.h b/src/server/game/World/IWorld.h | |
index 78eab7d7b..59aeedd82 100644 | |
--- a/src/server/game/World/IWorld.h | |
+++ b/src/server/game/World/IWorld.h | |
@@ -526,6 +526,8 @@ enum Rates | |
class IWorld | |
{ | |
public: | |
+ virtual void InjectDiff(uint32 diff) = 0; | |
+ | |
virtual ~IWorld() = default; | |
[[nodiscard]] virtual WorldSession* FindSession(uint32 id) const = 0; | |
[[nodiscard]] virtual WorldSession* FindOfflineSession(uint32 id) const = 0; | |
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp | |
index a5af85143..18380c6fb 100644 | |
--- a/src/server/game/World/World.cpp | |
+++ b/src/server/game/World/World.cpp | |
@@ -134,6 +134,7 @@ World::World() | |
_mail_expire_check_timer = 0s; | |
_isClosed = false; | |
_cleaningFlags = 0; | |
+ _injectDiff = 0; | |
memset(_rate_values, 0, sizeof(_rate_values)); | |
memset(_int_configs, 0, sizeof(_int_configs)); | |
@@ -2249,6 +2250,12 @@ void World::DetectDBCLang() | |
/// Update the World ! | |
void World::Update(uint32 diff) | |
{ | |
+ if (_injectDiff > 0) { | |
+ diff = _injectDiff; | |
+ GameTime::AddInjectedTimeMs(_injectDiff); | |
+ _injectDiff = 0; | |
+ } | |
+ | |
METRIC_TIMER("world_update_time_total"); | |
///- Update the game time and check for shutdown time | |
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h | |
index daaa53e15..388224ee1 100644 | |
--- a/src/server/game/World/World.h | |
+++ b/src/server/game/World/World.h | |
@@ -150,6 +150,9 @@ struct PetitionData | |
class World: public IWorld | |
{ | |
public: | |
+ | |
+ void InjectDiff(uint32 diff) { _injectDiff = diff; } | |
+ | |
World(); | |
~World() override; | |
@@ -438,6 +441,8 @@ private: | |
* @param session The World Session that we are finalizing. | |
*/ | |
inline void FinalizePlayerWorldSession(WorldSession* session); | |
+ | |
+ uint32 _injectDiff; | |
}; | |
std::unique_ptr<IWorld>& getWorldInstance(); | |
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp | |
index 286282bd3..b5f64d1de 100644 | |
--- a/src/server/scripts/Commands/cs_debug.cpp | |
+++ b/src/server/scripts/Commands/cs_debug.cpp | |
@@ -104,7 +104,8 @@ public: | |
{ "moveflags", HandleDebugMoveflagsCommand, SEC_ADMINISTRATOR, Console::No }, | |
{ "unitstate", HandleDebugUnitStateCommand, SEC_ADMINISTRATOR, Console::No }, | |
{ "objectcount", HandleDebugObjectCountCommand, SEC_ADMINISTRATOR, Console::Yes}, | |
- { "dummy", HandleDebugDummyCommand, SEC_ADMINISTRATOR, Console::No } | |
+ { "dummy", HandleDebugDummyCommand, SEC_ADMINISTRATOR, Console::No }, | |
+ { "timeff", HandleDebugTimeFastForward, SEC_ADMINISTRATOR, Console::Yes} | |
}; | |
static ChatCommandTable commandTable = | |
{ | |
@@ -1346,6 +1347,12 @@ public: | |
handler->SendSysMessage("This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing."); | |
return true; | |
} | |
+ | |
+ static bool HandleDebugTimeFastForward(ChatHandler* handler, uint32 seconds) | |
+ { | |
+ sWorld->InjectDiff(seconds * 1000); | |
+ return true; | |
+ } | |
}; | |
void AddSC_debug_commandscript() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment