Files
Eero caec44c57d Fix concurrent access issues with ConnectedClients
Replaced direct access to GameMain.Server.ConnectedClients with array snapshots in multiple server-side classes to prevent concurrent modification issues during parallel updates. Also updated PhysicsBody and LevelTrigger to avoid static/shared state in parallel contexts, improving thread safety and reliability.
2026-01-08 00:26:29 +08:00

42 lines
1.4 KiB
C#

using System.Linq;
namespace Barotrauma
{
partial class EventObjectiveAction : EventAction
{
partial void UpdateProjSpecific()
{
if (GameMain.Server == null) { return; }
EventManager.NetEventObjective objective = new EventManager.NetEventObjective(
Type,
Identifier,
ObjectiveTag,
TextTag,
ParentObjectiveId,
CanBeCompleted);
// Create snapshot to avoid concurrent access issues during parallel updates
var clients = GameMain.Server.ConnectedClients.ToArray();
if (TargetTag.IsEmpty)
{
foreach (var client in clients)
{
if (client.Character == null) { continue; }
EventManager.ServerWriteObjective(client, objective);
}
}
else
{
foreach (var target in ParentEvent.GetTargets(TargetTag))
{
if (target is not Character character) { continue; }
var ownerClient = clients.FirstOrDefault(c => c.Character == character);
if (ownerClient == null) { continue; }
EventManager.ServerWriteObjective(ownerClient, objective);
}
}
}
}
}