Browse Source

Crash fixes and LUA GetFactionAmount is now signed integer as it should be

- Fix GetFactionAmount to be Signed Integer
- Crash fix spell removal on zone shutdown when player already left
- PlayerItems mutex fixes
- Movement Location mutex fixes
Image 2 years ago
parent
commit
c6744428a8

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

@@ -718,7 +718,7 @@ int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
 	Player* player = (Player*)lua_interface->GetSpawn(state);
 	int32 faction_id = lua_interface->GetInt32Value(state, 2);
 	if (player && player->IsPlayer() && faction_id > 0) {
-		lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
+		lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
 		return 1;
 	}
 	return 0;

+ 12 - 3
EQ2/source/WorldServer/Player.cpp

@@ -2154,9 +2154,10 @@ vector<EQ2Packet*> Player::EquipItem(int16 index, int16 version, int8 appearance
 				//packets.reserve(packets.size() + tmp_packets.size());
 				packets.insert(packets.end(), tmp_packets.begin(), tmp_packets.end());
 			}
-			
-			// release for delete item / scripting etc
-			item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
+			else {
+				// release for delete item / scripting etc
+				item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
+			}
 		}
 		else if (canEquip && slot < 255) {
 			// If item is a 2handed weapon and something is in the secondary, unequip the secondary
@@ -2205,6 +2206,14 @@ vector<EQ2Packet*> Player::EquipItem(int16 index, int16 version, int8 appearance
 			}
 			SetCharSheetChanged(true);
 		}
+		else {
+				// clear items lock
+				item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
+		}
+	}
+	else {
+			// clear items lock
+			item_list.MPlayerItems.releasereadlock(__FUNCTION__, __LINE__);
 	}
 	
 	client->UpdateSentSpellList();

+ 29 - 15
EQ2/source/WorldServer/Spawn.cpp

@@ -3055,21 +3055,29 @@ void Spawn::RunToLocation(float x, float y, float z, float following_x, float fo
 
 MovementLocation* Spawn::GetCurrentRunningLocation(){
 	MovementLocation* ret = 0;
-	if(movement_locations && movement_locations->size() > 0){
+	if(MMovementLocations)
 		MMovementLocations->readlock(__FUNCTION__, __LINE__);
+	
+	if(movement_locations && movement_locations->size() > 0){
 		ret = movement_locations->front();
-		MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
 	}
+
+	if(MMovementLocations)
+		MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
 	return ret;
 }
 
 MovementLocation* Spawn::GetLastRunningLocation(){
 	MovementLocation* ret = 0;
-	if(movement_locations && movement_locations->size() > 0){
+	if(MMovementLocations)
 		MMovementLocations->readlock(__FUNCTION__, __LINE__);
+		
+	if(movement_locations && movement_locations->size() > 0){
 		ret = movement_locations->back();
-		MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
 	}
+
+	if(MMovementLocations)
+		MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
 	return ret;
 }
 
@@ -3238,7 +3246,7 @@ void Spawn::CalculateRunningLocation(bool stop){
 		return;
 	else if (!pauseTimerEnabled && !stop)
 		last_location_update = Timer::GetCurrentTime2();
-
+	bool continueElseIf = true;
 	bool removed = CalculateChange();
 	if (stop || pauseTimerEnabled) {
 		//following = false;
@@ -3248,21 +3256,27 @@ void Spawn::CalculateRunningLocation(bool stop){
 		SetPos(&appearance.pos.X3, GetX(), false);
 		SetPos(&appearance.pos.Y3, GetY(), false);
 		SetPos(&appearance.pos.Z3, GetZ(), false);
+		continueElseIf = false;
 	}
-	else if (removed && movement_locations && movement_locations->size() > 0) {
+	else if (removed && movement_locations && MMovementLocations) {
 		if (MMovementLocations)
 			MMovementLocations->readlock(__FUNCTION__, __LINE__);
-		MovementLocation* current_location = movement_locations->at(0);
-		if (movement_locations->size() > 1) {
-			MovementLocation* data = movement_locations->at(1);
-			RunToLocation(current_location->x, current_location->y, current_location->z, data->x, data->y, data->z);
-		}
-		else
-			RunToLocation(current_location->x, current_location->y, current_location->z, 0, 0, 0);
+			if(movement_locations->size() > 0) {
+				MovementLocation* current_location = movement_locations->at(0);
+				if (movement_locations->size() > 1) {
+					MovementLocation* data = movement_locations->at(1);
+					RunToLocation(current_location->x, current_location->y, current_location->z, data->x, data->y, data->z);
+				}
+				else
+					RunToLocation(current_location->x, current_location->y, current_location->z, 0, 0, 0);
+				
+				continueElseIf = false;
+			}
 		if (MMovementLocations)
 			MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
 	}
-	else if (GetZone() && GetTarget() != NULL && EngagedInCombat())
+	
+	if (continueElseIf && GetZone() && GetTarget() != NULL && EngagedInCombat())
 	{
 		if (GetDistance(GetTarget()) > rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())
 		{
@@ -3274,7 +3288,7 @@ void Spawn::CalculateRunningLocation(bool stop){
 		else
 			((Entity*)this)->HaltMovement();
 	}
-	else if (!following)
+	else if (continueElseIf && !following)
 	{
 		position_changed = true;
 		changed = true;

+ 10 - 1
EQ2/source/WorldServer/Spawn.h

@@ -1044,7 +1044,16 @@ public:
 	bool	NeedsToResumeMovement(){ return attack_resume_needed; }
 	void	NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
 	bool	HasMovementLoop(){ return movement_loop.size() > 0; }
-	bool	HasMovementLocations() { return movement_locations ? movement_locations->size() > 0 : false; }
+	bool	HasMovementLocations() { 
+			bool hasLocations = false;
+			if (MMovementLocations)
+				MMovementLocations->readlock(__FUNCTION__, __LINE__);
+				hasLocations = movement_locations ? movement_locations->size() > 0 : false;
+			if (MMovementLocations)
+				MMovementLocations->releasereadlock(__FUNCTION__, __LINE__);
+			return hasLocations;
+	}
+
 	Timer*	GetRunningTimer();
 	float	GetFaceTarget(float x, float z);
 	void	FaceTarget(float x, float z);

+ 3 - 0
EQ2/source/WorldServer/client.cpp

@@ -232,6 +232,9 @@ Client::~Client() {
 
 
 void Client::RemoveClientFromZone() {
+	if(player && player->GetZone())
+		player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true);
+		
 	if (current_zone && player) {
 		if (player->GetGroupMemberInfo())
 		{