mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-17 06:50:29 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0ba148005 | ||
|
|
abe3beaee7 | ||
|
|
7c9e5d818e | ||
|
|
571b0dc936 | ||
|
|
0a13d341b7 | ||
|
|
18790c57a1 | ||
|
|
abcded9287 |
@@ -56,6 +56,10 @@
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.8.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
||||
@@ -28,6 +28,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -57,12 +58,10 @@ namespace ArchiSteamFarm {
|
||||
|
||||
if (!string.IsNullOrEmpty(apiKey) && !apiKey.Equals("null")) {
|
||||
ApiKey = apiKey;
|
||||
} else {
|
||||
ApiKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
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 +124,30 @@ namespace ArchiSteamFarm {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -200,6 +223,45 @@ namespace ArchiSteamFarm {
|
||||
return result;
|
||||
}
|
||||
|
||||
internal async Task JoinClan(ulong clanID) {
|
||||
if (clanID == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
string sessionID;
|
||||
if (!SteamCookieDictionary.TryGetValue("sessionid", out sessionID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
string request = "http://steamcommunity.com/gid/" + clanID;
|
||||
|
||||
Dictionary<string, string> postData = new Dictionary<string, string>() {
|
||||
{"sessionID", sessionID},
|
||||
{"action", "join"}
|
||||
};
|
||||
|
||||
await Utilities.UrlPostRequest(request, postData, SteamCookieDictionary).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task LeaveClan(ulong clanID) {
|
||||
if (clanID == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
string sessionID;
|
||||
if (!SteamCookieDictionary.TryGetValue("sessionid", out sessionID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
string request = GetHomeProcess();
|
||||
Dictionary<string, string> postData = new Dictionary<string, string>() {
|
||||
{"sessionID", sessionID},
|
||||
{"action", "leaveGroup"},
|
||||
{"groupId", clanID.ToString()}
|
||||
};
|
||||
await Utilities.UrlPostRequest(request, postData, SteamCookieDictionary).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task<bool> AcceptTradeOffer(ulong tradeID) {
|
||||
if (tradeID == 0) {
|
||||
return false;
|
||||
@@ -219,7 +281,21 @@ namespace ArchiSteamFarm {
|
||||
{"tradeofferid", tradeID.ToString()}
|
||||
};
|
||||
|
||||
return await Utilities.UrlPostRequest(request, postData, SteamCookieDictionary, referer).ConfigureAwait(false);
|
||||
HttpResponseMessage result = await Utilities.UrlPostRequestWithResponse(request, postData, SteamCookieDictionary, referer).ConfigureAwait(false);
|
||||
bool success = result.IsSuccessStatusCode;
|
||||
|
||||
if (!success) {
|
||||
Logging.LogGenericWarning(Bot.BotName, "Request failed, reason: " + result.ReasonPhrase);
|
||||
switch (result.StatusCode) {
|
||||
case HttpStatusCode.InternalServerError:
|
||||
Logging.LogGenericWarning(Bot.BotName, "That might be caused by 7-days trade lock from new device");
|
||||
Logging.LogGenericWarning(Bot.BotName, "Try again in 7 days, declining that offer for now");
|
||||
DeclineTradeOffer(tradeID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
internal bool DeclineTradeOffer(ulong tradeID) {
|
||||
@@ -252,26 +328,6 @@ namespace ArchiSteamFarm {
|
||||
return response != null; // Steam API doesn't respond with any error code, assume any response is a success
|
||||
}
|
||||
|
||||
internal async Task LeaveClan(ulong clanID) {
|
||||
if (clanID == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
string sessionID;
|
||||
if (!SteamCookieDictionary.TryGetValue("sessionid", out sessionID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
string request = GetHomeProcess();
|
||||
Dictionary<string, string> postData = new Dictionary<string, string>() {
|
||||
{"sessionID", sessionID},
|
||||
{"action", "leaveGroup"},
|
||||
{"groupId", clanID.ToString()}
|
||||
};
|
||||
|
||||
await Utilities.UrlPostRequest(request, postData, SteamCookieDictionary).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task<HtmlDocument> GetBadgePage(int page) {
|
||||
if (SteamID == 0 || page == 0) {
|
||||
return null;
|
||||
|
||||
@@ -55,14 +55,16 @@ namespace ArchiSteamFarm {
|
||||
internal Trading Trading { get; private set; }
|
||||
|
||||
// Config variables
|
||||
private bool Enabled { get { return bool.Parse(Config["Enabled"]); } }
|
||||
internal bool Enabled { get { return bool.Parse(Config["Enabled"]); } }
|
||||
private string SteamLogin { get { return Config["SteamLogin"]; } }
|
||||
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>();
|
||||
internal bool Statistics { get { return bool.Parse(Config["Statistics"]); } }
|
||||
|
||||
internal Bot(string botName) {
|
||||
BotName = botName;
|
||||
@@ -127,6 +129,7 @@ namespace ArchiSteamFarm {
|
||||
SteamFriends = SteamClient.GetHandler<SteamFriends>();
|
||||
CallbackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList);
|
||||
CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg);
|
||||
CallbackManager.Subscribe<SteamFriends.PersonaStateCallback>(OnPersonaState);
|
||||
|
||||
SteamUser = SteamClient.GetHandler<SteamUser>();
|
||||
CallbackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
|
||||
@@ -183,9 +186,21 @@ namespace ArchiSteamFarm {
|
||||
sentryHash = CryptoHelper.SHAHash(sentryFileContent);
|
||||
}
|
||||
|
||||
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 {
|
||||
Username = SteamLogin,
|
||||
Password = SteamPassword,
|
||||
Username = steamLogin,
|
||||
Password = steamPassword,
|
||||
AuthCode = AuthCode,
|
||||
TwoFactorCode = TwoFactorAuth,
|
||||
SentryFileHash = sentryHash
|
||||
@@ -256,6 +271,18 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPersonaState(SteamFriends.PersonaStateCallback callback) {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamID steamID = callback.FriendID;
|
||||
SteamID sourceSteamID = callback.SourceSteamID;
|
||||
string steamNickname = callback.Name;
|
||||
EPersonaState personaState = callback.State;
|
||||
EClanRank clanRank = (EClanRank) callback.ClanRank;
|
||||
}
|
||||
|
||||
private void OnAccountInfo(SteamUser.AccountInfoCallback callback) {
|
||||
if (callback == null) {
|
||||
return;
|
||||
@@ -284,10 +311,10 @@ namespace ArchiSteamFarm {
|
||||
EResult result = callback.Result;
|
||||
switch (result) {
|
||||
case EResult.AccountLogonDenied:
|
||||
AuthCode = Program.GetSteamGuardCode(SteamLogin, false);
|
||||
AuthCode = Program.GetUserInput(SteamLogin, Program.EUserInputType.SteamGuard);
|
||||
break;
|
||||
case EResult.AccountLoginDeniedNeedTwoFactor:
|
||||
TwoFactorAuth = Program.GetSteamGuardCode(SteamLogin, true);
|
||||
TwoFactorAuth = Program.GetUserInput(SteamLogin, Program.EUserInputType.TwoFactorAuthentication);
|
||||
break;
|
||||
case EResult.OK:
|
||||
Logging.LogGenericInfo(BotName, "Successfully logged on!");
|
||||
@@ -297,13 +324,24 @@ namespace ArchiSteamFarm {
|
||||
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) {
|
||||
SteamFriends.JoinChat(clanID);
|
||||
}
|
||||
|
||||
if (Statistics) {
|
||||
SteamFriends.JoinChat(Program.ArchiSCFarmGroup);
|
||||
await ArchiWebHandler.JoinClan(Program.ArchiSCFarmGroup).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await CardsFarmer.StartFarming().ConfigureAwait(false);
|
||||
break;
|
||||
case EResult.Timeout:
|
||||
|
||||
@@ -50,6 +50,10 @@ namespace ArchiSteamFarm {
|
||||
Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message);
|
||||
}
|
||||
|
||||
internal static void LogGenericNotice(string botName, string message, [CallerMemberName] string previousMethodName = "") {
|
||||
Log("[*] NOTICE: " + previousMethodName + "() <" + botName + "> " + message);
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
internal static void LogGenericDebug(string botName, string message, [CallerMemberName] string previousMethodName = "") {
|
||||
Log("[#] DEBUG: " + previousMethodName + "() <" + botName + "> " + message);
|
||||
|
||||
@@ -22,31 +22,81 @@
|
||||
|
||||
*/
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class Program {
|
||||
internal enum EUserInputType {
|
||||
Login,
|
||||
Password,
|
||||
SteamGuard,
|
||||
SteamParentalPIN,
|
||||
TwoFactorAuthentication,
|
||||
}
|
||||
|
||||
internal const ulong ArchiSCFarmGroup = 103582791440160998;
|
||||
internal const string ConfigDirectoryPath = "config";
|
||||
private const string LatestGithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases/latest";
|
||||
|
||||
private static readonly HashSet<Bot> Bots = new HashSet<Bot>();
|
||||
internal static readonly object ConsoleLock = new object();
|
||||
internal static string Version { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } }
|
||||
|
||||
private static async Task CheckForUpdate() {
|
||||
JObject response = await Utilities.UrlToJObject(LatestGithubReleaseURL).ConfigureAwait(false);
|
||||
if (response == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
string remoteVersion = response["tag_name"].ToString();
|
||||
if (string.IsNullOrEmpty(remoteVersion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
string localVersion = Version;
|
||||
|
||||
if (localVersion.CompareTo(remoteVersion) < 0) {
|
||||
Logging.LogGenericNotice("", "New version is available!");
|
||||
Logging.LogGenericNotice("", "Local version: " + localVersion);
|
||||
Logging.LogGenericNotice("", "Remote version: " + remoteVersion);
|
||||
Logging.LogGenericNotice("", "Consider updating yourself!");
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Exit(int exitCode = 0) {
|
||||
ShutdownAllBots();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
|
||||
internal static string GetSteamGuardCode(string botLogin, bool twoFactorAuthentication) {
|
||||
internal static string GetUserInput(string botLogin, EUserInputType userInputType) {
|
||||
string result;
|
||||
lock (ConsoleLock) {
|
||||
if (twoFactorAuthentication) {
|
||||
Console.Write("<" + botLogin + "> Please enter your 2 factor auth code from your authenticator app: ");
|
||||
} else {
|
||||
Console.Write("<" + botLogin + "> Please enter the auth code sent to your email : ");
|
||||
switch (userInputType) {
|
||||
case EUserInputType.Login:
|
||||
Console.Write("<" + botLogin + "> Please enter your login: ");
|
||||
break;
|
||||
case EUserInputType.Password:
|
||||
Console.Write("<" + botLogin + "> Please enter your password: ");
|
||||
break;
|
||||
case EUserInputType.SteamGuard:
|
||||
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: ");
|
||||
break;
|
||||
}
|
||||
result = Console.ReadLine();
|
||||
Console.Clear(); // For security purposes
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -61,6 +111,10 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
private static void Main(string[] args) {
|
||||
Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version);
|
||||
|
||||
Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait();
|
||||
|
||||
// Config directory may not be in the same directory as the .exe, check maximum of 3 levels lower
|
||||
for (var i = 0; i < 4 && !Directory.Exists(ConfigDirectoryPath); i++) {
|
||||
Directory.SetCurrentDirectory("..");
|
||||
@@ -75,7 +129,11 @@ namespace ArchiSteamFarm {
|
||||
lock (Bots) {
|
||||
foreach (var configFile in Directory.EnumerateFiles(ConfigDirectoryPath, "*.xml")) {
|
||||
string botName = Path.GetFileNameWithoutExtension(configFile);
|
||||
Bots.Add(new Bot(botName));
|
||||
Bot bot = new Bot(botName);
|
||||
Bots.Add(bot);
|
||||
if (!bot.Enabled) {
|
||||
Logging.LogGenericInfo(botName, "Not starting this instance because it's disabled in config file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("0.4.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.0.0")]
|
||||
|
||||
@@ -86,10 +86,6 @@ namespace ArchiSteamFarm {
|
||||
success = Bot.ArchiWebHandler.DeclineTradeOffer(tradeID);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
Logging.LogGenericWarning(Bot.BotName, "Response <accept: " + tradeAccepted + "> to trade " + tradeID + " failed!");
|
||||
}
|
||||
|
||||
if (tradeAccepted && success) {
|
||||
// Do whatever we want with success
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
using HtmlAgilityPack;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -48,35 +49,40 @@ namespace ArchiSteamFarm {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ulong result = ulong.Parse(resultString, CultureInfo.InvariantCulture);
|
||||
return result;
|
||||
return ulong.Parse(resultString, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
internal static async Task<HttpResponseMessage> UrlToHttpResponse(string websiteAddress, Dictionary<string, string> cookieVariables = null) {
|
||||
if (string.IsNullOrEmpty(websiteAddress)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpResponseMessage result = null;
|
||||
if (!string.IsNullOrEmpty(websiteAddress)) {
|
||||
try {
|
||||
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
|
||||
using (HttpClient client = new HttpClient(clientHandler)) {
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, websiteAddress);
|
||||
if (cookieVariables != null) {
|
||||
StringBuilder cookie = new StringBuilder();
|
||||
foreach (KeyValuePair<string, string> cookieVariable in cookieVariables) {
|
||||
cookie.Append(cookieVariable.Key + "=" + cookieVariable.Value + ";");
|
||||
}
|
||||
requestMessage.Headers.Add("Cookie", cookie.ToString());
|
||||
}
|
||||
HttpResponseMessage responseMessage = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if (responseMessage != null) {
|
||||
responseMessage.EnsureSuccessStatusCode();
|
||||
result = responseMessage;
|
||||
|
||||
try {
|
||||
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
|
||||
using (HttpClient client = new HttpClient(clientHandler)) {
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("ArchiSteamFarm/1.0");
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, websiteAddress);
|
||||
if (cookieVariables != null) {
|
||||
StringBuilder cookie = new StringBuilder();
|
||||
foreach (KeyValuePair<string, string> cookieVariable in cookieVariables) {
|
||||
cookie.Append(cookieVariable.Key + "=" + cookieVariable.Value + ";");
|
||||
}
|
||||
requestMessage.Headers.Add("Cookie", cookie.ToString());
|
||||
}
|
||||
HttpResponseMessage responseMessage = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if (responseMessage != null) {
|
||||
responseMessage.EnsureSuccessStatusCode();
|
||||
result = responseMessage;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logging.LogGenericException("Utilities", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -85,52 +91,124 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal static async Task<HtmlDocument> UrlToHtmlDocument(string websiteAddress, Dictionary<string, string> cookieVariables = null) {
|
||||
HtmlDocument result = null;
|
||||
if (!string.IsNullOrEmpty(websiteAddress)) {
|
||||
try {
|
||||
HttpResponseMessage responseMessage = await UrlToHttpResponse(websiteAddress, cookieVariables).ConfigureAwait(false);
|
||||
if (responseMessage != null) {
|
||||
string source = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
if (!string.IsNullOrEmpty(source)) {
|
||||
source = WebUtility.HtmlDecode(source);
|
||||
result = new HtmlDocument();
|
||||
result.LoadHtml(source);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
if (string.IsNullOrEmpty(websiteAddress)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HtmlDocument result = null;
|
||||
|
||||
try {
|
||||
HttpResponseMessage responseMessage = await UrlToHttpResponse(websiteAddress, cookieVariables).ConfigureAwait(false);
|
||||
if (responseMessage != null) {
|
||||
string source = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
if (!string.IsNullOrEmpty(source)) {
|
||||
source = WebUtility.HtmlDecode(source);
|
||||
result = new HtmlDocument();
|
||||
result.LoadHtml(source);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logging.LogGenericException("Utilities", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static async Task<bool> UrlPostRequest(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request) || postData == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (!string.IsNullOrEmpty(request)) {
|
||||
try {
|
||||
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
|
||||
using (HttpClient client = new HttpClient(clientHandler)) {
|
||||
client.Timeout = TimeSpan.FromSeconds(15);
|
||||
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) {
|
||||
result = responseMessage.IsSuccessStatusCode;
|
||||
|
||||
try {
|
||||
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
|
||||
using (HttpClient client = new HttpClient(clientHandler)) {
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("ArchiSteamFarm/1.0");
|
||||
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) {
|
||||
result = responseMessage.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logging.LogGenericException("Utilities", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static async Task<HttpResponseMessage> UrlPostRequestWithResponse(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request) || postData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpResponseMessage result = null;
|
||||
|
||||
try {
|
||||
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
|
||||
using (HttpClient client = new HttpClient(clientHandler)) {
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("ArchiSteamFarm/1.0");
|
||||
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) {
|
||||
result = responseMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logging.LogGenericException("Utilities", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static async Task<JObject> UrlToJObject(string request) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpResponseMessage httpResponseMessage = await UrlToHttpResponse(request, null).ConfigureAwait(false);
|
||||
if (httpResponseMessage == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
string source = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
if (string.IsNullOrEmpty(source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JObject result = null;
|
||||
try {
|
||||
result = JObject.Parse(source);
|
||||
} catch {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,27 +4,44 @@
|
||||
<!-- Every bot should have it's own unique .xml configuration file, this is example on which you can base on -->
|
||||
|
||||
<!-- Master switch to turn account on and off, set to "true" after you're done -->
|
||||
<!-- TIP: This bot instance won't run unless below switch is set to "true" -->
|
||||
<Enabled type="bool" value="false"/>
|
||||
|
||||
<!-- This is your steam login, the one you use for logging in to steam -->
|
||||
<!-- TIP: You can use "null" if you wish to enter login on every startup -->
|
||||
<SteamLogin type="string" value="Foo"/>
|
||||
|
||||
<!-- This is your steam password, the one you use for logging in to steam -->
|
||||
<!-- TIP: You can use "null" if you wish to enter password on every startup -->
|
||||
<SteamPassword type="string" value="Bar"/>
|
||||
|
||||
<!-- This is steam nickname, the one you want to use for bot. Can be anything up to 32 characters -->
|
||||
<!-- TIP: You can use "null" if you wish to preserve your actual nickname -->
|
||||
<SteamNickname type="string" value="null"/>
|
||||
|
||||
<!-- Get one at https://steamcommunity.com/dev/apikey while logged in as bot, domain doesn't matter. You can also use "null", but that will disable many API functions, e.g. trading -->
|
||||
<!-- This is your bot's API key, get one at https://steamcommunity.com/dev/apikey while logged in as bot, domain doesn't matter -->
|
||||
<!-- 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"/>
|
||||
|
||||
<!-- If you want from the bot to join particular chat of given clan, set it here, otherwise leave at 0 -->
|
||||
<!-- This defines clan of the master, bot will join chatroom of that clan automatically after logging in -->
|
||||
<!-- 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: Most likely you don't want to change it -->
|
||||
<Blacklist type="HashSet(uint)" value="368020"/>
|
||||
|
||||
<!-- This enables statistics for me - bot will join Archi's SC Farm group and chat -->
|
||||
<!-- Consider leaving it at "true", this way I can check how many running bots are active -->
|
||||
<!-- TIP: Group link is http://steamcommunity.com/groups/ascfarm -->
|
||||
<Statistics type="bool" value="true"/>
|
||||
|
||||
</configuration>
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net45" />
|
||||
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
|
||||
<package id="SteamKit2" version="1.6.5" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="8.0.1-beta1" targetFramework="net45" />
|
||||
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
|
||||
<package id="SteamKit2" version="1.6.5" targetFramework="net45" />
|
||||
</packages>
|
||||
Binary file not shown.
Binary file not shown.
9598
packages/Newtonsoft.Json.8.0.1-beta1/lib/net20/Newtonsoft.Json.xml
Normal file
9598
packages/Newtonsoft.Json.8.0.1-beta1/lib/net20/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
8741
packages/Newtonsoft.Json.8.0.1-beta1/lib/net35/Newtonsoft.Json.xml
Normal file
8741
packages/Newtonsoft.Json.8.0.1-beta1/lib/net35/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
9048
packages/Newtonsoft.Json.8.0.1-beta1/lib/net40/Newtonsoft.Json.xml
Normal file
9048
packages/Newtonsoft.Json.8.0.1-beta1/lib/net40/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
9048
packages/Newtonsoft.Json.8.0.1-beta1/lib/net45/Newtonsoft.Json.xml
Normal file
9048
packages/Newtonsoft.Json.8.0.1-beta1/lib/net45/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
116
packages/Newtonsoft.Json.8.0.1-beta1/tools/install.ps1
Normal file
116
packages/Newtonsoft.Json.8.0.1-beta1/tools/install.ps1
Normal file
@@ -0,0 +1,116 @@
|
||||
param($installPath, $toolsPath, $package, $project)
|
||||
|
||||
# open json.net splash page on package install
|
||||
# don't open if json.net is installed as a dependency
|
||||
|
||||
try
|
||||
{
|
||||
$url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
|
||||
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
|
||||
|
||||
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
|
||||
{
|
||||
# user is installing from VS NuGet console
|
||||
# get reference to the window, the console host and the input history
|
||||
# show webpage if "install-package newtonsoft.json" was last input
|
||||
|
||||
$consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
|
||||
|
||||
$props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
$prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
|
||||
if ($prop -eq $null) { return }
|
||||
|
||||
$hostInfo = $prop.GetValue($consoleWindow)
|
||||
if ($hostInfo -eq $null) { return }
|
||||
|
||||
$history = $hostInfo.WpfConsole.InputHistory.History
|
||||
|
||||
$lastCommand = $history | select -last 1
|
||||
|
||||
if ($lastCommand)
|
||||
{
|
||||
$lastCommand = $lastCommand.Trim().ToLower()
|
||||
if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# user is installing from VS NuGet dialog
|
||||
# get reference to the window, then smart output console provider
|
||||
# show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
|
||||
|
||||
$instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
$consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
if ($instanceField -eq $null -or $consoleField -eq $null) { return }
|
||||
|
||||
$instance = $instanceField.GetValue($null)
|
||||
|
||||
if ($instance -eq $null) { return }
|
||||
|
||||
$consoleProvider = $consoleField.GetValue($instance)
|
||||
if ($consoleProvider -eq $null) { return }
|
||||
|
||||
$console = $consoleProvider.CreateOutputConsole($false)
|
||||
|
||||
$messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
if ($messagesField -eq $null) { return }
|
||||
|
||||
$messages = $messagesField.GetValue($console)
|
||||
if ($messages -eq $null) { return }
|
||||
|
||||
$operations = $messages -split "=============================="
|
||||
|
||||
$lastOperation = $operations | select -last 1
|
||||
|
||||
if ($lastOperation)
|
||||
{
|
||||
$lastOperation = $lastOperation.ToLower()
|
||||
|
||||
$lines = $lastOperation -split "`r`n"
|
||||
|
||||
$installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
|
||||
|
||||
if ($installMatch)
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
$pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
|
||||
|
||||
$selection = $pmPane.TextDocument.Selection
|
||||
$selection.StartOfDocument($false)
|
||||
$selection.EndOfDocument($true)
|
||||
|
||||
if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
|
||||
{
|
||||
# don't show on upgrade
|
||||
if (!$selection.Text.Contains("Removed package"))
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
# stop potential errors from bubbling up
|
||||
# worst case the splash page won't open
|
||||
}
|
||||
}
|
||||
|
||||
# still yolo
|
||||
Reference in New Issue
Block a user