feat(Core/Scripts): new OnBeforeFinalizePlayerWorldSession() hook (#7136)

Co-authored-by: Yehonal <yehonal.azeroth@gmail.com>
This commit is contained in:
Kaytotes
2021-08-22 12:41:19 +01:00
committed by GitHub
parent 75e55e21df
commit d18545263f
5 changed files with 37 additions and 7 deletions

View File

@@ -0,0 +1,3 @@
### Added
- Added `OnBeforeFinalizePlayerWorldSession ` that can be used to modify the cache version that is sent to the client via modules.

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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<IWorld>& getWorldInstance();