Skip to content

Commit 18790c5

Browse files
committed
Add SteamParentalPIN
I still can't believe that I actually spent time on doing that
1 parent abcded9 commit 18790c5

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

ArchiSteamFarm/ArchiWebHandler.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ limitations under the License.
2828
using System.Collections.Generic;
2929
using System.Globalization;
3030
using System.Net;
31+
using System.Net.Http;
3132
using System.Text;
3233
using System.Threading.Tasks;
3334

@@ -62,7 +63,7 @@ internal ArchiWebHandler(Bot bot, string apiKey) {
6263
}
6364
}
6465

65-
internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL) {
66+
internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL, string parentalPin) {
6667
if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) {
6768
return;
6869
}
@@ -125,6 +126,30 @@ internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanit
125126
SteamCookieDictionary.Add("steamLoginSecure", steamLoginSecure);
126127
SteamCookieDictionary.Add("birthtime", "-473356799"); // ( ͡° ͜ʖ ͡°)
127128

129+
if (!string.IsNullOrEmpty(parentalPin) && !parentalPin.Equals("0")) {
130+
Logging.LogGenericInfo(Bot.BotName, "Unlocking parental account...");
131+
Dictionary<string, string> postData = new Dictionary<string, string>() {
132+
{"pin", parentalPin}
133+
};
134+
135+
HttpResponseMessage response = await Utilities.UrlPostRequestWithResponse("https://steamcommunity.com/parental/ajaxunlock", postData, SteamCookieDictionary, "https://steamcommunity.com/").ConfigureAwait(false);
136+
if (response != null && response.IsSuccessStatusCode) {
137+
Logging.LogGenericInfo(Bot.BotName, "Success!");
138+
139+
var setCookieValues = response.Headers.GetValues("Set-Cookie");
140+
foreach (string setCookieValue in setCookieValues) {
141+
if (setCookieValue.Contains("steamparental=")) {
142+
string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14);
143+
setCookie = setCookie.Substring(0, setCookie.IndexOf(';'));
144+
SteamCookieDictionary.Add("steamparental", setCookie);
145+
break;
146+
}
147+
}
148+
} else {
149+
Logging.LogGenericInfo(Bot.BotName, "Failed!");
150+
}
151+
}
152+
128153
Bot.Trading.CheckTrades();
129154
}
130155

ArchiSteamFarm/Bot.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ internal class Bot {
6060
private string SteamPassword { get { return Config["SteamPassword"]; } }
6161
private string SteamNickname { get { return Config["SteamNickname"]; } }
6262
private string SteamApiKey { get { return Config["SteamApiKey"]; } }
63+
private string SteamParentalPIN { get { return Config["SteamParentalPIN"]; } }
6364
internal ulong SteamMasterID { get { return ulong.Parse(Config["SteamMasterID"]); } }
6465
private ulong SteamMasterClanID { get { return ulong.Parse(Config["SteamMasterClanID"]); } }
6566
internal HashSet<uint> Blacklist { get; } = new HashSet<uint>();
@@ -186,11 +187,13 @@ private void OnConnected(SteamClient.ConnectedCallback callback) {
186187
string steamLogin = SteamLogin;
187188
if (string.IsNullOrEmpty(steamLogin) || steamLogin.Equals("null")) {
188189
steamLogin = Program.GetUserInput(BotName, Program.EUserInputType.Login);
190+
Config["SteamLogin"] = steamLogin;
189191
}
190192

191193
string steamPassword = SteamPassword;
192194
if (string.IsNullOrEmpty(steamPassword) || steamPassword.Equals("null")) {
193195
steamPassword = Program.GetUserInput(BotName, Program.EUserInputType.Password);
196+
Config["SteamPassword"] = steamPassword;
194197
}
195198

196199
SteamUser.LogOn(new SteamUser.LogOnDetails {
@@ -307,7 +310,13 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
307310
SteamFriends.SetPersonaName(steamNickname);
308311
}
309312

310-
ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL);
313+
string steamParentalPIN = SteamParentalPIN;
314+
if (string.IsNullOrEmpty(steamParentalPIN) || steamParentalPIN.Equals("null")) {
315+
steamParentalPIN = Program.GetUserInput(BotName, Program.EUserInputType.SteamParentalPIN);
316+
Config["SteamParentalPIN"] = steamParentalPIN;
317+
}
318+
319+
await ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL, steamParentalPIN).ConfigureAwait(false);
311320

312321
ulong clanID = SteamMasterClanID;
313322
if (clanID != 0) {

ArchiSteamFarm/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal enum EUserInputType {
3333
Login,
3434
Password,
3535
SteamGuard,
36+
SteamParentalPIN,
3637
TwoFactorAuthentication,
3738
}
3839

@@ -56,7 +57,10 @@ internal static string GetUserInput(string botLogin, EUserInputType userInputTyp
5657
Console.Write("<" + botLogin + "> Please enter your password: ");
5758
break;
5859
case EUserInputType.SteamGuard:
59-
Console.Write("<" + botLogin + "> Please enter the auth code sent to your email : ");
60+
Console.Write("<" + botLogin + "> Please enter the auth code sent to your email: ");
61+
break;
62+
case EUserInputType.SteamParentalPIN:
63+
Console.Write("<" + botLogin + "> Please enter steam parental PIN: ");
6064
break;
6165
case EUserInputType.TwoFactorAuthentication:
6266
Console.Write("<" + botLogin + "> Please enter your 2 factor auth code from your authenticator app: ");

ArchiSteamFarm/Utilities.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,36 @@ internal static async Task<bool> UrlPostRequest(string request, Dictionary<strin
133133
}
134134
return result;
135135
}
136+
137+
internal static async Task<HttpResponseMessage> UrlPostRequestWithResponse(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
138+
HttpResponseMessage result = null;
139+
if (!string.IsNullOrEmpty(request)) {
140+
try {
141+
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
142+
using (HttpClient client = new HttpClient(clientHandler)) {
143+
client.Timeout = TimeSpan.FromSeconds(10);
144+
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, request);
145+
requestMessage.Content = new FormUrlEncodedContent(postData);
146+
if (cookieVariables != null && cookieVariables.Count > 0) {
147+
StringBuilder cookie = new StringBuilder();
148+
foreach (KeyValuePair<string, string> cookieVariable in cookieVariables) {
149+
cookie.Append(cookieVariable.Key + "=" + cookieVariable.Value + ";");
150+
}
151+
requestMessage.Headers.Add("Cookie", cookie.ToString());
152+
}
153+
if (referer != null) {
154+
requestMessage.Headers.Referrer = new Uri(referer);
155+
}
156+
HttpResponseMessage responseMessage = await client.SendAsync(requestMessage).ConfigureAwait(false);
157+
if (responseMessage != null && responseMessage.IsSuccessStatusCode) {
158+
result = responseMessage;
159+
}
160+
}
161+
}
162+
} catch {
163+
}
164+
}
165+
return result;
166+
}
136167
}
137168
}

ArchiSteamFarm/config/example.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
<!-- TIP: You can use "null", but it will disable all API-based functionalities such as trading -->
2424
<SteamApiKey type="string" value="null"/>
2525

26+
<!-- This is your parental PIN if you use steam parental functionality -->
27+
<!-- 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 -->
28+
<SteamParentalPIN type="string" value="0"/>
29+
2630
<!-- This is steamID of the bot-master - you, in steamID64 format -->
2731
<!-- TIP: You can use "0", but bot won't accept steam cd-keys or trades from anybody" -->
2832
<SteamMasterID type="ulong" value="76561198006963719"/>
2933

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

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

3842
</configuration>

0 commit comments

Comments
 (0)