diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index fc9cb1014..913ba66e4 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -150,6 +150,28 @@ namespace ArchiSteamFarm { } } + internal async Task IsLoggedIn() { + if (SteamID == 0) { + return false; + } + + HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocument("http://steamcommunity.com/my/profile", SteamCookieDictionary).ConfigureAwait(false); + if (htmlDocument == null) { + return null; + } + + HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='account_pulldown']"); + return htmlNode != null; + } + + internal async Task ReconnectIfNeeded() { + bool? isLoggedIn = await IsLoggedIn().ConfigureAwait(false); + if (isLoggedIn.HasValue && !isLoggedIn.Value) { + Logging.LogGenericInfo(Bot.BotName, "Reconnecting because our sessionID expired!"); + Bot.SteamClient.Disconnect(); // Bot will handle reconnect + } + } + internal List GetTradeOffers() { if (ApiKey == null) { return null; diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 7edb23264..00e5ad78e 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -323,15 +323,22 @@ namespace ArchiSteamFarm { } private async Task ShouldFarm(ulong appID) { - bool? result = null; - HtmlDocument gamePageDocument = await Bot.ArchiWebHandler.GetGameCardsPage(appID).ConfigureAwait(false); - if (gamePageDocument != null) { - HtmlNode gamePageNode = gamePageDocument.DocumentNode.SelectSingleNode("//span[@class='progress_info_bold']"); - if (gamePageNode != null) { - result = !gamePageNode.InnerText.Contains("No card drops"); - } + if (appID == 0) { + return false; } - return result; + + HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetGameCardsPage(appID).ConfigureAwait(false); + if (htmlDocument == null) { + return null; + } + + HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//span[@class='progress_info_bold']"); + if (htmlNode == null) { + await Bot.ArchiWebHandler.ReconnectIfNeeded().ConfigureAwait(false); + return null; + } + + return !htmlNode.InnerText.Contains("No card drops"); } private async Task Farm(uint appID) {