Change classes that use FieldLoader to use read-only collections.

This commit is contained in:
RoosterDragon
2025-11-08 12:40:56 +00:00
committed by Paul Chote
parent 797c71e500
commit 649e7e8c28
308 changed files with 1233 additions and 901 deletions

View File

@@ -10,7 +10,9 @@
#endregion
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using OpenRA.Primitives;
@@ -47,7 +49,7 @@ namespace OpenRA.Network
public class GameServer
{
static readonly string[] SerializeFields =
static readonly ImmutableArray<string> SerializeFields =
[
// Server information
@@ -131,10 +133,10 @@ namespace OpenRA.Network
public readonly bool IsJoinable = false;
[FieldLoader.LoadUsing(nameof(LoadClients))]
public readonly GameClient[] Clients;
public readonly ImmutableArray<GameClient> Clients;
/// <summary>The list of spawnpoints that are disabled for this game.</summary>
public readonly int[] DisabledSpawnPoints = [];
public readonly FrozenSet<int> DisabledSpawnPoints = FrozenSet<int>.Empty;
public string ModLabel => $"{ModTitle} ({Version})";
@@ -150,7 +152,7 @@ namespace OpenRA.Network
clients.Add(FieldLoader.Load<GameClient>(client.Value));
}
return clients.ToArray();
return clients.ToImmutableArray();
}
public GameServer(MiniYaml yaml)
@@ -227,9 +229,9 @@ namespace OpenRA.Network
ModWebsite = manifest.Metadata.Website;
ModIcon32 = manifest.Metadata.WebIcon32;
Protected = !string.IsNullOrEmpty(server.Settings.Password);
Authentication = server.Settings.RequireAuthentication || server.Settings.ProfileIDWhitelist.Length > 0;
Clients = server.LobbyInfo.Clients.Select(c => new GameClient(c)).ToArray();
DisabledSpawnPoints = server.LobbyInfo.DisabledSpawnPoints?.ToArray() ?? [];
Authentication = server.Settings.RequireAuthentication || server.Settings.ProfileIDWhitelist.Count > 0;
Clients = server.LobbyInfo.Clients.Select(c => new GameClient(c)).ToImmutableArray();
DisabledSpawnPoints = server.LobbyInfo.DisabledSpawnPoints?.ToFrozenSet() ?? FrozenSet<int>.Empty;
}
public string ToPOSTData(bool lanGame)