diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index c5c54fc54ff95..bba1ca5ec8d4a 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -675,10 +675,6 @@ private static async Task RegisterBots() { throw new InvalidOperationException(nameof(WebBrowser)); } - // Kill SK2 servers cache in order to force refresh during initial connection - // TODO: This should be removed when SK2 learns to purge its stale cache itself - await GlobalDatabase.ServerListProvider.UpdateServerListAsync([]).ConfigureAwait(false); - HashSet botNames; try { diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 4efb3e6f0293c..658bd19fec389 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -353,6 +353,9 @@ private Bot(string botName, BotConfig botConfig, BotDatabase botDatabase) { } ); + // Decrease the ServerList cache in order to fight with Steam gibberish data + SteamConfiguration.ServerList.ServerListBeforeRefreshTimeSpan = TimeSpan.FromHours(1); + // Initialize SteamClient = new SteamClient(SteamConfiguration, botName); diff --git a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs index e67b0fc308695..cf6ae5f6a7542 100644 --- a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs @@ -34,23 +34,25 @@ namespace ArchiSteamFarm.Steam.SteamKit2; internal sealed class InMemoryServerListProvider : IServerListProvider { - // TODO - public DateTime LastServerListRefresh => DateTime.MinValue; + [JsonInclude] + public DateTime LastServerListRefresh { get; private set; } [JsonDisallowNull] [JsonInclude] - private ConcurrentHashSet ServerRecords { get; init; } = []; + private ConcurrentList ServerRecords { get; init; } = []; public Task> FetchServerListAsync() => Task.FromResult(ServerRecords.Where(static server => !string.IsNullOrEmpty(server.Host) && server is { Port: > 0, ProtocolTypes: > 0 }).Select(static server => ServerRecord.CreateServer(server.Host, server.Port, server.ProtocolTypes))); public Task UpdateServerListAsync(IEnumerable endpoints) { ArgumentNullException.ThrowIfNull(endpoints); - HashSet newServerRecords = endpoints.Select(static endpoint => new ServerRecordEndPoint(endpoint.GetHost(), (ushort) endpoint.GetPort(), endpoint.ProtocolTypes)).ToHashSet(); + LastServerListRefresh = DateTime.UtcNow; + + IEnumerable serverRecords = endpoints.Select(static endpoint => new ServerRecordEndPoint(endpoint.GetHost(), (ushort) endpoint.GetPort(), endpoint.ProtocolTypes)); + + ServerRecords.ReplaceWith(serverRecords); - if (ServerRecords.ReplaceIfNeededWith(newServerRecords)) { - ServerListUpdated?.Invoke(this, EventArgs.Empty); - } + ServerListUpdated?.Invoke(this, EventArgs.Empty); return Task.CompletedTask; }