From 727040d2dd128e9d47dc4e69ee91d21b67d806a0 Mon Sep 17 00:00:00 2001 From: Emagi Date: Mon, 2 Sep 2024 08:15:41 -0400 Subject: [PATCH] Attempt to fix deleting spells more than once if short durations --- source/WorldServer/LuaInterface.cpp | 4 +++- source/WorldServer/LuaInterface.h | 3 ++- source/WorldServer/SpellProcess.cpp | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index a36afab..32dc600 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -288,7 +288,8 @@ bool LuaInterface::LoadLuaSpell(const char* name) { spell->restored = false; spell->initial_caster_char_id = 0; spell->initial_target_char_id = 0; - + spell->spell_deleting = false; + MSpells.lock(); if (spells.count(lua_script) > 0) { @@ -2078,6 +2079,7 @@ LuaSpell* LuaInterface::GetSpell(const char* name) { new_spell->restored = false; new_spell->initial_caster_char_id = 0; new_spell->initial_target_char_id = 0; + new_spell->spell_deleting = false; return new_spell; } else{ diff --git a/source/WorldServer/LuaInterface.h b/source/WorldServer/LuaInterface.h index 8bd5966..b51afb7 100644 --- a/source/WorldServer/LuaInterface.h +++ b/source/WorldServer/LuaInterface.h @@ -22,6 +22,7 @@ #include #include +#include #include "Spawn.h" #include "Spells.h" @@ -102,7 +103,7 @@ struct LuaSpell{ Mutex MSpellTargets; int32 effect_bitmask; bool restored; // restored spell cross zone - + std::atomic spell_deleting; }; class LUAUserData{ diff --git a/source/WorldServer/SpellProcess.cpp b/source/WorldServer/SpellProcess.cpp index 3ee9ca0..a9d9d7d 100644 --- a/source/WorldServer/SpellProcess.cpp +++ b/source/WorldServer/SpellProcess.cpp @@ -414,11 +414,12 @@ bool SpellProcess::DeleteCasterSpell(LuaSpell* spell, string reason, bool removi if(shared_lock_spell && !removing_all_spells) { MSpellProcess.lock_shared(); } - + bool ret = false; Spawn* target = 0; bool target_valid = false; - if(spell) { + if(spell && !spell->spell_deleting) { + spell->spell_deleting = true; spell->MSpellTargets.writelock(__FUNCTION__, __LINE__); if(remove_target && spell->targets.size() > 1) { for (int32 i = 0; i < spell->targets.size(); i++) {