Optimize SteamTimeDifference

In very unlikely case of actually having exactly the same time difference, notice the difference between no value and value of 0
This commit is contained in:
JustArchi
2016-09-05 18:46:00 +02:00
parent cada3fa920
commit e020f54753

View File

@@ -64,7 +64,7 @@ namespace ArchiSteamFarm {
private static readonly SemaphoreSlim TimeSemaphore = new SemaphoreSlim(1);
private static short SteamTimeDifference;
private static short? SteamTimeDifference;
private readonly SemaphoreSlim ConfirmationsSemaphore = new SemaphoreSlim(1);
@@ -270,13 +270,13 @@ namespace ArchiSteamFarm {
}
internal async Task<uint> GetSteamTime() {
if (SteamTimeDifference != 0) {
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference);
if (SteamTimeDifference.HasValue) {
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
}
await TimeSemaphore.WaitAsync().ConfigureAwait(false);
if (SteamTimeDifference == 0) {
if (!SteamTimeDifference.HasValue) {
uint serverTime = Bot.ArchiWebHandler.GetServerTime();
if (serverTime != 0) {
SteamTimeDifference = (short) (serverTime - Utilities.GetUnixTime());
@@ -284,7 +284,7 @@ namespace ArchiSteamFarm {
}
TimeSemaphore.Release();
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference);
return (uint) (Utilities.GetUnixTime() + SteamTimeDifference.GetValueOrDefault());
}
private string GenerateTokenForTime(uint time) {