Browse Source

Stop crash when player/spawn zone is not yet set

Emagi 1 year ago
parent
commit
00d92aed43
2 changed files with 51 additions and 44 deletions
  1. 6 1
      EQ2/source/WorldServer/LuaInterface.cpp
  2. 45 43
      EQ2/source/WorldServer/SpellProcess.cpp

+ 6 - 1
EQ2/source/WorldServer/LuaInterface.cpp

@@ -842,6 +842,9 @@ void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool
 	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
 	if(spell->caster) {
 		for (int8 i = 0; i < spell->targets.size(); i++) {
+			if(!spell->caster->GetZone())
+				continue;
+			
 			Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
 			if (!target || !target->IsEntity())
 				continue;
@@ -875,7 +878,9 @@ void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool
 	}
 	if (spell->caster)
 	{
-		spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell);
+		if(spell->caster->GetZone()) {
+			spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell);
+		}
 		spell->caster->RemoveProc(0, spell);
 		spell->caster->RemoveMaintainedSpell(spell);
 

+ 45 - 43
EQ2/source/WorldServer/SpellProcess.cpp

@@ -436,55 +436,57 @@ bool SpellProcess::DeleteCasterSpell(LuaSpell* spell, string reason, bool removi
 			spell->caster->RemoveMaintainedSpell(spell);
 			CheckRemoveTargetFromSpell(spell, removing_all_spells, removing_all_spells);
 			ZoneServer* zone = spell->caster->GetZone();
-			spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
-			for (int32 i = 0; i < spell->targets.size(); i++) {
-				target = zone->GetSpawnByID(spell->targets.at(i));
-				if(target && target->IsEntity()){
-					spell->removed_targets.push_back(target->GetID());
-					((Entity*)target)->RemoveProc(0, spell);
-					((Entity*)target)->RemoveSpellEffect(spell);
-					((Entity*)target)->RemoveSpellBonus(spell);
-					if(spell->spell->GetSpellData()->det_type > 0 && (spell->spell->GetSpellDuration() > 0 || spell->spell->GetSpellData()->duration_until_cancel))
-						((Entity*)target)->RemoveDetrimentalSpell(spell);
-				}
-				else{
-					spell->caster->RemoveSpellEffect(spell);
-					spell->caster->RemoveSpellBonus(spell);
-					if(spell->spell->GetSpellData()->det_type > 0 && (spell->spell->GetSpellDuration() > 0 || spell->spell->GetSpellData()->duration_until_cancel))
-						spell->caster->RemoveDetrimentalSpell(spell);
-				}
-				if(target && target->IsPlayer() && spell->spell->GetSpellData()->fade_message.length() > 0){
-					Client* client = target->GetZone()->GetClientBySpawn(target);
-					if(client){
-						bool send_to_sender = true;
-						string fade_message = spell->spell->GetSpellData()->fade_message;
-						if(fade_message.find("%t") != string::npos)
-							fade_message.replace(fade_message.find("%t"), 2, target->GetName());						
-						client->Message(CHANNEL_SPELLS_OTHER, fade_message.c_str());
+			if(zone) {
+				spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
+				for (int32 i = 0; i < spell->targets.size(); i++) {
+					target = zone->GetSpawnByID(spell->targets.at(i));
+					if(target && target->IsEntity()){
+						spell->removed_targets.push_back(target->GetID());
+						((Entity*)target)->RemoveProc(0, spell);
+						((Entity*)target)->RemoveSpellEffect(spell);
+						((Entity*)target)->RemoveSpellBonus(spell);
+						if(spell->spell->GetSpellData()->det_type > 0 && (spell->spell->GetSpellDuration() > 0 || spell->spell->GetSpellData()->duration_until_cancel))
+							((Entity*)target)->RemoveDetrimentalSpell(spell);
 					}
-				}
-				if (target && target->IsPlayer() && spell->spell->GetSpellData()->fade_message.length() > 0) {
-					Client* client = target->GetZone()->GetClientBySpawn(target);
-					if (client) {
-						bool send_to_sender = true;
-						string fade_message_others = spell->spell->GetSpellData()->fade_message_others;
-						if (fade_message_others.find("%t") != string::npos)
-							fade_message_others.replace(fade_message_others.find("%t"), 2, target->GetName());
-						if (fade_message_others.find("%c") != string::npos)
-							fade_message_others.replace(fade_message_others.find("%c"), 2, spell->caster->GetName());
-						if (fade_message_others.find("%T") != string::npos) {
-							fade_message_others.replace(fade_message_others.find("%T"), 2, target->GetName());
-							send_to_sender = false;
+					else{
+						spell->caster->RemoveSpellEffect(spell);
+						spell->caster->RemoveSpellBonus(spell);
+						if(spell->spell->GetSpellData()->det_type > 0 && (spell->spell->GetSpellDuration() > 0 || spell->spell->GetSpellData()->duration_until_cancel))
+							spell->caster->RemoveDetrimentalSpell(spell);
+					}
+					if(target && target->IsPlayer() && spell->spell->GetSpellData()->fade_message.length() > 0){
+						Client* client = target->GetZone()->GetClientBySpawn(target);
+						if(client){
+							bool send_to_sender = true;
+							string fade_message = spell->spell->GetSpellData()->fade_message;
+							if(fade_message.find("%t") != string::npos)
+								fade_message.replace(fade_message.find("%t"), 2, target->GetName());						
+							client->Message(CHANNEL_SPELLS_OTHER, fade_message.c_str());
 						}
-						if (fade_message_others.find("%C") != string::npos) {
-							fade_message_others.replace(fade_message_others.find("%C"), 2, spell->caster->GetName());
-							send_to_sender = false;
+					}
+					if (target && target->IsPlayer() && spell->spell->GetSpellData()->fade_message.length() > 0) {
+						Client* client = target->GetZone()->GetClientBySpawn(target);
+						if (client) {
+							bool send_to_sender = true;
+							string fade_message_others = spell->spell->GetSpellData()->fade_message_others;
+							if (fade_message_others.find("%t") != string::npos)
+								fade_message_others.replace(fade_message_others.find("%t"), 2, target->GetName());
+							if (fade_message_others.find("%c") != string::npos)
+								fade_message_others.replace(fade_message_others.find("%c"), 2, spell->caster->GetName());
+							if (fade_message_others.find("%T") != string::npos) {
+								fade_message_others.replace(fade_message_others.find("%T"), 2, target->GetName());
+								send_to_sender = false;
+							}
+							if (fade_message_others.find("%C") != string::npos) {
+								fade_message_others.replace(fade_message_others.find("%C"), 2, spell->caster->GetName());
+								send_to_sender = false;
+							}
+							spell->caster->GetZone()->SimpleMessage(CHANNEL_SPELLS_OTHER, fade_message_others.c_str(), target, 50, send_to_sender);
 						}
-						spell->caster->GetZone()->SimpleMessage(CHANNEL_SPELLS_OTHER, fade_message_others.c_str(), target, 50, send_to_sender);
 					}
 				}
+				spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 			}
-			spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 			ret = true;
 		}
 		if(lua_interface)