diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 42b76cae0918c..11683ee605ff4 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -28,6 +28,7 @@ limitations under the License. using System.Collections.Generic; using System.Globalization; using System.Net; +using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -62,7 +63,7 @@ internal ArchiWebHandler(Bot bot, string apiKey) { } } - internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL) { + internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL, string parentalPin) { if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) { return; } @@ -125,6 +126,30 @@ internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanit SteamCookieDictionary.Add("steamLoginSecure", steamLoginSecure); SteamCookieDictionary.Add("birthtime", "-473356799"); // ( ͡° ͜ʖ ͡°) + if (!string.IsNullOrEmpty(parentalPin) && !parentalPin.Equals("0")) { + Logging.LogGenericInfo(Bot.BotName, "Unlocking parental account..."); + Dictionary postData = new Dictionary() { + {"pin", parentalPin} + }; + + HttpResponseMessage response = await Utilities.UrlPostRequestWithResponse("https://steamcommunity.com/parental/ajaxunlock", postData, SteamCookieDictionary, "https://steamcommunity.com/").ConfigureAwait(false); + if (response != null && response.IsSuccessStatusCode) { + Logging.LogGenericInfo(Bot.BotName, "Success!"); + + var setCookieValues = response.Headers.GetValues("Set-Cookie"); + foreach (string setCookieValue in setCookieValues) { + if (setCookieValue.Contains("steamparental=")) { + string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14); + setCookie = setCookie.Substring(0, setCookie.IndexOf(';')); + SteamCookieDictionary.Add("steamparental", setCookie); + break; + } + } + } else { + Logging.LogGenericInfo(Bot.BotName, "Failed!"); + } + } + Bot.Trading.CheckTrades(); } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 3c4d7f9e74037..9b338e77c22af 100644 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -60,6 +60,7 @@ internal class Bot { private string SteamPassword { get { return Config["SteamPassword"]; } } private string SteamNickname { get { return Config["SteamNickname"]; } } private string SteamApiKey { get { return Config["SteamApiKey"]; } } + private string SteamParentalPIN { get { return Config["SteamParentalPIN"]; } } internal ulong SteamMasterID { get { return ulong.Parse(Config["SteamMasterID"]); } } private ulong SteamMasterClanID { get { return ulong.Parse(Config["SteamMasterClanID"]); } } internal HashSet Blacklist { get; } = new HashSet(); @@ -186,11 +187,13 @@ private void OnConnected(SteamClient.ConnectedCallback callback) { string steamLogin = SteamLogin; if (string.IsNullOrEmpty(steamLogin) || steamLogin.Equals("null")) { steamLogin = Program.GetUserInput(BotName, Program.EUserInputType.Login); + Config["SteamLogin"] = steamLogin; } string steamPassword = SteamPassword; if (string.IsNullOrEmpty(steamPassword) || steamPassword.Equals("null")) { steamPassword = Program.GetUserInput(BotName, Program.EUserInputType.Password); + Config["SteamPassword"] = steamPassword; } SteamUser.LogOn(new SteamUser.LogOnDetails { @@ -307,7 +310,13 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) { SteamFriends.SetPersonaName(steamNickname); } - ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL); + string steamParentalPIN = SteamParentalPIN; + if (string.IsNullOrEmpty(steamParentalPIN) || steamParentalPIN.Equals("null")) { + steamParentalPIN = Program.GetUserInput(BotName, Program.EUserInputType.SteamParentalPIN); + Config["SteamParentalPIN"] = steamParentalPIN; + } + + await ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL, steamParentalPIN).ConfigureAwait(false); ulong clanID = SteamMasterClanID; if (clanID != 0) { diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index f7d79d447a8f2..eac5df4ccb0d6 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -33,6 +33,7 @@ internal enum EUserInputType { Login, Password, SteamGuard, + SteamParentalPIN, TwoFactorAuthentication, } @@ -56,7 +57,10 @@ internal static string GetUserInput(string botLogin, EUserInputType userInputTyp Console.Write("<" + botLogin + "> Please enter your password: "); break; case EUserInputType.SteamGuard: - Console.Write("<" + botLogin + "> Please enter the auth code sent to your email : "); + Console.Write("<" + botLogin + "> Please enter the auth code sent to your email: "); + break; + case EUserInputType.SteamParentalPIN: + Console.Write("<" + botLogin + "> Please enter steam parental PIN: "); break; case EUserInputType.TwoFactorAuthentication: Console.Write("<" + botLogin + "> Please enter your 2 factor auth code from your authenticator app: "); diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 8f0ed0db010d7..2378eba54e6dd 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -133,5 +133,36 @@ internal static async Task UrlPostRequest(string request, Dictionary UrlPostRequestWithResponse(string request, Dictionary postData, Dictionary cookieVariables = null, string referer = null) { + HttpResponseMessage result = null; + if (!string.IsNullOrEmpty(request)) { + try { + using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) { + using (HttpClient client = new HttpClient(clientHandler)) { + client.Timeout = TimeSpan.FromSeconds(10); + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, request); + requestMessage.Content = new FormUrlEncodedContent(postData); + if (cookieVariables != null && cookieVariables.Count > 0) { + StringBuilder cookie = new StringBuilder(); + foreach (KeyValuePair cookieVariable in cookieVariables) { + cookie.Append(cookieVariable.Key + "=" + cookieVariable.Value + ";"); + } + requestMessage.Headers.Add("Cookie", cookie.ToString()); + } + if (referer != null) { + requestMessage.Headers.Referrer = new Uri(referer); + } + HttpResponseMessage responseMessage = await client.SendAsync(requestMessage).ConfigureAwait(false); + if (responseMessage != null && responseMessage.IsSuccessStatusCode) { + result = responseMessage; + } + } + } + } catch { + } + } + return result; + } } } diff --git a/ArchiSteamFarm/config/example.xml b/ArchiSteamFarm/config/example.xml index f7b51c69a1b1a..600728c30b1ae 100644 --- a/ArchiSteamFarm/config/example.xml +++ b/ArchiSteamFarm/config/example.xml @@ -23,16 +23,20 @@ + + + + - + - + \ No newline at end of file