mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Add proper support for server list provider cache
This commit is contained in:
@@ -675,10 +675,6 @@ public static class ASF {
|
||||
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<string> botNames;
|
||||
|
||||
try {
|
||||
|
||||
@@ -353,6 +353,9 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
|
||||
}
|
||||
);
|
||||
|
||||
// Decrease the ServerList cache in order to fight with Steam gibberish data
|
||||
SteamConfiguration.ServerList.ServerListBeforeRefreshTimeSpan = TimeSpan.FromHours(1);
|
||||
|
||||
// Initialize
|
||||
SteamClient = new SteamClient(SteamConfiguration, botName);
|
||||
|
||||
|
||||
@@ -34,23 +34,25 @@ using SteamKit2.Discovery;
|
||||
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<ServerRecordEndPoint> ServerRecords { get; init; } = [];
|
||||
private ConcurrentList<ServerRecordEndPoint> ServerRecords { get; init; } = [];
|
||||
|
||||
public Task<IEnumerable<ServerRecord>> 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<ServerRecord> endpoints) {
|
||||
ArgumentNullException.ThrowIfNull(endpoints);
|
||||
|
||||
HashSet<ServerRecordEndPoint> newServerRecords = endpoints.Select(static endpoint => new ServerRecordEndPoint(endpoint.GetHost(), (ushort) endpoint.GetPort(), endpoint.ProtocolTypes)).ToHashSet();
|
||||
LastServerListRefresh = DateTime.UtcNow;
|
||||
|
||||
if (ServerRecords.ReplaceIfNeededWith(newServerRecords)) {
|
||||
ServerListUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
IEnumerable<ServerRecordEndPoint> serverRecords = endpoints.Select(static endpoint => new ServerRecordEndPoint(endpoint.GetHost(), (ushort) endpoint.GetPort(), endpoint.ProtocolTypes));
|
||||
|
||||
ServerRecords.ReplaceWith(serverRecords);
|
||||
|
||||
ServerListUpdated?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user