Browse Source

ghost map day #2 -- the reckoning?

Image 2 years ago
parent
commit
fcc409dacc

+ 1 - 1
EQ2/source/WorldServer/Combat.cpp

@@ -1251,7 +1251,7 @@ void Entity::ProcessCombat() {
 void NPC::ProcessCombat() {
 	MBrain.writelock(__FUNCTION__, __LINE__);
 	// Check to see if it is time to call the AI again
-	if (GetHP() > 0 && Timer::GetCurrentTime2() >= (m_brain->LastTick() + m_brain->Tick())) {
+	if (m_brain && GetHP() > 0 && Timer::GetCurrentTime2() >= (m_brain->LastTick() + m_brain->Tick())) {
 		// Probably never want to use the following log, will spam the console for every NPC in a zone 4 times a second
 		//LogWrite(NPC_AI__DEBUG, 9, "NPC_AI", "%s is thinking...", GetName());
 		m_brain->Think();

+ 1 - 1
EQ2/source/WorldServer/NPC.cpp

@@ -925,7 +925,7 @@ void NPC::SetBrain(::Brain* brain) {
 	// Again, had to use the '::' to refer to the Brain class and not the function defined in the NPC class
 	MBrain.writelock(__FUNCTION__, __LINE__);
 	// Check to make sure the NPC the brain controls matches this npc
-	if (brain->GetBody() != this) {
+	if (brain && brain->GetBody() != this) {
 		LogWrite(NPC_AI__ERROR, 0, "NPC_AI", "Brain body does not match the npc we tried to assign the brain to.");
 		MBrain.releasewritelock(__FUNCTION__, __LINE__);
 		return;

+ 4 - 4
EQ2/source/WorldServer/Spawn.cpp

@@ -709,8 +709,8 @@ uchar* Spawn::spawn_info_changes(Player* player, int16 version){
 		return nullptr;
 	}
 
-	uchar* tmp = new uchar[size + 10];
-	size = Pack(tmp, xor_info_packet, size, size, version);
+	uchar* tmp = new uchar[size + 1000];
+	size = Pack(tmp, xor_info_packet, size, size+1000, version);
 	player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
 
 	int32 orig_size = size;
@@ -1083,8 +1083,8 @@ uchar* Spawn::spawn_info_changes_ex(Player* player, int16 version) {
 		return nullptr;
 	}
 
-	uchar* tmp = new uchar[size + 10];
-	size = Pack(tmp, xor_info_packet, size, size, version);
+	uchar* tmp = new uchar[size + 1000];
+	size = Pack(tmp, xor_info_packet, size, size+1000, version);
 
 	player->info_mutex.releasewritelock(__FUNCTION__, __LINE__);
 

+ 7 - 1
EQ2/source/WorldServer/client.cpp

@@ -209,6 +209,7 @@ Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_deb
 	MSpellDetails.SetName("Client::MSpellDetails");
 	hasSentTempPlacementSpawn = false;
 	spawn_removal_timer.Start();
+	disable_save = false;
 }
 
 Client::~Client() {
@@ -789,7 +790,9 @@ void Client::SendCharInfo() {
 	GetPlayer()->ChangePrimaryWeapon();
 	GetPlayer()->ChangeSecondaryWeapon();
 	GetPlayer()->ChangeRangedWeapon();
-	database.LoadBuyBacks(this);
+	if(!GetPlayer()->IsReturningFromLD()) {
+		database.LoadBuyBacks(this);
+	}
 	if (version > 546)
 		master_aa_list.DisplayAA(this, 0, 0);
 
@@ -865,6 +868,7 @@ void Client::SendCharInfo() {
 
 	database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
 	database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
+
 	GetPlayer()->SetSaveSpellEffects(false);
 	GetPlayer()->SetCharSheetChanged(true);
 	GetPlayer()->SetReturningFromLD(false);
@@ -9823,6 +9827,7 @@ bool Client::HandleNewLogin(int32 account_id, int32 access_code)
 				if (client->GetCurrentZone() && !client->IsZoning()) {
 					//swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
 					if (client->GetVersion() == version) {
+						client->DisableSave();
 						client->ReplaceGroupClient(this);
 						Player* current_player = GetPlayer();
 						SetPlayer(client->GetPlayer());
@@ -9831,6 +9836,7 @@ bool Client::HandleNewLogin(int32 account_id, int32 access_code)
 						SetCurrentZone(GetPlayer()->GetZone());
 						GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
 						client->SetPlayer(current_player);
+						GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
 						GetPlayer()->ResetSavedSpawns();
 					}
 					ZoneServer* tmpZone = client->GetCurrentZone();

+ 4 - 0
EQ2/source/WorldServer/client.h

@@ -521,6 +521,9 @@ public:
 		sent_spell_details[id] = tier;
 		MSpellDetails.releasewritelock(__FUNCTION__, __LINE__);
 	}
+
+	void	DisableSave() { disable_save = true; }
+	bool	IsSaveDisabled() { return disable_save; }
 private:
 	void    SavePlayerImages();
 	void	SkillChanged(Skill* skill, int16 previous_value, int16 new_value);
@@ -645,6 +648,7 @@ private:
 	bool player_loading_complete;
 	Mutex MItemDetails;
 	Mutex MSpellDetails;
+	bool disable_save;
 };
 
 class ClientList {

+ 16 - 28
EQ2/source/WorldServer/zoneserver.cpp

@@ -28,6 +28,7 @@ using namespace std;
 #include <regex>
 #include "Commands/Commands.h"
 #include "Zone/pathfinder_interface.h"
+#include "NPC_AI.h"
 
 #ifdef WIN32
 #include <WinSock2.h>
@@ -1086,7 +1087,7 @@ void ZoneServer::CheckSendSpawnToClient(Client* client, bool initial_login) {
 		return;
 	}
 
-	if (!initial_login && !client->GetInitialSpawnsSent() || (!initial_login && !client->IsReadyForUpdates()))
+	if (!initial_login && !client->GetInitialSpawnsSent() || (!initial_login && !client->IsReadyForSpawns()))
 		return;
 
 	Spawn* spawn = 0;
@@ -1231,6 +1232,14 @@ void ZoneServer::DeleteSpawns(bool delete_all) {
 				if (spawn && movementMgr != nullptr) {
 					movementMgr->RemoveMob((Entity*)spawn);
 				}
+
+				// delete brain if it has one
+				if(spawn->IsNPC()) {
+					NPC* tmpNPC = (NPC*)spawn;
+					if(tmpNPC->Brain())
+						tmpNPC->SetBrain(nullptr);
+				}
+
 				erase_itr = itr++;
 				spawn_delete_list.erase(erase_itr);
 				
@@ -3142,33 +3151,12 @@ void ZoneServer::RemoveClientImmediately(Client* client) {
 
 	if(client) 
 	{
-		database.ToggleCharacterOnline(client, 0);
-		loginserver.SendImmediateEquipmentUpdatesForChar(client->GetPlayer()->GetCharacterID());
-		if(connected_clients.count(client) > 0)
-		{
-			if (!client->IsZoning() && (guild = client->GetPlayer()->GetGuild()))
-				guild->GuildMemberLogoff(client->GetPlayer());
-			
-			MClientList.writelock(__FUNCTION__, __LINE__);
-			std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
-			if (itr != clients.end())
-				clients.erase(itr);
-			MClientList.releasewritelock(__FUNCTION__, __LINE__);
-			//clients.Remove(client);
-			LogWrite(ZONE__INFO, 0, "Zone", "Removing connection for client '%s'.", client->GetPlayer()->GetName());
-			connected_clients.Remove(client, true);
-			// client is deleted at this point
-			client = 0;
-		}
-		else
-		{
-			MClientList.writelock(__FUNCTION__, __LINE__);
-			std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
-			if (itr != clients.end())
-				clients.erase(itr);
-			MClientList.releasewritelock(__FUNCTION__, __LINE__);
+		MClientList.writelock(__FUNCTION__, __LINE__);
+		std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
+		if (itr != clients.end())
+			clients.erase(itr);
+		MClientList.releasewritelock(__FUNCTION__, __LINE__);
 			//clients.Remove(client, true);
-		}
 	}
 }
 
@@ -3969,7 +3957,7 @@ void ZoneServer::RemoveSpawn(Spawn* spawn, bool delete_spawn, bool respawn, bool
 	MClientList.releasereadlock(__FUNCTION__, __LINE__);
 
 	safe_delete(packet);
-
+	
 	spawn->RemoveSpawnProximities();
 	RemoveSpawnProximities(spawn);