From d18545263fda54e19c875d22adfb28ae4072ec01 Mon Sep 17 00:00:00 2001 From: Kaytotes Date: Sun, 22 Aug 2021 12:41:19 +0100 Subject: [PATCH] feat(Core/Scripts): new OnBeforeFinalizePlayerWorldSession() hook (#7136) Co-authored-by: Yehonal --- .../pendings/changes_1629216324271376300.md | 3 +++ src/server/game/Scripting/ScriptMgr.cpp | 5 +++++ src/server/game/Scripting/ScriptMgr.h | 8 +++++++ src/server/game/World/World.cpp | 21 ++++++++++++------- src/server/game/World/World.h | 7 +++++++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 doc/changelog/pendings/changes_1629216324271376300.md diff --git a/doc/changelog/pendings/changes_1629216324271376300.md b/doc/changelog/pendings/changes_1629216324271376300.md new file mode 100644 index 000000000..ae58ea916 --- /dev/null +++ b/doc/changelog/pendings/changes_1629216324271376300.md @@ -0,0 +1,3 @@ +### Added + +- Added `OnBeforeFinalizePlayerWorldSession ` that can be used to modify the cache version that is sent to the client via modules. \ No newline at end of file diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index c46982de3..17929410d 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -408,6 +408,11 @@ void ScriptMgr::OnAfterConfigLoad(bool reload) FOREACH_SCRIPT(WorldScript)->OnAfterConfigLoad(reload); } +void ScriptMgr::OnBeforeFinalizePlayerWorldSession(uint32& cacheVersion) +{ + FOREACH_SCRIPT(WorldScript)->OnBeforeFinalizePlayerWorldSession(cacheVersion); +} + void ScriptMgr::OnMotdChange(std::string& newMotd) { FOREACH_SCRIPT(WorldScript)->OnMotdChange(newMotd); diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index fc1033f8a..3fce9ea56 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -194,6 +194,13 @@ public: // Called when the world is actually shut down. virtual void OnShutdown() { } + + /** + * @brief This hook runs before finalizing the player world session. Can be also used to mutate the cache version of the Client. + * + * @param version The cache version that we will be sending to the Client. + */ + virtual void OnBeforeFinalizePlayerWorldSession(uint32& /*cacheVersion*/) {} }; class FormulaScript : public ScriptObject @@ -1466,6 +1473,7 @@ public: /* WorldScript */ void OnOpenStateChange(bool open); void OnBeforeConfigLoad(bool reload); void OnAfterConfigLoad(bool reload); + void OnBeforeFinalizePlayerWorldSession(uint32& cacheVersion); void OnMotdChange(std::string& newMotd); void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask); void OnShutdownCancel(); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 804675a82..c09273c85 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -312,9 +312,8 @@ void World::AddSession_(WorldSession* s) } s->SendAuthResponse(AUTH_OK, true); - s->SendAddonsInfo(); - s->SendClientCacheVersion(sWorld->getIntConfig(CONFIG_CLIENTCACHE_VERSION)); - s->SendTutorialsData(); + + FinalizePlayerWorldSession(s); UpdateMaxSessionCounters(); } @@ -397,11 +396,9 @@ bool World::RemoveQueuedPlayer(WorldSession* sess) pop_sess->SetInQueue(false); pop_sess->ResetTimeOutTime(false); pop_sess->SendAuthWaitQue(0); - pop_sess->SendAddonsInfo(); - - pop_sess->SendClientCacheVersion(sWorld->getIntConfig(CONFIG_CLIENTCACHE_VERSION)); pop_sess->SendAccountDataTimes(GLOBAL_CACHE_MASK); - pop_sess->SendTutorialsData(); + + FinalizePlayerWorldSession(pop_sess); m_QueuedPlayer.pop_front(); @@ -3480,3 +3477,13 @@ uint32 World::GetNextWhoListUpdateDelaySecs() return uint32(ceil(t / 1000.0f)); } + +void World::FinalizePlayerWorldSession(WorldSession* session) +{ + uint32 cacheVersion = sWorld->getIntConfig(CONFIG_CLIENTCACHE_VERSION); + sScriptMgr->OnBeforeFinalizePlayerWorldSession(cacheVersion); + + session->SendAddonsInfo(); + session->SendClientCacheVersion(cacheVersion); + session->SendTutorialsData(); +} diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 28c8244b1..472fd070d 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -486,6 +486,13 @@ private: void ProcessQueryCallbacks(); QueryCallbackProcessor _queryProcessor; + + /** + * @brief Executed when a World Session is being finalized. Be it from a normal login or via queue popping. + * + * @param session The World Session that we are finalizing. + */ + inline void FinalizePlayerWorldSession(WorldSession* session); }; std::unique_ptr& getWorldInstance();