Skip to content

Commit

Permalink
Handle expired sessionIDs for main accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 16, 2015
1 parent 5e22c83 commit 98e1d51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
22 changes: 22 additions & 0 deletions ArchiSteamFarm/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string
}
}

internal async Task<bool?> 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<SteamTradeOffer> GetTradeOffers() {
if (ApiKey == null) {
return null;
Expand Down
23 changes: 15 additions & 8 deletions ArchiSteamFarm/CardsFarmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,22 @@ private async Task CheckGamesForFarming() {
}

private async Task<bool?> 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<bool> Farm(uint appID) {
Expand Down

0 comments on commit 98e1d51

Please sign in to comment.