diff options
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 10 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 8 | ||||
| -rw-r--r-- | src/server/worldserver/WorldThread/WorldRunnable.cpp | 13 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 86336d138c6..ba9e848a566 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1012,6 +1012,16 @@ void ScriptMgr::OnRelocate(Transport* transport, uint32 mapId, float x, float y, tmpscript->OnRelocate(transport, mapId, x, y, z); } +void ScriptMgr::OnStartup() +{ + FOREACH_SCRIPT(WorldScript)->OnStartup(); +} + +void ScriptMgr::OnShutdown() +{ + FOREACH_SCRIPT(WorldScript)->OnShutdown(); +} + void SpellHandlerScript::RegisterSelf() { ScriptMgr::ScriptRegistry<SpellHandlerScript>::AddScript(this); diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 971924b6b58..e735c7b9765 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -292,6 +292,12 @@ class WorldScript : public ScriptObject, public UpdatableScript<void> // Called on every world tick (don't execute too heavy code here). virtual void OnUpdate(void* null, uint32 diff) { } + + // Called when the world is started. + virtual void OnStartup() { } + + // Called when the world is actually shut down. + virtual void OnShutdown() { } }; class FormulaScript : public ScriptObject @@ -787,6 +793,8 @@ class ScriptMgr void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask); void OnShutdownCancel(); void OnWorldUpdate(uint32 diff); + void OnStartup(); + void OnShutdown(); public: /* FormulaScript */ diff --git a/src/server/worldserver/WorldThread/WorldRunnable.cpp b/src/server/worldserver/WorldThread/WorldRunnable.cpp index 69639da62fa..b1e5f212b3e 100644 --- a/src/server/worldserver/WorldThread/WorldRunnable.cpp +++ b/src/server/worldserver/WorldThread/WorldRunnable.cpp @@ -27,7 +27,7 @@ #include "World.h" #include "WorldSocketMgr.h" #include "Database/DatabaseEnv.h" - +#include "ScriptMgr.h" #include "BattleGroundMgr.h" #include "MapManager.h" #include "Timer.h" @@ -53,6 +53,8 @@ void WorldRunnable::run() uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST + sScriptMgr.OnStartup(); + ///- While we have not World::m_stopEvent, update the world while (!World::IsStopped()) { @@ -77,11 +79,16 @@ void WorldRunnable::run() prevSleepTime = 0; #ifdef _WIN32 - if (m_ServiceStatus == 0) World::StopNow(SHUTDOWN_EXIT_CODE); - while (m_ServiceStatus == 2) Sleep(1000); + if (m_ServiceStatus == 0) + World::StopNow(SHUTDOWN_EXIT_CODE); + + while (m_ServiceStatus == 2) + Sleep(1000); #endif } + sScriptMgr.OnShutdown(); + sWorld.KickAll(); // save and kick all players sWorld.UpdateSessions( 1 ); // real players unload required UpdateSessions call |
