mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Don't keep SteamTimeDifference infinitely
With long-running systems time might run out of sync eventually.
This commit is contained in:
@@ -37,7 +37,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private readonly ArchiLogger ArchiLogger;
|
||||
|
||||
internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue;
|
||||
internal DateTime LastPacketReceived { get; private set; }
|
||||
|
||||
internal ArchiHandler(ArchiLogger archiLogger) => ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace ArchiSteamFarm {
|
||||
private string CachedApiKey;
|
||||
private bool? CachedPublicInventory;
|
||||
private string CachedTradeToken;
|
||||
private DateTime LastSessionRefreshCheck = DateTime.MinValue;
|
||||
private DateTime LastSessionRefreshCheck;
|
||||
private bool MarkingInventoryScheduled;
|
||||
private ulong SteamID;
|
||||
private string VanityURL;
|
||||
|
||||
@@ -34,10 +34,12 @@ namespace ArchiSteamFarm {
|
||||
internal sealed class MobileAuthenticator : IDisposable {
|
||||
private const byte CodeDigits = 5;
|
||||
private const byte CodeInterval = 30;
|
||||
private const byte SteamTimeTTL = 24; // For how many hours we can assume that SteamTimeDifference is correct
|
||||
|
||||
private static readonly char[] CodeCharacters = { '2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y' };
|
||||
private static readonly SemaphoreSlim TimeSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
private static DateTime LastSteamTimeCheck;
|
||||
private static int? SteamTimeDifference;
|
||||
|
||||
// "ERROR" is being used by SteamDesktopAuthenticator
|
||||
@@ -338,10 +340,14 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
private async Task<uint> GetSteamTime() {
|
||||
if (SteamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalHours < SteamTimeTTL)) {
|
||||
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.Value);
|
||||
}
|
||||
|
||||
await TimeSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try {
|
||||
if (SteamTimeDifference.HasValue) {
|
||||
if (SteamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalHours < SteamTimeTTL)) {
|
||||
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.Value);
|
||||
}
|
||||
|
||||
@@ -351,6 +357,8 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
SteamTimeDifference = (int) (serverTime - Utilities.GetUnixTime());
|
||||
LastSteamTimeCheck = DateTime.UtcNow;
|
||||
|
||||
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.Value);
|
||||
} finally {
|
||||
TimeSemaphore.Release();
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace ArchiSteamFarm {
|
||||
private readonly Bot Bot;
|
||||
private readonly SemaphoreSlim RequestsSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
private DateTime LastAnnouncementCheck = DateTime.MinValue;
|
||||
private DateTime LastHeartBeat = DateTime.MinValue;
|
||||
private DateTime LastPersonaStateRequest = DateTime.MinValue;
|
||||
private DateTime LastAnnouncementCheck;
|
||||
private DateTime LastHeartBeat;
|
||||
private DateTime LastPersonaStateRequest;
|
||||
private bool ShouldSendHeartBeats;
|
||||
|
||||
internal Statistics(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
|
||||
|
||||
Reference in New Issue
Block a user