diff --git a/BotLooter/Steam/SteamUserSession.cs b/BotLooter/Steam/SteamUserSession.cs index 3c28c85..2e192cd 100644 --- a/BotLooter/Steam/SteamUserSession.cs +++ b/BotLooter/Steam/SteamUserSession.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Text.RegularExpressions; using BotLooter.Resources; using Polly; using Polly.Retry; @@ -54,11 +55,25 @@ private async ValueTask IsSessionAlive() return false; } - var request = new RestRequest("https://store.steampowered.com/account", Method.Head); + var request = new RestRequest("https://steamcommunity.com/my", Method.Get); + request.AddOrUpdateHeader("Sec-Fetch-Dest", "document"); + request.AddOrUpdateHeader("Sec-Fetch-Mode", "navigate"); + request.AddOrUpdateHeader("Sec-Fetch-Site", "none"); + var response = await WebRequest(request); - return response.ResponseUri is not null && !response.ResponseUri.AbsolutePath.StartsWith("/login"); + if (response.StatusCode == HttpStatusCode.Found) // 302 redirect + { + var location = response.Headers?.FirstOrDefault(h => h.Name?.Equals("Location", StringComparison.OrdinalIgnoreCase) == true)?.Value?.ToString(); + + if (location is not null) + { + return Regex.IsMatch(location, @"steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?"); + } + } + + return false; } private async Task<(bool Success, string Message)> TryLogin()