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.
This commit is contained in:
Eero
2026-01-08 00:26:29 +08:00
parent f4a0d149ca
commit caec44c57d
13 changed files with 108 additions and 59 deletions
@@ -14,8 +14,10 @@ partial class HighlightAction : EventAction
IEnumerable<Client>? targetClients = null;
if (targetCharacters != null)
{
// Create snapshot to avoid concurrent access issues during parallel updates
var clients = GameMain.Server.ConnectedClients.ToArray();
targetClients = targetCharacters
.Select(c => GameMain.Server.ConnectedClients.FirstOrDefault(client => client.Character == c))
.Select(c => clients.FirstOrDefault(client => client.Character == c))
.Where(c => c != null)!;
}
GameMain.Server?.CreateEntityEvent(item, new Item.SetHighlightEventData(State, highlightColor, targetClients));