refactor: ServerEvent - OnStartup, OnBeforeConfigLoad, OnConfigLoad (#311)

This commit is contained in:
iThorgrim
2025-09-16 21:57:52 +02:00
committed by GitHub
parent 576d18753c
commit 04ce900383
5 changed files with 33 additions and 13 deletions

View File

@@ -1111,14 +1111,17 @@ public:
///- Initialize Lua Engine
LOG_INFO("eluna", "Initialize Eluna Lua Engine...");
Eluna::Initialize();
if(sEluna->IsInitialized())
sEluna->RunScripts();
}
sEluna->OnConfigLoad(reload, true);
sEluna->OnBeforeConfigLoad(reload);
}
void OnAfterConfigLoad(bool reload) override
{
sEluna->OnConfigLoad(reload, false);
sEluna->OnAfterConfigLoad(reload);
}
void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) override
@@ -1153,10 +1156,7 @@ public:
void OnBeforeWorldInitialized() override
{
///- Run eluna scripts.
// in multithread foreach: run scripts
sEluna->RunScripts();
sEluna->OnConfigLoad(false, false); // Must be done after Eluna is initialized and scripts have run.
sEluna->OnBeforeWorldInitialized();
}
};

View File

@@ -113,7 +113,7 @@ namespace Hooks
// World
WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) - Needs core support on Mangos
WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload)
WORLD_EVENT_ON_AFTER_CONFIG_LOAD = 9, // (event, reload)
// UNUSED = 10,
WORLD_EVENT_ON_SHUTDOWN_INIT = 11, // (event, code, mask)
WORLD_EVENT_ON_SHUTDOWN_CANCEL = 12, // (event)
@@ -157,6 +157,9 @@ namespace Hooks
GAME_EVENT_START = 34, // (event, gameeventid)
GAME_EVENT_STOP = 35, // (event, gameeventid)
WORLD_EVENT_ON_BEFORE_WORLD_INITIALIZED = 36, // (event)
WORLD_EVENT_ON_BEFORE_CONFIG_LOAD = 37, // (event, reload)
SERVER_EVENT_COUNT
};

View File

@@ -556,13 +556,15 @@ public:
/* World */
void OnOpenStateChange(bool open);
void OnConfigLoad(bool reload, bool isBefore);
void OnAfterConfigLoad(bool reload);
void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask);
void OnShutdownCancel();
void OnStartup();
void OnShutdown();
void OnGameEventStart(uint32 eventid);
void OnGameEventStop(uint32 eventid);
void OnBeforeWorldInitialized();
void OnBeforeConfigLoad(bool reload);
/* Battle Ground */
void OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
@@ -575,7 +577,7 @@ public:
void OnTicketClose(GmTicket* ticket);
void OnTicketUpdateLastChange(GmTicket* ticket);
void OnTicketResolve(GmTicket* ticket);
/* Spell */
void OnSpellPrepare(Unit* caster, Spell* spell, SpellInfo const* spellInfo);
void OnSpellCast(Unit* caster, Spell* spell, SpellInfo const* spellInfo, bool skipCheck);

View File

@@ -227,11 +227,10 @@ void Eluna::OnOpenStateChange(bool open)
CallAllFunctions(ServerEventBindings, key);
}
void Eluna::OnConfigLoad(bool reload, bool isBefore)
void Eluna::OnAfterConfigLoad(bool reload)
{
START_HOOK(WORLD_EVENT_ON_CONFIG_LOAD);
START_HOOK(WORLD_EVENT_ON_AFTER_CONFIG_LOAD);
Push(reload);
Push(isBefore);
CallAllFunctions(ServerEventBindings, key);
}
@@ -278,6 +277,19 @@ void Eluna::OnShutdown()
CallAllFunctions(ServerEventBindings, key);
}
void Eluna::OnBeforeWorldInitialized()
{
START_HOOK(WORLD_EVENT_ON_BEFORE_WORLD_INITIALIZED);
CallAllFunctions(ServerEventBindings, key);
}
void Eluna::OnBeforeConfigLoad(bool reload)
{
START_HOOK(WORLD_EVENT_ON_BEFORE_CONFIG_LOAD);
Push(reload);
CallAllFunctions(ServerEventBindings, key);
}
/* Map */
void Eluna::OnCreate(Map* map)
{

View File

@@ -649,7 +649,7 @@ namespace LuaGlobalFunctions
*
* // World
* WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) - Needs core support on Mangos
* WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload)
* WORLD_EVENT_ON_AFTER_CONFIG_LOAD = 9, // (event, reload)
* // UNUSED = 10,
* WORLD_EVENT_ON_SHUTDOWN_INIT = 11, // (event, code, mask)
* WORLD_EVENT_ON_SHUTDOWN_CANCEL = 12, // (event)
@@ -692,6 +692,9 @@ namespace LuaGlobalFunctions
*
* GAME_EVENT_START = 34, // (event, gameeventid)
* GAME_EVENT_STOP = 35, // (event, gameeventid)
*
* WORLD_EVENT_ON_BEFORE_WORLD_INITIALIZED = 36, // (event)
* WORLD_EVENT_ON_BEFORE_CONFIG_LOAD = 37, // (event, reload)
* };
*
* @proto cancel = (event, function)