From 7bab5a73a31790a183597aa543871d4c28b2bd1b Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 10 Nov 2018 07:23:04 +0100 Subject: [PATCH] Further session improvements --- ArchiSteamFarm/ArchiWebHandler.cs | 38 +++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index b9f5d6e69..28a6a2635 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1542,11 +1542,13 @@ namespace ArchiSteamFarm { return LastSessionCheck != LastSessionRefresh; } + const string host = SteamCommunityURL; + // It would make sense to use /my/profile here, but it dismisses notifications related to profile comments // So instead, we'll use some less invasive /my link that ensures the session validation, doesn't cause issues and is fast enough - const string request = SteamCommunityURL + "/my/edit/settings"; + const string request = "/my/edit/settings"; - WebBrowser.BasicResponse response = await WebBrowser.UrlHead(request).ConfigureAwait(false); + WebBrowser.BasicResponse response = await WebLimitRequest(host, async () => await WebBrowser.UrlHead(host + request).ConfigureAwait(false)).ConfigureAwait(false); if (response?.FinalUri == null) { return null; } @@ -1739,6 +1741,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlGetToHtmlDocumentWithSession(host, request, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -1802,6 +1808,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlGetToJsonObjectWithSession(host, request, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -1865,6 +1875,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlGetToXmlDocumentWithSession(host, request, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -1928,6 +1942,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlHeadWithSession(host, request, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return false; } } else { // If session refresh is already in progress, just wait for it @@ -1991,6 +2009,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlPostToHtmlDocumentWithSession(host, request, data, referer, session, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -2083,6 +2105,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlPostToJsonObjectWithSession(host, request, data, referer, session, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -2175,6 +2201,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlPostToJsonObjectWithSession(host, request, data, referer, session, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return null; } } else { // If session refresh is already in progress, just wait for it @@ -2270,6 +2300,10 @@ namespace ArchiSteamFarm { if (await RefreshSession().ConfigureAwait(false)) { return await UrlPostWithSession(host, request, data, referer, session, true, --maxTries).ConfigureAwait(false); } + + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request)); + return false; } } else { // If session refresh is already in progress, just wait for it