Compare commits

...

18 Commits
0.2 ... 0.5.0.0

Author SHA1 Message Date
JustArchi
137e8d1f63 Add icon 2015-10-31 07:32:08 +01:00
JustArchi
fed3ac3404 Merge assemblies together to single .exe 2015-10-31 06:59:55 +01:00
JustArchi
3ba90e5d6d Misc 2015-10-31 06:09:22 +01:00
JustArchi
71227168cf Many internal async improvements 2015-10-31 05:27:30 +01:00
JustArchi
2545e7bbf3 Make OtherSteamID64 less costly 2015-10-31 03:50:08 +01:00
JustArchi
411f796fab Many improvements
Most notable:
- Support for older configs, with auto-selecting defaults for missing ones
- Auto exit when all bots are done
2015-10-31 03:27:58 +01:00
JustArchi
fa6dbed593 Add missing enum, thanks to Nephrite 2015-10-29 19:18:49 +01:00
JustArchi
a0ba148005 Implement update check on startup 2015-10-29 17:36:16 +01:00
JustArchi
abe3beaee7 Volvo and it's 7-days locks 2015-10-29 17:06:02 +01:00
JustArchi
7c9e5d818e Add very basic statistics 2015-10-29 16:38:16 +01:00
JustArchi
571b0dc936 Misc 2015-10-29 11:14:08 +01:00
JustArchi
0a13d341b7 Code review 2015-10-29 11:09:22 +01:00
JustArchi
18790c57a1 Add SteamParentalPIN
I still can't believe that I actually spent time on doing that
2015-10-29 01:01:31 +01:00
JustArchi
abcded9287 Make it possible to enter login/password on each startup 2015-10-28 23:29:50 +01:00
JustArchi
a17682e4e2 Fix derp 2015-10-28 22:53:47 +01:00
JustArchi
cd0d0a94a1 Add support for blacklist feature, fix SMG 2015-10-28 22:34:53 +01:00
JustArchi
639067d04f More bugs slained 2015-10-28 21:47:31 +01:00
JustArchi
03885babf6 Fix wrong status after reedeming the key 2015-10-28 20:48:22 +01:00
30 changed files with 54018 additions and 218 deletions

View File

@@ -30,11 +30,12 @@ namespace ArchiSteamFarm {
internal sealed class PurchaseResponseCallback : CallbackMsg {
internal enum EPurchaseResult {
Unknown = 0,
OK = 1,
Unknown = -1,
OK = 0,
AlreadyOwned = 9,
InvalidKey = 14,
DuplicatedKey = 15,
BaseGameRequired = 24,
OnCooldown = 53
}

View File

@@ -11,6 +11,7 @@
<AssemblyName>ArchiSteamFarm</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -23,7 +24,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@@ -39,7 +39,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>
@@ -47,12 +47,22 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>cirno.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<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>
@@ -76,6 +86,7 @@
<Compile Include="Bot.cs" />
<Compile Include="CardsFarmer.cs" />
<Compile Include="CMsgClientClanInviteAction.cs" />
<Compile Include="Debugging.cs" />
<Compile Include="Logging.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -100,7 +111,24 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="cirno.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent Condition=" '$(OS)' != 'Unix' ">(robocopy $(ProjectDir)config $(TargetDir)config /S /E) ^&amp; IF %25ERRORLEVEL%25 GEQ 2 exit 0
if $(ConfigurationName) == Release (
mkdir "$(TargetDir)out" "$(TargetDir)out\config"
copy "$(TargetDir)config\example.xml" "$(TargetDir)out\config"
"$(SolutionDir)tools\ILMerge.exe" /out:"$(TargetDir)out\ASF.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards
del "$(TargetDir)out\ASF.pdb"
)</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -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;
@@ -47,8 +48,9 @@ namespace ArchiSteamFarm {
return "http://steamcommunity.com/id/" + VanityURL + "/home_process";
} else if (SteamID != 0) {
return "http://steamcommunity.com/profiles/" + SteamID + "/home_process";
} else {
return null;
}
return null;
}
internal ArchiWebHandler(Bot bot, string apiKey) {
@@ -56,13 +58,11 @@ namespace ArchiSteamFarm {
if (!string.IsNullOrEmpty(apiKey) && !apiKey.Equals("null")) {
ApiKey = apiKey;
} else {
ApiKey = null;
}
}
internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL) {
if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(vanityURL)) {
internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL, string parentalPin) {
if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) {
return;
}
@@ -124,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();
}
@@ -195,9 +219,49 @@ namespace ArchiSteamFarm {
}
result.Add(tradeOffer);
}
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;
@@ -217,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) {
@@ -250,39 +328,20 @@ 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) {
HtmlDocument result = null;
if (SteamID != 0 && page != 0) {
result = await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/badges?p=" + page, SteamCookieDictionary).ConfigureAwait(false);
if (SteamID == 0 || page == 0) {
return null;
}
return result;
return await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/badges?p=" + page, SteamCookieDictionary).ConfigureAwait(false);
}
internal async Task<HtmlDocument> GetGameCardsPage(ulong appID) {
HtmlDocument result = null;
if (SteamID != 0 && appID != 0) {
result = await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/gamecards/" + appID, SteamCookieDictionary).ConfigureAwait(false);
if (SteamID == 0 || appID == 0) {
return null;
}
return result;
return await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/gamecards/" + appID, SteamCookieDictionary).ConfigureAwait(false);
}
}
}

