From fb592b4d76c7af88bcdaeca0a25115082d4a1b2b Mon Sep 17 00:00:00 2001 From: Emagi Date: Fri, 6 Sep 2024 08:10:47 -0400 Subject: [PATCH] Update LuaInterface::DestroySpells to assure we cover all the new lua states under the spell_scripts instead of the obselete spells map --- source/WorldServer/LuaInterface.cpp | 28 ++++++++++++++++++---------- source/WorldServer/LuaInterface.h | 3 +-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index e61fdbf..5cc637b 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -143,17 +143,25 @@ void LuaInterface::Process() { } void LuaInterface::DestroySpells() { - map::iterator itr; MSpells.lock(); - for(itr = spells.begin(); itr != spells.end(); itr++){ - MSpellDelete.lock(); - RemoveCurrentSpell(itr->second->state, itr->second, false); - MSpellDelete.unlock(); - lua_close(itr->second->state); - safe_delete(itr->second); + map >::iterator spell_script_itr; + for(spell_script_itr = spell_scripts.begin(); spell_script_itr != spell_scripts.end(); spell_script_itr++) { + map::iterator inner_itr; + for(inner_itr = spell_script_itr->second.begin(); inner_itr != spell_script_itr->second.end(); inner_itr++) { + LuaSpell* cur_spell = inner_itr->second; + MSpellDelete.lock(); + RemoveCurrentSpell(inner_itr->first, inner_itr->second, false, true, false); + MSpellDelete.unlock(); + lua_close(inner_itr->first); + safe_delete(cur_spell); + } + + Mutex* mutex = GetSpellScriptMutex(spell_script_itr->first.c_str()); + safe_delete(mutex); } + current_spells.clear(); + spell_scripts_mutex.clear(); spell_scripts.clear(); - spells.clear(); MSpells.unlock(); } @@ -597,13 +605,13 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) { return spell; } -void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell) { +void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) { if(needsLock) { MSpells.lock(); MSpellDelete.lock(); } map::iterator itr = current_spells.find(state); - if(itr->second) { + if(removeSpellScript && itr->second) { MSpellScripts.readlock(__FUNCTION__, __LINE__); map >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name); if(spell_script_itr != spell_scripts.end()) { diff --git a/source/WorldServer/LuaInterface.h b/source/WorldServer/LuaInterface.h index 1b889c7..66ae196 100644 --- a/source/WorldServer/LuaInterface.h +++ b/source/WorldServer/LuaInterface.h @@ -234,7 +234,7 @@ public: std::string AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast = false, const char* function = 0, SpellScriptTimer* timer = 0, bool passLuaSpell=false, Spawn* altTarget = 0); LuaSpell* GetCurrentSpell(lua_State* state, bool needsLock = true); - void RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock = true, bool removeCurSpell = true); + void RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock = true, bool removeCurSpell = true, bool removeSpellScript = true); bool CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string functionCalled); LuaSpell* GetSpell(const char* name); void UseItemScript(const char* name, lua_State* state, bool val); @@ -322,7 +322,6 @@ private: vector* GetDirectoryListing(const char* directory); lua_State* LoadLuaFile(const char* name); void RegisterFunctions(lua_State* state); - map spells; map inverse_spells; map quests;