Skip to content

Commit

Permalink
Allow AWH to forcefully refresh session
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Oct 19, 2023
1 parent 374dede commit cdce466
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,14 +1526,14 @@ internal async Task OnFarmingStopped() {
await PluginsCore.OnBotFarmingStopped(this).ConfigureAwait(false);
}

internal async Task<bool> RefreshWebSession() {
internal async Task<bool> RefreshWebSession(bool force = false) {
if (!IsConnectedAndLoggedOn) {
return false;
}

DateTime now = DateTime.UtcNow;

if (!string.IsNullOrEmpty(AccessToken) && AccessTokenValidUntil.HasValue && (AccessTokenValidUntil.Value > now.AddMinutes(5))) {
if (!force && !string.IsNullOrEmpty(AccessToken) && AccessTokenValidUntil.HasValue && (AccessTokenValidUntil.Value > now.AddMinutes(5))) {
// We can use the tokens we already have
if (await ArchiWebHandler.Init(SteamID, SteamClient.Universe, AccessToken!, SteamParentalActive ? BotConfig.SteamParentalCode : null).ConfigureAwait(false)) {
InitRefreshTokensTimer(AccessTokenValidUntil.Value);
Expand Down Expand Up @@ -1564,7 +1564,7 @@ internal async Task<bool> RefreshWebSession() {
}

// TODO: Handle update of refresh token with next SK2 release
UpdateTokens(response.access_token, RefreshToken);
UpdateTokens(response.access_token, RefreshToken!);

if (await ArchiWebHandler.Init(SteamID, SteamClient.Universe, response.access_token, SteamParentalActive ? BotConfig.SteamParentalCode : null).ConfigureAwait(false)) {
InitRefreshTokensTimer(AccessTokenValidUntil ?? now.AddDays(1));
Expand Down
2 changes: 1 addition & 1 deletion ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ private async Task<bool> RefreshSession() {
}

Bot.ArchiLogger.LogGenericInfo(Strings.RefreshingOurSession);
bool result = await Bot.RefreshWebSession().ConfigureAwait(false);
bool result = await Bot.RefreshWebSession(true).ConfigureAwait(false);

DateTime now = DateTime.UtcNow;

Expand Down

0 comments on commit cdce466

Please sign in to comment.