View File

@@ -35,37 +35,58 @@ namespace ArchiSteamFarm {
internal class Bot {
private const ushort CallbackSleep = 500; // In miliseconds
private readonly Dictionary<string, string> Config = new Dictionary<string, string>();
private static readonly HashSet<Bot> Bots = new HashSet<Bot>();
internal readonly string BotName;
private readonly string ConfigFile;
private readonly string SentryFile;
private readonly CardsFarmer CardsFarmer;
internal ulong BotID { get; private set; }
private bool IsRunning = false;
private string AuthCode, TwoFactorAuth;
internal readonly string BotName;
internal ArchiHandler ArchiHandler { get; private set; }
internal ArchiWebHandler ArchiWebHandler { get; private set; }
internal CallbackManager CallbackManager { get; private set; }
internal CardsFarmer CardsFarmer { get; private set; }
internal SteamClient SteamClient { get; private set; }
internal SteamFriends SteamFriends { get; private set; }
internal SteamUser SteamUser { get; private set; }
internal Trading Trading { get; private set; }
// Config variables
private 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"]; } }
internal ulong SteamMasterID { get { return ulong.Parse(Config["SteamMasterID"]); } }
private ulong SteamMasterClanID { get { return ulong.Parse(Config["SteamMasterClanID"]); } }
internal bool Enabled { get; private set; } = true;
internal string SteamLogin { get; private set; } = "null";
internal string SteamPassword { get; private set; } = "null";
internal string SteamNickname { get; private set; } = "null";
internal string SteamApiKey { get; private set; } = "null";
internal string SteamParentalPIN { get; private set; } = "0";
internal ulong SteamMasterID { get; private set; } = 76561198006963719;
internal ulong SteamMasterClanID { get; private set; } = 0;
internal bool ShutdownOnFarmingFinished { get; private set; } = false;
internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint> { 368020 };
internal bool Statistics { get; private set; } = true;
internal static int GetRunningBotsCount() {
int result;
lock (Bots) {
result = Bots.Count;
}
return result;
}
internal static async Task ShutdownAllBots() {
List<Task> tasks = new List<Task>();
lock (Bots) {
foreach (Bot bot in Bots) {
tasks.Add(Task.Run(async () => await bot.Shutdown().ConfigureAwait(false)));
}
}
await Task.WhenAll(tasks).ConfigureAwait(false);
}
internal Bot(string botName) {
BotName = botName;
CardsFarmer = new CardsFarmer(this);
ConfigFile = Path.Combine(Program.ConfigDirectoryPath, BotName + ".xml");
SentryFile = Path.Combine(Program.ConfigDirectoryPath, BotName + ".bin");
@@ -76,6 +97,39 @@ namespace ArchiSteamFarm {
return;
}
lock (Bots) {
Bots.Add(this);
}
// Initialize
SteamClient = new SteamClient();
ArchiHandler = new ArchiHandler();
SteamClient.AddHandler(ArchiHandler);
CallbackManager = new CallbackManager(SteamClient);
CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
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);
CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
CallbackManager.Subscribe<ArchiHandler.NotificationCallback>(OnNotification);
CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse);
ArchiWebHandler = new ArchiWebHandler(this, SteamApiKey);
CardsFarmer = new CardsFarmer(this);
Trading = new Trading(this);
// Start
Start();
}
@@ -96,53 +150,83 @@ namespace ArchiSteamFarm {
continue;
}
Config.Add(key, value);
switch (key) {
case "Enabled":
Enabled = bool.Parse(value);
break;
case "SteamLogin":
SteamLogin = value;
break;
case "SteamPassword":
SteamPassword = value;
break;
case "SteamNickname":
SteamNickname = value;
break;
case "SteamApiKey":
SteamApiKey = value;
break;
case "SteamParentalPIN":
SteamParentalPIN = value;
break;
case "SteamMasterID":
SteamMasterID = ulong.Parse(value);
break;
case "SteamMasterClanID":
SteamMasterClanID = ulong.Parse(value);
break;
case "ShutdownOnFarmingFinished":
ShutdownOnFarmingFinished = bool.Parse(value);
break;
case "Blacklist":
foreach (string appID in value.Split(',')) {
Blacklist.Add(uint.Parse(appID));
}
break;
case "Statistics":
Statistics = bool.Parse(value);
break;
default:
Logging.LogGenericWarning(BotName, "Unrecognized config value: " + key + "=" + value);
break;
}
}
}
}
internal void Start() {
if (SteamClient != null) {
if (IsRunning) {
return;
}
SteamClient = new SteamClient();
ArchiHandler = new ArchiHandler();
SteamClient.AddHandler(ArchiHandler);
CallbackManager = new CallbackManager(SteamClient);
CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
SteamFriends = SteamClient.GetHandler<SteamFriends>();
CallbackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList);
CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg);
SteamUser = SteamClient.GetHandler<SteamUser>();
CallbackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
CallbackManager.Subscribe<ArchiHandler.NotificationCallback>(OnNotification);
CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse);
ArchiWebHandler = new ArchiWebHandler(this, SteamApiKey);
Trading = new Trading(this);
SteamClient.Connect();
IsRunning = true;
Task.Run(() => HandleCallbacks());
}
internal void Stop() {
if (SteamClient == null) {
internal async Task Stop() {
if (!IsRunning) {
return;
}
await CardsFarmer.StopFarming().ConfigureAwait(false);
SteamClient.Disconnect();
SteamClient = null;
CallbackManager = null;
IsRunning = false;
}
internal async Task Shutdown() {
await Stop().ConfigureAwait(false);
lock (Bots) {
Bots.Remove(this);
}
Program.OnBotShutdown(this);
}
internal async Task OnFarmingFinished() {
if (ShutdownOnFarmingFinished) {
await Shutdown().ConfigureAwait(false);
}
}
internal void PlayGame(params ulong[] gameIDs) {
@@ -151,7 +235,7 @@ namespace ArchiSteamFarm {
private void HandleCallbacks() {
TimeSpan timeSpan = TimeSpan.FromMilliseconds(CallbackSleep);
while (CallbackManager != null) {
while (IsRunning) {
CallbackManager.RunWaitCallbacks(timeSpan);
}
}
@@ -174,6 +258,14 @@ namespace ArchiSteamFarm {
sentryHash = CryptoHelper.SHAHash(sentryFileContent);
}
if (SteamLogin.Equals("null")) {
SteamLogin = Program.GetUserInput(BotName, Program.EUserInputType.Login);
}
if (SteamPassword.Equals("null")) {
SteamPassword = Program.GetUserInput(BotName, Program.EUserInputType.Password);
}
SteamUser.LogOn(new SteamUser.LogOnDetails {
Username = SteamLogin,
Password = SteamPassword,
@@ -187,6 +279,7 @@ namespace ArchiSteamFarm {
if (callback == null) {
return;
}
if (SteamClient == null) {
return;
}
@@ -222,7 +315,7 @@ namespace ArchiSteamFarm {
}
}
private void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
private async void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
if (callback == null) {
return;
}
@@ -244,6 +337,27 @@ namespace ArchiSteamFarm {
if (message.Length == 17 && message[5] == '-' && message[11] == '-') {
ArchiHandler.RedeemKey(message);
}
switch (message) {
case "!farm":
await CardsFarmer.StartFarming().ConfigureAwait(false);
break;
case "!exit":
await Shutdown().ConfigureAwait(false);
break;
}
}
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) {
@@ -267,45 +381,49 @@ namespace ArchiSteamFarm {
return;
}
if (callback.ClientSteamID != 0) {
BotID = callback.ClientSteamID;
}
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!");
string steamNickname = SteamNickname;
if (!string.IsNullOrEmpty(steamNickname) && !steamNickname.Equals("null")) {
SteamFriends.SetPersonaName(steamNickname);
if (!SteamNickname.Equals("null")) {
SteamFriends.SetPersonaName(SteamNickname);
}
ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL);
if (SteamParentalPIN.Equals("null")) {
SteamParentalPIN = Program.GetUserInput(BotName, Program.EUserInputType.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:
case EResult.TryAnotherCM:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult + ", retrying...");
Stop();
await Stop().ConfigureAwait(false);
Thread.Sleep(5000);
Start();
break;
default:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult);
Stop();
await Shutdown().ConfigureAwait(false);
break;
}
}

View File

@@ -31,31 +31,47 @@ namespace ArchiSteamFarm {
internal class CardsFarmer {
private const byte StatusCheckSleep = 5; // In minutes, how long to wait before checking the appID again
private readonly ManualResetEvent FarmResetEvent = new ManualResetEvent(false);
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
private readonly Bot Bot;
private bool NowFarming;
private readonly AutoResetEvent AutoResetEvent = new AutoResetEvent(false);
private volatile bool NowFarming = false;
internal CardsFarmer(Bot bot) {
Bot = bot;
}
internal async Task StartFarming() {
await StopFarming().ConfigureAwait(false);
await Semaphore.WaitAsync().ConfigureAwait(false);
if (NowFarming) {
Semaphore.Release();
return;
}
Logging.LogGenericInfo(Bot.BotName, "Checking badges...");
// Find the number of badge pages
HtmlDocument badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false);
if (badgesDocument == null) {
Logging.LogGenericWarning(Bot.BotName, "Could not get badges information, farming is stopped!");
Semaphore.Release();
return;
}
var maxPages = 1;
HtmlNodeCollection badgesPagesNodeCollection = badgesDocument.DocumentNode.SelectNodes("//a[@class='pagelink']");
if (badgesPagesNodeCollection != null) {
maxPages = (byte) (badgesPagesNodeCollection.Count / 2 + 1); // Don't do this at home
maxPages = (badgesPagesNodeCollection.Count / 2) + 1; // Don't do this at home
}
// Find APPIDs we need to farm
List<uint> appIDs = new List<uint>();
for (var page = 1; page <= maxPages; page++) {
Logging.LogGenericInfo(Bot.BotName, "Checking page: " + page + "/" + maxPages);
if (page > 1) { // Because we fetched page number 1 already
badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(page).ConfigureAwait(false);
if (badgesDocument == null) {
@@ -71,14 +87,18 @@ namespace ArchiSteamFarm {
foreach (HtmlNode badgesPageNode in badgesPageNodes) {
string steamLink = badgesPageNode.GetAttributeValue("href", null);
if (steamLink == null) {
page = maxPages; // Break from outer loop
break;
Logging.LogGenericError(Bot.BotName, "Couldn't get steamLink for one of the games: " + badgesPageNode.OuterHtml);
continue;
}
uint appID = (uint) Utilities.OnlyNumbers(steamLink);
if (appID == 0) {
page = maxPages; // Break from outer loop
break;
Logging.LogGenericError(Bot.BotName, "Couldn't get appID for one of the games: " + badgesPageNode.OuterHtml);
continue;
}
if (Bot.Blacklist.Contains(appID)) {
continue;
}
appIDs.Add(appID);
@@ -92,11 +112,31 @@ namespace ArchiSteamFarm {
if (await Farm(appID).ConfigureAwait(false)) {
appIDs.Remove(appID);
} else {
break;
return;
}
}
Logging.LogGenericInfo(Bot.BotName, "Farming finished!");
await Bot.OnFarmingFinished().ConfigureAwait(false);
}
internal async Task StopFarming() {
await Semaphore.WaitAsync().ConfigureAwait(false);
if (!NowFarming) {
Semaphore.Release();
return;
}
Logging.LogGenericInfo(Bot.BotName, "Sending signal to stop farming");
FarmResetEvent.Set();
while (NowFarming) {
Logging.LogGenericInfo(Bot.BotName, "Waiting for reaction...");
Thread.Sleep(1000);
}
FarmResetEvent.Reset();
Logging.LogGenericInfo(Bot.BotName, "Farming stopped!");
Semaphore.Release();
}
private async Task<bool?> ShouldFarm(ulong appID) {
@@ -112,12 +152,6 @@ namespace ArchiSteamFarm {
}
private async Task<bool> Farm(ulong appID) {
if (NowFarming) {
AutoResetEvent.Set();
Thread.Sleep(1000);
AutoResetEvent.Reset();
}
bool success = true;
bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
while (keepFarming == null || keepFarming.Value) {
@@ -125,17 +159,20 @@ namespace ArchiSteamFarm {
NowFarming = true;
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID);
Bot.PlayGame(appID);
Semaphore.Release(); // We're farming, allow other tasks to shut us down
} else {
Logging.LogGenericInfo(Bot.BotName, "Still farming: " + appID);
}
if (AutoResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
success = false;
break;
}
keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
}
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID);
Bot.PlayGame(0);
NowFarming = false;
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID);
return success;
}
}

View File

@@ -0,0 +1,40 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
Copyright 2015 Łukasz "JustArchi" Domeradzki
Contact: JustArchi@JustArchi.net
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System.Diagnostics;
namespace ArchiSteamFarm {
internal static class Debugging {
internal static bool IsReleaseBuild { get; private set; } = true;
static Debugging() {
MarkIfDebug();
}
[Conditional("DEBUG")]
private static void MarkIfDebug() {
IsReleaseBuild = false;
}
}
}

View File

@@ -23,6 +23,7 @@
*/
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace ArchiSteamFarm {
@@ -49,10 +50,16 @@ 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);
}
[Conditional("DEBUG")]
internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") {
LogGenericDebug("DEBUG", message, previousMethodName);
}

View File

@@ -22,64 +22,122 @@
*/
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 const string ConfigDirectoryPath = "config";
private static readonly HashSet<Bot> Bots = new HashSet<Bot>();
internal static readonly object ConsoleLock = new object();
internal enum EUserInputType {
Login,
Password,
SteamGuard,
SteamParentalPIN,
TwoFactorAuthentication,
}
internal static void Exit(int exitCode = 0) {
ShutdownAllBots();
internal const ulong ArchiSCFarmGroup = 103582791440160998;
internal const string ConfigDirectoryPath = "config";
private const string LatestGithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases/latest";
internal static readonly object ConsoleLock = new object();
private static readonly ManualResetEvent ShutdownResetEvent = new ManualResetEvent(false);
private static readonly AssemblyName AssemblyName = Assembly.GetExecutingAssembly().GetName();
private static readonly string ExeName = AssemblyName.Name + ".exe";
private static readonly string Version = AssemblyName.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;
Logging.LogGenericNotice("", "Local version: " + localVersion);
Logging.LogGenericNotice("", "Remote version: " + remoteVersion);
int comparisonResult = localVersion.CompareTo(remoteVersion);
if (localVersion.CompareTo(remoteVersion) < 0) {
Logging.LogGenericNotice("", "New version is available!");
Logging.LogGenericNotice("", "Consider updating yourself!");
Thread.Sleep(5000);
} else if (localVersion.CompareTo(remoteVersion) > 0) {
Logging.LogGenericNotice("", "You're currently using pre-release version!");
Logging.LogGenericNotice("", "Be careful!");
}
}
internal static async Task Exit(int exitCode = 0) {
await Bot.ShutdownAllBots().ConfigureAwait(false);
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;
}
private static void ShutdownAllBots() {
lock (Bots) {
foreach (Bot bot in Bots) {
bot.Stop();
}
Bots.Clear();
internal static void OnBotShutdown(Bot bot) {
if (Bot.GetRunningBotsCount() == 0) {
Logging.LogGenericInfo("Main", "No bots are running, exiting");
Thread.Sleep(5000); // This might be the only message user gets, consider giving him some time
ShutdownResetEvent.Set();
}
}
private static void Main(string[] args) {
// 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("..");
}
Logging.LogGenericInfo("Main", "Archi's Steam Farm, version " + Version);
Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait();
if (!Directory.Exists(ConfigDirectoryPath)) {
Logging.LogGenericError("Main", "Config directory doesn't exist!");
Console.ReadLine();
Exit(1);
Task.Run(async () => await Exit(1).ConfigureAwait(false)).Wait();
}
lock (Bots) {
foreach (var configFile in Directory.EnumerateFiles(ConfigDirectoryPath, "*.xml")) {
string botName = Path.GetFileNameWithoutExtension(configFile);
Bots.Add(new Bot(botName));
foreach (var configFile in Directory.EnumerateFiles(ConfigDirectoryPath, "*.xml")) {
string botName = Path.GetFileNameWithoutExtension(configFile);
Bot bot = new Bot(botName);
if (!bot.Enabled) {
Logging.LogGenericInfo(botName, "Not starting this instance because it's disabled in config file");
}
}
Thread.Sleep(Timeout.Infinite);
// Check if we got any bots running
OnBotShutdown(null);
ShutdownResetEvent.WaitOne();
}
}
}

View 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.5.0.0")]
[assembly: AssemblyFileVersion("0.5.0.0")]

View File

@@ -55,9 +55,14 @@ namespace ArchiSteamFarm {
internal bool from_real_time_trade { get; set; }
// Extra
private ulong _OtherSteamID64 = 0;
internal ulong OtherSteamID64 {
get {
return new SteamID((uint) accountid_other, EUniverse.Public, EAccountType.Individual).ConvertToUInt64();
if (_OtherSteamID64 == 0 && accountid_other != 0) {
_OtherSteamID64 = new SteamID((uint) accountid_other, EUniverse.Public, EAccountType.Individual).ConvertToUInt64();
}
return _OtherSteamID64;
}
}
}

View File

@@ -28,9 +28,9 @@ using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal sealed class Trading {
private Bot Bot;
private readonly Bot Bot;
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
private volatile byte ParsingTasks = 0;
private SemaphoreSlim semaphore = new SemaphoreSlim(1);
internal Trading(Bot bot) {
Bot = bot;
@@ -44,7 +44,7 @@ namespace ArchiSteamFarm {
}
private async Task ParseActiveTrades() {
await semaphore.WaitAsync().ConfigureAwait(false);
await Semaphore.WaitAsync().ConfigureAwait(false);
List<SteamTradeOffer> tradeOffers = Bot.ArchiWebHandler.GetTradeOffers();
if (tradeOffers != null) {
@@ -62,7 +62,7 @@ namespace ArchiSteamFarm {
}
ParsingTasks--;
semaphore.Release();
Semaphore.Release();
}
private async Task ParseTrade(SteamTradeOffer tradeOffer) {
@@ -75,21 +75,17 @@ namespace ArchiSteamFarm {
return;
}
ulong steamID = tradeOffer.OtherSteamID64;
ulong otherSteamID = tradeOffer.OtherSteamID64;
bool success = false;
bool tradeAccepted = false;
if (tradeOffer.items_to_give.Count == 0 || steamID == Bot.SteamMasterID) {
if (tradeOffer.items_to_give.Count == 0 || otherSteamID == Bot.SteamMasterID) {
tradeAccepted = true;
success = await Bot.ArchiWebHandler.AcceptTradeOffer(tradeID).ConfigureAwait(false);
} else {
success = Bot.ArchiWebHandler.DeclineTradeOffer(tradeID);
}
if (!success) {
Logging.LogGenericWarning(Bot.BotName, "Response to trade " + tradeID + " failed!");
}
if (tradeAccepted && success) {
// Do whatever we want with success
}

View File

@@ -23,6 +23,7 @@
*/
using HtmlAgilityPack;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -48,89 +49,162 @@ 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;
}
internal static async Task<HttpResponseMessage> UrlToHttpResponse(string websiteAddress) {
return await UrlToHttpResponse(websiteAddress, null).ConfigureAwait(false);
}
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;
}
}

BIN
ArchiSteamFarm/cirno.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

View File

@@ -3,25 +3,51 @@
<!-- 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 -->
<!-- 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 -->
<SteamLogin type="string" value="Foo"/>
<!-- TIP: You can use "null" if you wish to enter login on every startup -->
<SteamLogin type="string" value="null"/>
<!-- This is your steam password, the one you use for logging in to steam -->
<SteamPassword type="string" value="Bar"/>
<!-- TIP: You can use "null" if you wish to enter password on every startup -->
<SteamPassword type="string" value="null"/>
<!-- 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"/>
<!-- This switch defines if bot should disconnect once farming is finished -->
<!-- When no bots are active, ASF will shutdown as well -->
<!-- Some people may want to keep their bots 24/7, other disconnect them after job is done -->
<!-- Choose yourself what you prefer -->
<ShutdownOnFarmingFinished type="bool" value="false"/>
<!-- 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>

View File

@@ -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>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View 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

BIN
tools/ILMerge.exe Normal file

Binary file not shown.