From 7a97045412b7238ffc77f8375f09a5b200ef7d08 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 13 Mar 2016 20:19:52 +0100 Subject: [PATCH] Add ForceHttp --- ArchiSteamFarm/ArchiWebHandler.cs | 32 +++++++++++++++++++------------ ArchiSteamFarm/GlobalConfig.cs | 3 +++ ArchiSteamFarm/Logging.cs | 10 +++++----- ArchiSteamFarm/Program.cs | 2 +- ArchiSteamFarm/config/ASF.json | 1 + 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 35e696f7e..9c2ea0554 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -34,6 +34,10 @@ using System.Threading.Tasks; namespace ArchiSteamFarm { internal sealed class ArchiWebHandler { + private const string SteamCommunity = "steamcommunity.com"; + + private static string SteamCommunityURL = "https://" + SteamCommunity; + private static int Timeout = 30 * 1000; private readonly Bot Bot; @@ -43,6 +47,7 @@ namespace ArchiSteamFarm { internal static void Init() { Timeout = Program.GlobalConfig.HttpTimeout * 1000; + SteamCommunityURL = (Program.GlobalConfig.ForceHttp ? "http://" : "https://") + SteamCommunity; } internal ArchiWebHandler(Bot bot) { @@ -91,7 +96,7 @@ namespace ArchiSteamFarm { sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), method: WebRequestMethods.Http.Post, - secure: true + secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); @@ -126,7 +131,7 @@ namespace ArchiSteamFarm { HtmlDocument htmlDocument = null; for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) { - htmlDocument = await WebBrowser.UrlGetToHtmlDocument("https://steamcommunity.com/my/profile", Cookie).ConfigureAwait(false); + htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/my/profile", Cookie).ConfigureAwait(false); } if (htmlDocument == null) { @@ -163,7 +168,7 @@ namespace ArchiSteamFarm { response = iEconService.GetTradeOffers( get_received_offers: 1, active_only: 1, - secure: true + secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); @@ -219,7 +224,7 @@ namespace ArchiSteamFarm { return false; } - string request = "https://steamcommunity.com/gid/" + clanID; + string request = SteamCommunityURL + "/gid/" + clanID; Dictionary data = new Dictionary(2) { {"sessionID", sessionID}, @@ -249,7 +254,7 @@ namespace ArchiSteamFarm { return false; } - string referer = "https://steamcommunity.com/tradeoffer/" + tradeID; + string referer = SteamCommunityURL + "/tradeoffer/" + tradeID; string request = referer + "/accept"; Dictionary data = new Dictionary(3) { @@ -285,7 +290,7 @@ namespace ArchiSteamFarm { response = iEconService.DeclineTradeOffer( tradeofferid: tradeID.ToString(), method: WebRequestMethods.Http.Post, - secure: true + secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); @@ -304,7 +309,7 @@ namespace ArchiSteamFarm { internal async Task> GetMyTradableInventory() { JObject jObject = null; for (byte i = 0; i < WebBrowser.MaxRetries && jObject == null; i++) { - jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6?trading=1", Cookie).ConfigureAwait(false); + jObject = await WebBrowser.UrlGetToJObject(SteamCommunityURL + "/my/inventory/json/753/6?trading=1", Cookie).ConfigureAwait(false); } if (jObject == null) { @@ -362,7 +367,7 @@ namespace ArchiSteamFarm { }); } - string referer = "https://steamcommunity.com/tradeoffer/new"; + string referer = SteamCommunityURL + "/tradeoffer/new"; string request = referer + "/send"; foreach (Steam.TradeOfferRequest trade in trades) { @@ -396,7 +401,7 @@ namespace ArchiSteamFarm { HtmlDocument htmlDocument = null; for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) { - htmlDocument = await WebBrowser.UrlGetToHtmlDocument("https://steamcommunity.com/profiles/" + SteamID + "/badges?l=english&p=" + page, Cookie).ConfigureAwait(false); + htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/profiles/" + SteamID + "/badges?l=english&p=" + page, Cookie).ConfigureAwait(false); } if (htmlDocument == null) { @@ -414,7 +419,7 @@ namespace ArchiSteamFarm { HtmlDocument htmlDocument = null; for (byte i = 0; i < WebBrowser.MaxRetries && htmlDocument == null; i++) { - htmlDocument = await WebBrowser.UrlGetToHtmlDocument("https://steamcommunity.com/profiles/" + SteamID + "/gamecards/" + appID + "?l=english", Cookie).ConfigureAwait(false); + htmlDocument = await WebBrowser.UrlGetToHtmlDocument(SteamCommunityURL + "/profiles/" + SteamID + "/gamecards/" + appID + "?l=english", Cookie).ConfigureAwait(false); } if (htmlDocument == null) { @@ -432,7 +437,7 @@ namespace ArchiSteamFarm { HttpResponseMessage response = null; for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) { - response = await WebBrowser.UrlGet("https://steamcommunity.com/profiles/" + SteamID + "/inventory", Cookie).ConfigureAwait(false); + response = await WebBrowser.UrlGet(SteamCommunityURL + "/profiles/" + SteamID + "/inventory", Cookie).ConfigureAwait(false); } if (response == null) { @@ -453,9 +458,12 @@ namespace ArchiSteamFarm { { "pin", parentalPin } }; + string referer = SteamCommunityURL; + string request = referer + "/parental/ajaxunlock"; + HttpResponseMessage response = null; for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) { - response = await WebBrowser.UrlPost("https://steamcommunity.com/parental/ajaxunlock", data, Cookie, "https://steamcommunity.com/").ConfigureAwait(false); + response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false); } if (response == null) { diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 4a5054aa9..c728fbbdc 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -65,6 +65,9 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal byte InventoryLimiterDelay { get; private set; } = 3; + [JsonProperty(Required = Required.DisallowNull)] + internal bool ForceHttp { get; private set; } = false; + [JsonProperty(Required = Required.DisallowNull)] internal byte HttpTimeout { get; private set; } = 60; diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 6ab73c278..1539744a9 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -71,9 +71,8 @@ namespace ArchiSteamFarm { Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message); Log("[!] StackTrace: " + exception.StackTrace); - Exception innerException = exception.InnerException; - if (innerException != null) { - LogGenericException(innerException, botName, previousMethodName); + if (exception.InnerException != null) { + LogGenericException(exception.InnerException, botName, previousMethodName); } } @@ -119,7 +118,9 @@ namespace ArchiSteamFarm { // Write on console only when not awaiting response from user if (!Program.ConsoleIsBusy) { - Console.Write(loggedMessage); + try { + Console.Write(loggedMessage); + } catch { } } if (LogToFile.GetValueOrDefault()) { @@ -129,7 +130,6 @@ namespace ArchiSteamFarm { } catch (Exception e) { LogToFile = false; LogGenericException(e); - LogToFile = true; } } } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 3545eea4a..f090f2502 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -53,7 +53,7 @@ namespace ArchiSteamFarm { Server // Normal + WCF server } - private const string GithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases"; + private const string GithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases"; // GitHub API is HTTPS only internal const string ASF = "ASF"; internal const string ConfigDirectory = "config"; diff --git a/ArchiSteamFarm/config/ASF.json b/ArchiSteamFarm/config/ASF.json index 389ad017b..6b8c9dbb3 100644 --- a/ArchiSteamFarm/config/ASF.json +++ b/ArchiSteamFarm/config/ASF.json @@ -8,6 +8,7 @@ "AccountPlayingDelay": 5, "LoginLimiterDelay": 7, "InventoryLimiterDelay": 3, + "ForceHttp": false, "HttpTimeout": 60, "WCFHostname": "localhost", "WCFPort": 1242,