fixed some races

This commit is contained in:
Tahir Akhlaq 2017-06-06 02:03:56 +01:00
parent 52cacb1ded
commit 72099e92bb

View File

@ -64,7 +64,7 @@ namespace FFXIVClassic_Map_Server.Actors
this.displayNameId = 0; this.displayNameId = 0;
this.customDisplayName = "_areaMaster"; this.customDisplayName = "_areaMaster";
this.actorName = String.Format("_areaMaster@{0:X5}",id<<8); this.actorName = String.Format("_areaMaster@{0:X5}", id << 8);
this.classPath = classPath; this.classPath = classPath;
this.className = classPath.Substring(classPath.LastIndexOf("/") + 1); this.className = classPath.Substring(classPath.LastIndexOf("/") + 1);
@ -77,12 +77,11 @@ namespace FFXIVClassic_Map_Server.Actors
for (int y = 0; y < numYBlocks; y++) for (int y = 0; y < numYBlocks; y++)
{ {
for (int x = 0; x < numXBlocks; x++ ) for (int x = 0; x < numXBlocks; x++)
{ {
mActorBlock[x, y] = new List<Actor>(); mActorBlock[x, y] = new List<Actor>();
} }
} }
} }
public override SubPacket CreateScriptBindPacket(uint playerActorId) public override SubPacket CreateScriptBindPacket(uint playerActorId)
@ -109,8 +108,11 @@ namespace FFXIVClassic_Map_Server.Actors
public void AddActorToZone(Actor actor) public void AddActorToZone(Actor actor)
{ {
if (!mActorList.ContainsKey(actor.actorId)) lock (mActorList)
mActorList.Add(actor.actorId, actor); {
if (!mActorList.ContainsKey(actor.actorId))
mActorList.Add(actor.actorId, actor);
}
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
@ -134,7 +136,8 @@ namespace FFXIVClassic_Map_Server.Actors
public void RemoveActorFromZone(Actor actor) public void RemoveActorFromZone(Actor actor)
{ {
mActorList.Remove(actor.actorId); lock (mActorList)
mActorList.Remove(actor.actorId);
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
@ -223,11 +226,14 @@ namespace FFXIVClassic_Map_Server.Actors
List<Actor> result = new List<Actor>(); List<Actor> result = new List<Actor>();
for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++) lock (mActorBlock)
{ {
for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++) for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++)
{ {
result.AddRange(mActorBlock[gx, gy]); for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++)
{
result.AddRange(mActorBlock[gx, gy]);
}
} }
} }
@ -266,14 +272,16 @@ namespace FFXIVClassic_Map_Server.Actors
List<Actor> result = new List<Actor>(); List<Actor> result = new List<Actor>();
for (int gy = ((gridY - checkDistance) < 0 ? 0 : (gridY - checkDistance)); gy <= ((gridY + checkDistance) >= numYBlocks ? numYBlocks - 1 : (gridY + checkDistance)); gy++) lock (mActorBlock)
{ {
for (int gx = ((gridX - checkDistance) < 0 ? 0 : (gridX - checkDistance)); gx <= ((gridX + checkDistance) >= numXBlocks ? numXBlocks - 1 : (gridX + checkDistance)); gx++) for (int gy = ((gridY - checkDistance) < 0 ? 0 : (gridY - checkDistance)); gy <= ((gridY + checkDistance) >= numYBlocks ? numYBlocks - 1 : (gridY + checkDistance)); gy++)
{ {
result.AddRange(mActorBlock[gx, gy]); for (int gx = ((gridX - checkDistance) < 0 ? 0 : (gridX - checkDistance)); gx <= ((gridX + checkDistance) >= numXBlocks ? numXBlocks - 1 : (gridX + checkDistance)); gx++)
{
result.AddRange(mActorBlock[gx, gy]);
}
} }
} }
//Remove players if isolation zone //Remove players if isolation zone
if (isIsolated) if (isIsolated)
{ {
@ -291,19 +299,25 @@ namespace FFXIVClassic_Map_Server.Actors
public Actor FindActorInArea(uint id) public Actor FindActorInArea(uint id)
{ {
if (!mActorList.ContainsKey(id)) lock (mActorList)
return null; {
return mActorList[id]; if (!mActorList.ContainsKey(id))
return null;
return mActorList[id];
}
} }
public Actor FindActorInZoneByUniqueID(string uniqueId) public Actor FindActorInZoneByUniqueID(string uniqueId)
{ {
foreach (Actor a in mActorList.Values) lock (mActorList)
{ {
if (a is Npc) foreach (Actor a in mActorList.Values)
{ {
if (((Npc)a).GetUniqueId().ToLower().Equals(uniqueId)) if (a is Npc)
return a; {
if (((Npc)a).GetUniqueId().ToLower().Equals(uniqueId))
return a;
}
} }
} }
return null; return null;
@ -311,33 +325,45 @@ namespace FFXIVClassic_Map_Server.Actors
public Player FindPCInZone(string name) public Player FindPCInZone(string name)
{ {
foreach (Actor a in mActorList.Values) lock (mActorList)
{ {
if (a is Player) foreach (Actor a in mActorList.Values)
{ {
if (((Player)a).customDisplayName.ToLower().Equals(name.ToLower())) if (a is Player)
return (Player)a; {
if (((Player)a).customDisplayName.ToLower().Equals(name.ToLower()))
return (Player)a;
}
} }
return null;
} }
return null;
} }
public Player FindPCInZone(uint id) public Player FindPCInZone(uint id)
{ {
if (!mActorList.ContainsKey(id)) lock (mActorList)
return null; {
return (Player)mActorList[id]; if (!mActorList.ContainsKey(id))
return null;
return (Player)mActorList[id];
}
} }
public void Clear() public void Clear()
{ {
//Clear All lock (mActorList)
mActorList.Clear();
for (int y = 0; y < numYBlocks; y++)
{ {
for (int x = 0; x < numXBlocks; x++) //Clear All
mActorList.Clear();
lock (mActorBlock)
{ {
mActorBlock[x, y].Clear(); for (int y = 0; y < numYBlocks; y++)
{
for (int x = 0; x < numXBlocks; x++)
{
mActorBlock[x, y].Clear();
}
}
} }
} }
} }
@ -450,12 +476,15 @@ namespace FFXIVClassic_Map_Server.Actors
} }
if (zoneWide) if (zoneWide)
{ {
foreach (var actor in mActorList) lock (mActorList)
{ {
if (actor.Value is Player) foreach (var actor in mActorList)
{ {
player = ((Player)actor.Value); if (actor.Value is Player)
player.QueuePacket(BasePacket.CreatePacket(SetWeatherPacket.BuildPacket(player.actorId, weather, transitionTime), true, false)); {
player = ((Player)actor.Value);
player.QueuePacket(BasePacket.CreatePacket(SetWeatherPacket.BuildPacket(player.actorId, weather, transitionTime), true, false));
}
} }
} }
} }