Skip to content

Commit

Permalink
Add SteamParentalPIN
Browse files Browse the repository at this point in the history
I still can't believe that I actually spent time on doing that
  • Loading branch information
JustArchi committed Oct 29, 2015
1 parent abcded9 commit 18790c5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
27 changes: 26 additions & 1 deletion ArchiSteamFarm/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<string, string> postData = new Dictionary<string, string>() {
{"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();
}

Expand Down
11 changes: 10 additions & 1 deletion ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint> Blacklist { get; } = new HashSet<uint>();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion ArchiSteamFarm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal enum EUserInputType {
Login,
Password,
SteamGuard,
SteamParentalPIN,
TwoFactorAuthentication,
}

Expand All @@ -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: ");
Expand Down
31 changes: 31 additions & 0 deletions ArchiSteamFarm/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,36 @@ internal static async Task<bool> UrlPostRequest(string request, Dictionary<strin
}
return result;
}

internal static async Task<HttpResponseMessage> UrlPostRequestWithResponse(string request, Dictionary<string, string> postData, Dictionary<string, string> 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<string, string> 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;
}
}
}
8 changes: 6 additions & 2 deletions ArchiSteamFarm/config/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
<!-- TIP: You can use "null", but it will disable all API-based functionalities such as trading -->
<SteamApiKey type="string" value="null"/>

<!-- This is your parental PIN if you use steam parental functionality -->
<!-- TIP: Most likely you don't want to change it. You can use "null" if you wish to enter PIN on every startup, 0 means there is no PIN -->
<SteamParentalPIN type="string" value="0"/>

<!-- This is steamID of the bot-master - you, in steamID64 format -->
<!-- TIP: You can use "0", but bot won't accept steam cd-keys or trades from anybody" -->
<SteamMasterID type="ulong" value="76561198006963719"/>

<!-- This defines clan of the master, bot will join chatroom of that clan automatically after logging in -->
<!-- TIP: You most likely don't want to change it -->
<!-- TIP: Most likely you don't want to change it -->
<SteamMasterClanID type="ulong" value="0"/>

<!-- Comma-separated list of IDs that should not be considered for farming -->
<!-- TIP: You most likely don't want to change it -->
<!-- TIP: Most likely you don't want to change it -->
<Blacklist type="HashSet(uint)" value="368020"/>

</configuration>

0 comments on commit 18790c5

Please sign in to comment.