Compare commits

..

75 Commits

Author SHA1 Message Date
JustArchi
e8e393b320 Correct anti-captcha delay 2015-11-27 16:25:03 +01:00
JustArchi
84db370516 Try to implement some anty-captcha, #22 2015-11-26 01:22:56 +01:00
JustArchi
173148ce25 Add support for longer cd-keys 2015-11-25 16:49:01 +01:00
JustArchi
0fd0528fd0 Use global timeout 2015-11-25 16:35:09 +01:00
JustArchi
664a0e0758 Use new ArchiBoT's WebBrowser 2015-11-25 16:31:39 +01:00
JustArchi
6454e3ee12 Packages update 2015-11-25 05:35:14 +01:00
Łukasz Domeradzki
33f4a82dd5 Sometimes Git SHA1 hash is everything you need 2015-11-22 19:42:00 +01:00
Łukasz Domeradzki
9bd6532411 Update README.md 2015-11-22 01:50:17 +01:00
JustArchi
b89d2977f8 10 hours should be enough 2015-11-22 01:45:58 +01:00
JustArchi
25b557d5d1 Misc 2015-11-22 01:40:44 +01:00
JustArchi
3e34fabfaf Avoid possible steam network fuckups 2015-11-22 01:22:45 +01:00
Łukasz Domeradzki
fc49e8ffa7 Update README.md 2015-11-22 01:08:12 +01:00
JustArchi
48a5eeec29 Misc 2015-11-21 21:30:49 +01:00
JustArchi
7fa176ef7b Fix current status to match actual situation 2015-11-21 21:28:34 +01:00
JustArchi
bfaa99a8a9 Revolution is here 2015-11-21 21:00:46 +01:00
JustArchi
1ff4ed026e Prepare configs for future cards farm algorithms 2015-11-21 18:27:58 +01:00
JustArchi
1703bbfb68 Version bump 2015-11-20 19:08:55 +01:00
JustArchi
a6a2e1605d Misc 2015-11-20 14:47:16 +01:00
JustArchi
c0c61913c2 Fix crash related to trading 2015-11-19 18:34:18 +01:00
JustArchi
fb2437d75d Code cleanup & improvements of previous pull request 2015-11-18 22:10:24 +01:00
Łukasz Domeradzki
499e55c473 Merge pull request #15 from Ryzhehvost/statusplus
added extended !status syntax
2015-11-18 21:59:40 +01:00
jogger
dfd4513b16 added extended !status syntax 2015-11-18 22:15:10 +02:00
JustArchi
f873da7236 Packages update 2015-11-18 14:49:31 +01:00
JustArchi
59360c5b60 Formatting is killing me 2015-11-18 14:30:05 +01:00
JustArchi
750c34189a General code review 2015-11-18 14:28:46 +01:00
JustArchi
7c3f5beb3a Hopefully fix all farming deadlocks, thanks to @Ryzhehvost, closes #14 2015-11-18 14:12:29 +01:00
JustArchi
8dfe095dae Misc 2015-11-15 21:57:46 +01:00
JustArchi
53022632e0 Misc 2015-11-15 17:06:26 +01:00
Łukasz Domeradzki
29a916e5ad Update README.md 2015-11-14 18:04:46 +01:00
JustArchi
44b3a518bd 5 seconds seems good for now 2015-11-04 18:30:38 +01:00
JustArchi
1fe60e7037 Trim GetUserInput(), closes #12 2015-11-04 18:18:04 +01:00
JustArchi
27ad98492f Misc 2015-11-04 05:01:18 +01:00
JustArchi
e3386c5b29 Misc 2015-11-04 04:55:25 +01:00
JustArchi
021ac470d3 Handle broken configs 2015-11-04 04:51:52 +01:00
JustArchi
b4fb0bf9a6 Update defaults according to example.xml changes 2015-11-04 04:46:55 +01:00
JustArchi
b63dd1035c Improve flow and get rid of synchronous sleeps 2015-11-04 04:42:13 +01:00
JustArchi
f577e1a6cb Bots are now limited in Start() 2015-11-04 04:35:34 +01:00
JustArchi
34ffb975b6 Use new experimental delay everywhere 2015-11-04 04:32:26 +01:00
Łukasz Domeradzki
5a3b132d5e Merge pull request #11 from Pandiora/patch-6
Random Number for delayed connecting bots
2015-11-04 04:19:30 +01:00
Pandi
ef29b6f33d Random Number for delayed connecting bots
See my answer @ #10
2015-11-03 19:06:50 +01:00
JustArchi
e8335ac183 EXPERIMENTAL: Try to solve #10 2015-11-03 09:34:35 +01:00
JustArchi
90339fb276 Merge branch 'master' of https://github.com/JustArchi/ArchiSteamFarm 2015-11-03 00:47:23 +01:00
JustArchi
88759303dd Add more ignored IDs 2015-11-03 00:47:21 +01:00
Łukasz Domeradzki
befe01ca59 Merge pull request #8 from Pandiora/patch-5
Added Debian 8.1 (tested and working)
2015-11-02 02:12:52 +01:00
Pandi
c9cc728da3 Jessi > Jessie - fixed 2015-11-01 22:27:38 +01:00
Pandi
a81a59396d Added Debian 8.1 (tested and working) 2015-11-01 22:25:57 +01:00
Łukasz Domeradzki
df3fcfb1df Merge pull request #7 from Pandiora/patch-4
Cleaned up better looking Readme
2015-11-01 18:57:25 +01:00
Pandi
e097b33d89 Cleaned up better looking Readme
Removed the part of smart multi-game-idling where you wrote about the 2 hour-restriction of steam. AFAIK this restriction doesn´t exists anymore and you can farm cards on every game directly after you bought it. Added new sections filled with data I´m sure bout:

- Current Commands
- Operating Systems

Also rewrote some text-fragments or edited the format. Hope this looks good for you too and helps.
2015-11-01 18:55:47 +01:00
Łukasz Domeradzki
db6e775b10 Merge pull request #6 from Pandiora/patch-3
SteamMasterID Change
2015-11-01 18:01:16 +01:00
Pandiora
b53c41a0f9 removed newline
¯\_(ツ)_/¯
2015-11-01 18:01:07 +01:00
Pandiora
fec4873843 SteamID64 - changed invalid to 0
check
2015-11-01 17:58:52 +01:00
Pandiora
1e2efe38f1 SteamMasterID Change
To avoid ppl using your SteamID by accident, replaced it  with "00000000000000000" and added yours as example.
2015-11-01 17:56:44 +01:00
JustArchi
3e0dfac091 Misc 2015-11-01 17:53:38 +01:00
Łukasz Domeradzki
36d745aece Merge pull request #5 from Pandiora/patch-2
Explanation about how to find the groupID64
2015-11-01 17:46:56 +01:00
Pandiora
7896e7924e Explanation about how to find the groupID64
Didn´t added this to Wiki, because explanation is relatively short.
2015-11-01 17:45:19 +01:00
JustArchi
5b3c730d51 Ship items together with their IDs 2015-11-01 16:53:08 +01:00
JustArchi
f3aee0c34f Add support for activated games names 2015-11-01 16:46:02 +01:00
JustArchi
47389f67b8 One more status 2015-11-01 05:21:18 +01:00
JustArchi
19e72c93c1 Bugfix 2015-11-01 02:08:41 +01:00
JustArchi
164240641b Work work 2015-11-01 02:04:44 +01:00
JustArchi
337c397505 0.6 2015-10-31 09:17:56 +01:00
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
33 changed files with 54966 additions and 362 deletions

View File

@@ -24,6 +24,8 @@
using SteamKit2;
using SteamKit2.Internal;
using System.Collections.Generic;
using System.IO;
namespace ArchiSteamFarm {
internal sealed class ArchiHandler : ClientMsgHandler {
@@ -33,21 +35,31 @@ namespace ArchiSteamFarm {
Unknown = -1,
OK = 0,
AlreadyOwned = 9,
RegionLockedKey = 13,
InvalidKey = 14,
DuplicatedKey = 15,
BaseGameRequired = 24,
OnCooldown = 53
}
internal EResult Result { get; private set; }
internal EPurchaseResult PurchaseResult { get; private set; }
internal int ErrorCode { get; private set; }
internal byte[] ReceiptInfo { get; private set; }
internal KeyValue ReceiptInfo { get; private set; } = new KeyValue();
internal Dictionary<uint, string> Items { get; private set; } = new Dictionary<uint, string>();
internal PurchaseResponseCallback(CMsgClientPurchaseResponse body) {
Result = (EResult) body.eresult;
ErrorCode = body.purchase_result_details;
ReceiptInfo = body.purchase_receipt_info;
PurchaseResult = (EPurchaseResult) ErrorCode;
PurchaseResult = (EPurchaseResult) body.purchase_result_details;
using (MemoryStream ms = new MemoryStream(body.purchase_receipt_info)) {
if (!ReceiptInfo.TryReadAsBinary(ms)) {
return;
}
foreach (KeyValue lineItem in ReceiptInfo["lineitems"].Children) {
Items.Add((uint) lineItem["PackageID"].AsUnsignedLong(), lineItem["ItemDescription"].AsString());
}
}
}
}
@@ -78,14 +90,30 @@ namespace ArchiSteamFarm {
Client.Send(request);
}
internal void PlayGames(params ulong[] gameIDs) {
internal void PlayGames(params uint[] gameIDs) {
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
foreach (ulong gameID in gameIDs) {
if (gameID != 0) {
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
game_id = new GameID(gameID),
});
foreach (uint gameID in gameIDs) {
if (gameID == 0) {
continue;
}
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
game_id = new GameID(gameID),
});
}
Client.Send(request);
}
internal void PlayGames(ICollection<uint> gameIDs) {
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
foreach (uint gameID in gameIDs) {
if (gameID == 0) {
continue;
}
request.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed {
game_id = new GameID(gameID),
});
}
Client.Send(request);
}
@@ -98,15 +126,17 @@ namespace ArchiSteamFarm {
}
public sealed override void HandleMsg(IPacketMsg packetMsg) {
if (packetMsg != null) {
switch (packetMsg.MsgType) {
case EMsg.ClientPurchaseResponse:
HandlePurchaseResponse(packetMsg);
break;
case EMsg.ClientUserNotifications:
HandleUserNotifications(packetMsg);
break;
}
if (packetMsg == null) {
return;
}
switch (packetMsg.MsgType) {
case EMsg.ClientPurchaseResponse:
HandlePurchaseResponse(packetMsg);
break;
case EMsg.ClientUserNotifications:
HandleUserNotifications(packetMsg);
break;
}
}

View File

@@ -50,12 +50,24 @@
<DocumentationFile>
</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>cirno.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</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-beta3\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>
@@ -79,6 +91,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" />
@@ -86,6 +99,7 @@
<Compile Include="SteamTradeOffer.cs" />
<Compile Include="Trading.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="WebBrowser.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -103,7 +117,25 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="cirno.ico" />
<Content Include="config\example.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent Condition=" '$(OS)' != 'Unix' ">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>
<!-- 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,18 +28,20 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal class ArchiWebHandler {
private const int Timeout = 1000 * 15; // In miliseconds
internal sealed class ArchiWebHandler {
private const int Timeout = 1000 * WebBrowser.HttpTimeout; // In miliseconds
private readonly Bot Bot;
private readonly string ApiKey;
private readonly Dictionary<string, string> SteamCookieDictionary = new Dictionary<string, string>();
private ulong SteamID;
private string VanityURL;
private readonly Dictionary<string, string> SteamCookieDictionary = new Dictionary<string, string>();
// This is required because home_process request must be done on final URL
private string GetHomeProcess() {
@@ -57,12 +59,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 +125,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 WebBrowser.UrlPost("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 +224,46 @@ 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 WebBrowser.UrlPost(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 WebBrowser.UrlPost(request, postData, SteamCookieDictionary).ConfigureAwait(false);
}
internal async Task<bool> AcceptTradeOffer(ulong tradeID) {
if (tradeID == 0) {
return false;
@@ -219,7 +283,25 @@ namespace ArchiSteamFarm {
{"tradeofferid", tradeID.ToString()}
};
return await Utilities.UrlPostRequest(request, postData, SteamCookieDictionary, referer).ConfigureAwait(false);
HttpResponseMessage result = await WebBrowser.UrlPost(request, postData, SteamCookieDictionary, referer).ConfigureAwait(false);
if (result == null) {
return 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,32 +334,12 @@ 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;
}
return await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/badges?p=" + page, SteamCookieDictionary).ConfigureAwait(false);
return await WebBrowser.UrlGetToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/badges?p=" + page, SteamCookieDictionary).ConfigureAwait(false);
}
internal async Task<HtmlDocument> GetGameCardsPage(ulong appID) {
@@ -285,7 +347,7 @@ namespace ArchiSteamFarm {
return null;
}
return await Utilities.UrlToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/gamecards/" + appID, SteamCookieDictionary).ConfigureAwait(false);
return await WebBrowser.UrlGetToHtmlDocument("http://steamcommunity.com/profiles/" + SteamID + "/gamecards/" + appID, SteamCookieDictionary).ConfigureAwait(false);
}
}
}

423
ArchiSteamFarm/Bot.cs Normal file → Executable file
View File

@@ -24,97 +24,100 @@
using SteamKit2;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace ArchiSteamFarm {
internal class Bot {
internal sealed class Bot {
private const ushort CallbackSleep = 500; // In miliseconds
private readonly Dictionary<string, string> Config = new Dictionary<string, string>();
private static readonly ConcurrentDictionary<string, Bot> Bots = new ConcurrentDictionary<string, Bot>();
private readonly string ConfigFile, SentryFile;
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 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 HashSet<uint> Blacklist { get; } = new HashSet<uint>();
internal bool Enabled { get; private set; } = false;
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; } = 0;
internal ulong SteamMasterClanID { get; private set; } = 0;
internal bool CardDropsRestricted { get; private set; } = false;
internal bool ShutdownOnFarmingFinished { get; private set; } = false;
internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint> { 303700, 335590, 368020 };
internal bool Statistics { get; private set; } = true;
private static bool IsValidCdKey(string key) {
if (string.IsNullOrEmpty(key)) {
return false;
}
if (key.Length != 17 && key.Length != 29) {
return false;
}
for (byte i = 5; i < key.Length; i += 6) {
if (key[i] != '-') {
return false;
}
}
return true;
}
internal static int GetRunningBotsCount() {
return Bots.Count;
}
internal static async Task ShutdownAllBots() {
List<Task> tasks = new List<Task>();
foreach (Bot bot in Bots.Values) {
tasks.Add(Task.Run(async () => await bot.Shutdown().ConfigureAwait(false)));
}
await Task.WhenAll(tasks).ConfigureAwait(false);
}
internal Bot(string botName) {
if (Bots.ContainsKey(botName)) {
return;
}
BotName = botName;
CardsFarmer = new CardsFarmer(this);
ConfigFile = Path.Combine(Program.ConfigDirectoryPath, BotName + ".xml");
SentryFile = Path.Combine(Program.ConfigDirectoryPath, BotName + ".bin");
ReadConfig();
if (!ReadConfig()) {
return;
}
if (!Enabled) {
return;
}
Start();
}
private void ReadConfig() {
using (XmlReader reader = XmlReader.Create(ConfigFile)) {
while (reader.Read()) {
if (reader.NodeType != XmlNodeType.Element) {
continue;
}
string key = reader.Name;
if (string.IsNullOrEmpty(key)) {
continue;
}
string value = reader.GetAttribute("value");
if (string.IsNullOrEmpty(value)) {
continue;
}
Config.Add(key, value);
switch (key) {
case "Blacklist":
foreach (string appID in value.Split(',')) {
Blacklist.Add(uint.Parse(appID));
}
break;
}
}
}
}
internal void Start() {
if (SteamClient != null) {
return;
}
Bots.AddOrUpdate(BotName, this, (key, value) => this);
// Initialize
SteamClient = new SteamClient();
ArchiHandler = new ArchiHandler();
@@ -138,33 +141,214 @@ namespace ArchiSteamFarm {
CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse);
ArchiWebHandler = new ArchiWebHandler(this, SteamApiKey);
CardsFarmer = new CardsFarmer(this);
Trading = new Trading(this);
SteamClient.Connect();
Task.Run(() => HandleCallbacks());
// Start
var fireAndForget = Task.Run(async () => await Start().ConfigureAwait(false));
}
internal void Stop() {
if (SteamClient == null) {
private bool ReadConfig() {
if (!File.Exists(ConfigFile)) {
return false;
}
try {
using (XmlReader reader = XmlReader.Create(ConfigFile)) {
while (reader.Read()) {
if (reader.NodeType != XmlNodeType.Element) {
continue;
}
string key = reader.Name;
if (string.IsNullOrEmpty(key)) {
continue;
}
string value = reader.GetAttribute("value");
if (string.IsNullOrEmpty(value)) {
continue;
}
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 "CardDropsRestricted":
CardDropsRestricted = bool.Parse(value);
break;
case "ShutdownOnFarmingFinished":
ShutdownOnFarmingFinished = bool.Parse(value);
break;
case "Blacklist":
Blacklist.Clear();
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;
}
}
}
} catch (Exception e) {
Logging.LogGenericException(BotName, e);
Logging.LogGenericError(BotName, "Your config for this bot instance is invalid, it won't run!");
return false;
}
return true;
}
internal async Task Start() {
if (IsRunning) {
return;
}
SteamClient.Disconnect();
SteamClient = null;
CallbackManager = null;
IsRunning = true;
Logging.LogGenericInfo(BotName, "Starting...");
await Program.LimitSteamRequestsAsync().ConfigureAwait(false);
SteamClient.Connect();
var fireAndForget = Task.Run(() => HandleCallbacks());
}
internal void PlayGame(params ulong[] gameIDs) {
ArchiHandler.PlayGames(gameIDs);
internal async Task Stop() {
if (!IsRunning) {
return;
}
await CardsFarmer.StopFarming().ConfigureAwait(false);
IsRunning = false;
SteamClient.Disconnect();
}
private async Task<bool> Shutdown(string botNameToShutdown) {
Bot botToShutdown;
if (!Bots.TryGetValue(botNameToShutdown, out botToShutdown)) {
return false;
}
await botToShutdown.Stop().ConfigureAwait(false);
Bots.TryRemove(botNameToShutdown, out botToShutdown);
Program.OnBotShutdown(botToShutdown);
return true;
}
internal async Task<bool> Shutdown() {
return await Shutdown(BotName).ConfigureAwait(false);
}
internal async Task OnFarmingFinished() {
if (ShutdownOnFarmingFinished) {
await Shutdown().ConfigureAwait(false);
}
}
private void HandleCallbacks() {
TimeSpan timeSpan = TimeSpan.FromMilliseconds(CallbackSleep);
while (CallbackManager != null) {
while (IsRunning) {
CallbackManager.RunWaitCallbacks(timeSpan);
}
}
private void SendMessageToUser(ulong steamID, string message) {
if (steamID == 0 || string.IsNullOrEmpty(message)) {
return;
}
SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, message);
}
private void ResponseStatus(ulong steamID, string botName = null) {
if (steamID == 0) {
return;
}
Bot bot;
if (string.IsNullOrEmpty(botName)) {
bot = this;
} else {
if (!Bots.TryGetValue(botName, out bot)) {
SendMessageToUser(steamID, "Couldn't find any bot named " + botName + "!");
return;
}
}
if (bot.CardsFarmer.CurrentGamesFarming.Count > 0) {
SendMessageToUser(steamID, "Bot " + bot.BotName + " is currently farming appIDs: " + string.Join(", ", bot.CardsFarmer.CurrentGamesFarming) + " and has a total of " + bot.CardsFarmer.GamesToFarm.Count + " games left to farm");
}
SendMessageToUser(steamID, "Currently " + Bots.Count + " bots are running");
}
private void ResponseStart(ulong steamID, string botNameToStart) {
if (steamID == 0 || string.IsNullOrEmpty(botNameToStart)) {
return;
}
if (Bots.ContainsKey(botNameToStart)) {
SendMessageToUser(steamID, "That bot instance is already running!");
return;
}
new Bot(botNameToStart);
if (Bots.ContainsKey(botNameToStart)) {
SendMessageToUser(steamID, "Done!");
} else {
SendMessageToUser(steamID, "That bot instance failed to start, make sure that " + botNameToStart + ".xml config exists and bot is active!");
}
}
private async Task ResponseStop(ulong steamID, string botNameToShutdown) {
if (steamID == 0 || string.IsNullOrEmpty(botNameToShutdown)) {
return;
}
if (!Bots.ContainsKey(botNameToShutdown)) {
SendMessageToUser(steamID, "That bot instance is already inactive!");
return;
}
if (await Shutdown(botNameToShutdown).ConfigureAwait(false)) {
SendMessageToUser(steamID, "Done!");
} else {
SendMessageToUser(steamID, "That bot instance failed to shutdown!");
}
}
private void OnConnected(SteamClient.ConnectedCallback callback) {
if (callback == null) {
return;
@@ -183,6 +367,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,
@@ -192,17 +384,21 @@ namespace ArchiSteamFarm {
});
}
private void OnDisconnected(SteamClient.DisconnectedCallback callback) {
private async void OnDisconnected(SteamClient.DisconnectedCallback callback) {
if (callback == null) {
return;
}
if (!IsRunning) {
return;
}
if (SteamClient == null) {
return;
}
Logging.LogGenericWarning(BotName, "Disconnected from Steam, reconnecting...");
Thread.Sleep(TimeSpan.FromMilliseconds(CallbackSleep));
await Program.LimitSteamRequestsAsync().ConfigureAwait(false);
SteamClient.Connect();
}
@@ -219,7 +415,7 @@ namespace ArchiSteamFarm {
SteamID steamID = friend.SteamID;
switch (steamID.AccountType) {
case EAccountType.Clan:
//ArchiHandler.AcceptClanInvite(steamID);
ArchiHandler.DeclineClanInvite(steamID);
break;
default:
if (steamID == SteamMasterID) {
@@ -232,7 +428,7 @@ namespace ArchiSteamFarm {
}
}
private void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
private async void OnFriendMsg(SteamFriends.FriendMsgCallback callback) {
if (callback == null) {
return;
}
@@ -251,8 +447,51 @@ namespace ArchiSteamFarm {
return;
}
if (message.Length == 17 && message[5] == '-' && message[11] == '-') {
if (IsValidCdKey(message)) {
ArchiHandler.RedeemKey(message);
return;
}
if (!message.StartsWith("!")) {
return;
}
if (!message.Contains(" ")) {
switch (message) {
case "!exit":
await ShutdownAllBots().ConfigureAwait(false);
break;
case "!farm":
SendMessageToUser(steamID, "Please wait...");
await CardsFarmer.StartFarming().ConfigureAwait(false);
SendMessageToUser(steamID, "Done!");
break;
case "!restart":
await Program.Restart().ConfigureAwait(false);
break;
case "!status":
ResponseStatus(steamID);
break;
case "!stop":
await Shutdown().ConfigureAwait(false);
break;
}
} else {
string[] args = message.Split(' ');
switch (args[0]) {
case "!redeem":
ArchiHandler.RedeemKey(args[1]);
break;
case "!start":
ResponseStart(steamID, args[1]);
break;
case "!stop":
await ResponseStop(steamID, args[1]).ConfigureAwait(false);
break;
case "!status":
ResponseStatus(steamID, args[1]);
break;
}
}
}
@@ -277,45 +516,54 @@ 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.InvalidPassword:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result + ", will retry after a longer while");
await Stop().ConfigureAwait(false);
await Utilities.SleepAsync(25 * 1000).ConfigureAwait(false); // Steam removes requirement of captcha after around 20 minutes
await Start().ConfigureAwait(false);
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();
Thread.Sleep(5000);
Start();
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result + ", retrying...");
await Stop().ConfigureAwait(false);
await Start().ConfigureAwait(false);
break;
default:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult);
Stop();
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + result);
await Shutdown().ConfigureAwait(false);
break;
}
}
@@ -376,7 +624,8 @@ namespace ArchiSteamFarm {
}
var purchaseResult = callback.PurchaseResult;
SteamFriends.SendChatMessage(SteamMasterID, EChatEntryType.ChatMsg, "Status: " + purchaseResult);
var items = callback.Items;
SendMessageToUser(SteamMasterID, "Status: " + purchaseResult + " | Items: " + string.Join("", items));
if (purchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK) {
await CardsFarmer.StartFarming().ConfigureAwait(false);

View File

@@ -27,28 +27,21 @@ using SteamKit2.Internal;
using System.IO;
namespace ArchiSteamFarm {
/// <summary>
/// Message used to Accept or Decline a group(clan) invite.
/// </summary>
internal sealed class CMsgClientClanInviteAction : ISteamSerializableMessage, ISteamSerializable {
EMsg ISteamSerializableMessage.GetEMsg() {
return EMsg.ClientAcknowledgeClanInvite;
}
public CMsgClientClanInviteAction() {
}
/// <summary>
/// Group invited to.
/// </summary>
internal ulong GroupID = 0;
/// <summary>
/// To accept or decline the invite.
/// </summary>
internal bool AcceptInvite = true;
public CMsgClientClanInviteAction() { }
void ISteamSerializable.Serialize(Stream stream) {
if (stream == null) {
return;
}
try {
BinaryWriter binaryWriter = new BinaryWriter(stream);
binaryWriter.Write(GroupID);
@@ -59,6 +52,10 @@ namespace ArchiSteamFarm {
}
void ISteamSerializable.Deserialize(Stream stream) {
if (stream == null) {
return;
}
try {
BinaryReader binaryReader = new BinaryReader(stream);
GroupID = binaryReader.ReadUInt64();

267
ArchiSteamFarm/CardsFarmer.cs Normal file → Executable file
View File

@@ -23,28 +23,123 @@
*/
using HtmlAgilityPack;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal class CardsFarmer {
internal sealed class CardsFarmer {
private const byte StatusCheckSleep = 5; // In minutes, how long to wait before checking the appID again
private const ushort MaxFarmingTime = 600; // In minutes, how long ASF is allowed to farm one game in solo mode
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);
internal readonly ConcurrentDictionary<uint, double> GamesToFarm = new ConcurrentDictionary<uint, double>();
internal readonly List<uint> CurrentGamesFarming = new List<uint>();
private volatile bool NowFarming = false;
internal CardsFarmer(Bot bot) {
Bot = bot;
}
internal static List<uint> GetGamesToFarmSolo(ConcurrentDictionary<uint, double> gamesToFarm) {
if (gamesToFarm == null) {
return null;
}
List<uint> result = new List<uint>();
foreach (KeyValuePair<uint, double> keyValue in gamesToFarm) {
if (keyValue.Value >= 2) {
result.Add(keyValue.Key);
}
}
return result;
}
internal static uint GetAnyGameToFarm(ConcurrentDictionary<uint, double> gamesToFarm) {
if (gamesToFarm == null) {
return 0;
}
foreach (uint appID in gamesToFarm.Keys) {
return appID;
}
return 0;
}
internal bool FarmMultiple() {
if (GamesToFarm == null || GamesToFarm.Count == 0) {
return true;
}
double maxHour = -1;
foreach (double hour in GamesToFarm.Values) {
if (hour > maxHour) {
maxHour = hour;
}
}
CurrentGamesFarming.Clear();
foreach (uint appID in GamesToFarm.Keys) {
CurrentGamesFarming.Add(appID);
}
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + string.Join(", ", GamesToFarm.Keys));
if (Farm(maxHour, GamesToFarm.Keys)) {
return true;
} else {
CurrentGamesFarming.Clear();
NowFarming = false;
return false;
}
}
internal async Task<bool> FarmSolo(uint appID) {
if (appID == 0) {
return true;
}
CurrentGamesFarming.Clear();
CurrentGamesFarming.Add(appID);
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID);
if (await Farm(appID).ConfigureAwait(false)) {
double hours;
GamesToFarm.TryRemove(appID, out hours);
return true;
} else {
CurrentGamesFarming.Clear();
NowFarming = false;
return false;
}
}
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;
}
@@ -55,7 +150,6 @@ namespace ArchiSteamFarm {
}
// 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);
@@ -71,16 +165,15 @@ namespace ArchiSteamFarm {
continue;
}
GamesToFarm.Clear();
foreach (HtmlNode badgesPageNode in badgesPageNodes) {
string steamLink = badgesPageNode.GetAttributeValue("href", null);
if (steamLink == null) {
Logging.LogGenericWarning(Bot.BotName, "Couldn't get steamLink for one of the games: " + badgesPageNode.OuterHtml);
continue;
}
uint appID = (uint) Utilities.OnlyNumbers(steamLink);
if (appID == 0) {
Logging.LogGenericWarning(Bot.BotName, "Couldn't get appID for one of the games: " + badgesPageNode.OuterHtml);
continue;
}
@@ -88,22 +181,111 @@ namespace ArchiSteamFarm {
continue;
}
appIDs.Add(appID);
// We assume that every game has at least 2 hours played, until we actually check them
GamesToFarm.AddOrUpdate(appID, 2, (key, value) => 2);
}
}
// Start farming
while (appIDs.Count > 0) {
Logging.LogGenericInfo(Bot.BotName, "Farming in progress...");
uint appID = appIDs[0];
if (await Farm(appID).ConfigureAwait(false)) {
appIDs.Remove(appID);
} else {
break;
// If we have restricted card drops, actually do check all games that are left to farm
if (Bot.CardDropsRestricted) {
foreach (uint appID in GamesToFarm.Keys) {
Logging.LogGenericInfo(Bot.BotName, "Checking hours of appID: " + appID);
HtmlDocument appPage = await Bot.ArchiWebHandler.GetGameCardsPage(appID).ConfigureAwait(false);
if (appPage == null) {
continue;
}
HtmlNode appNode = appPage.DocumentNode.SelectSingleNode("//div[@class='badge_title_stats_playtime']");
if (appNode == null) {
continue;
}
string hoursString = appNode.InnerText;
if (string.IsNullOrEmpty(hoursString)) {
continue;
}
hoursString = Regex.Match(hoursString, @"[0-9\.,]+").Value;
double hours;
if (string.IsNullOrEmpty(hoursString)) {
hours = 0;
} else {
hours = double.Parse(hoursString, CultureInfo.InvariantCulture);
}
GamesToFarm[appID] = hours;
}
}
Logging.LogGenericInfo(Bot.BotName, "Farming in progress...");
NowFarming = GamesToFarm.Count > 0;
Semaphore.Release();
// Now the algorithm used for farming depends on whether account is restricted or not
if (Bot.CardDropsRestricted) {
// If we have restricted card drops, we use complex algorithm, which prioritizes farming solo titles >= 2 hours, then all at once, until any game hits mentioned 2 hours
Logging.LogGenericInfo(Bot.BotName, "Chosen farming algorithm: Complex");
while (GamesToFarm.Count > 0) {
List<uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
if (gamesToFarmSolo.Count > 0) {
while (gamesToFarmSolo.Count > 0) {
uint appID = gamesToFarmSolo[0];
bool success = await FarmSolo(appID).ConfigureAwait(false);
if (success) {
Logging.LogGenericInfo(Bot.BotName, "Done farming: " + appID);
gamesToFarmSolo.Remove(appID);
} else {
return;
}
}
} else {
bool success = FarmMultiple();
if (success) {
Logging.LogGenericInfo(Bot.BotName, "Done farming: " + string.Join(", ", GamesToFarm.Keys));
} else {
return;
}
}
}
} else {
// If we have unrestricted card drops, we use simple algorithm and farm cards one-by-one
Logging.LogGenericInfo(Bot.BotName, "Chosen farming algorithm: Simple");
while (GamesToFarm.Count > 0) {
uint appID = GetAnyGameToFarm(GamesToFarm);
bool success = await FarmSolo(appID).ConfigureAwait(false);
if (success) {
Logging.LogGenericInfo(Bot.BotName, "Done farming: " + appID);
} else {
return;
}
}
}
CurrentGamesFarming.Clear();
NowFarming = false;
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...");
await Utilities.SleepAsync(1000).ConfigureAwait(false);
}
FarmResetEvent.Reset();
Logging.LogGenericInfo(Bot.BotName, "Farming stopped!");
Semaphore.Release();
}
private async Task<bool?> ShouldFarm(ulong appID) {
@@ -118,31 +300,56 @@ namespace ArchiSteamFarm {
return result;
}
private async Task<bool> Farm(ulong appID) {
if (NowFarming) {
AutoResetEvent.Set();
Thread.Sleep(1000);
AutoResetEvent.Reset();
}
private async Task<bool> Farm(uint appID) {
Bot.ArchiHandler.PlayGames(appID);
bool success = true;
bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
while (keepFarming == null || keepFarming.Value) {
if (!NowFarming) {
NowFarming = true;
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID);
Bot.PlayGame(appID);
}
if (AutoResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
for (ushort farmingTime = 0; farmingTime <= MaxFarmingTime && (!keepFarming.HasValue || keepFarming.Value); farmingTime += StatusCheckSleep) {
Logging.LogGenericInfo(Bot.BotName, "Still farming: " + appID);
if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
success = false;
break;
}
keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
}
Bot.ArchiHandler.PlayGames(0);
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID);
Bot.PlayGame(0);
NowFarming = false;
return success;
}
private bool Farm(double maxHour, ICollection<uint> appIDs) {
if (maxHour >= 2) {
return true;
}
Bot.ArchiHandler.PlayGames(appIDs);
bool success = true;
while (maxHour < 2) {
Logging.LogGenericInfo(Bot.BotName, "Still farming: " + string.Join(", ", appIDs));
if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
success = false;
break;
}
// Don't forget to update our GamesToFarm hours
double timePlayed = StatusCheckSleep / 60.0;
foreach (KeyValuePair<uint, double> keyValue in GamesToFarm) {
if (!appIDs.Contains(keyValue.Key)) {
continue;
}
GamesToFarm[keyValue.Key] = keyValue.Value + timePlayed;
}
maxHour += timePlayed;
}
Bot.ArchiHandler.PlayGames(0);
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + string.Join(", ", appIDs));
return success;
}
}

View File

@@ -0,0 +1,41 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
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 IsDebugBuild { get; private set; } = false;
internal static bool IsReleaseBuild { get { return !IsDebugBuild; } }
static Debugging() {
MarkIfDebug();
}
[Conditional("DEBUG")]
private static void MarkIfDebug() {
IsDebugBuild = true;
}
}
}

View File

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

View File

@@ -22,64 +22,156 @@
*/
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,
}
private const string LatestGithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases/latest";
internal const ulong ArchiSCFarmGroup = 103582791440160998;
internal const string ConfigDirectoryPath = "config";
private static readonly HashSet<Bot> Bots = new HashSet<Bot>();
private static readonly SemaphoreSlim SteamSemaphore = new SemaphoreSlim(1);
private static readonly ManualResetEvent ShutdownResetEvent = new ManualResetEvent(false);
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private static readonly string ExecutablePath = Assembly.Location;
private static readonly AssemblyName AssemblyName = Assembly.GetName();
//private static readonly string ExeName = AssemblyName.Name + ".exe";
internal static readonly string Version = AssemblyName.Version.ToString();
internal static readonly object ConsoleLock = new object();
internal static void Exit(int exitCode = 0) {
ShutdownAllBots();
private static async Task CheckForUpdate() {
JObject response = await WebBrowser.UrlGetToJObject(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 (comparisonResult < 0) {
Logging.LogGenericNotice("", "New version is available!");
Logging.LogGenericNotice("", "Consider updating yourself!");
await Utilities.SleepAsync(5000).ConfigureAwait(false);
} else if (comparisonResult > 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 async Task Restart() {
await Bot.ShutdownAllBots().ConfigureAwait(false);
System.Diagnostics.Process.Start(ExecutablePath);
Environment.Exit(0);
}
internal static async Task LimitSteamRequestsAsync() {
await SteamSemaphore.WaitAsync().ConfigureAwait(false);
await Utilities.SleepAsync(5 * 1000).ConfigureAwait(false); // We must add some delay to not get caught by Steam anty-DoS
SteamSemaphore.Release();
}
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
}
result = result.Trim(); // Get rid of all whitespace characters
return result;
}
private static void ShutdownAllBots() {
lock (Bots) {
foreach (Bot bot in Bots) {
bot.Stop();
}
Bots.Clear();
internal static async void OnBotShutdown(Bot bot) {
if (Bot.GetRunningBotsCount() == 0) {
Logging.LogGenericInfo("Main", "No bots are running, exiting");
await Utilities.SleepAsync(5000).ConfigureAwait(false); // This might be the only message user gets, consider giving him some time
ShutdownResetEvent.Set();
}
}
private static void InitServices() {
WebBrowser.Init();
}
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);
InitServices();
Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait();
// Allow loading configs from source tree if it's a debug build
if (Debugging.IsDebugBuild) {
for (var i = 0; i < 4; i++) {
Directory.SetCurrentDirectory("..");
if (Directory.Exists(ConfigDirectoryPath)) {
break;
}
}
}
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.8.0.0")]
[assembly: AssemblyFileVersion("0.8.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,41 +28,40 @@ 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;
}
internal void CheckTrades() {
internal async void CheckTrades() {
if (ParsingTasks < 2) {
ParsingTasks++;
Task.Run(() => ParseActiveTrades());
await Semaphore.WaitAsync().ConfigureAwait(false);
await ParseActiveTrades().ConfigureAwait(false);
Semaphore.Release();
ParsingTasks--;
}
}
private async Task ParseActiveTrades() {
await semaphore.WaitAsync().ConfigureAwait(false);
List<SteamTradeOffer> tradeOffers = Bot.ArchiWebHandler.GetTradeOffers();
if (tradeOffers != null) {
List<Task> tasks = new List<Task>();
foreach (SteamTradeOffer tradeOffer in tradeOffers) {
if (tradeOffer.trade_offer_state == SteamTradeOffer.ETradeOfferState.Active) {
Task task = Task.Run(async () => {
await ParseTrade(tradeOffer).ConfigureAwait(false);
});
tasks.Add(task);
}
}
await Task.WhenAll(tasks).ConfigureAwait(false);
if (tradeOffers == null) {
return;
}
ParsingTasks--;
semaphore.Release();
List<Task> tasks = new List<Task>();
foreach (SteamTradeOffer tradeOffer in tradeOffers) {
if (tradeOffer.trade_offer_state == SteamTradeOffer.ETradeOfferState.Active) {
tasks.Add(Task.Run(async () => await ParseTrade(tradeOffer).ConfigureAwait(false)));
}
}
await Task.WhenAll(tasks).ConfigureAwait(false);
}
private async Task ParseTrade(SteamTradeOffer tradeOffer) {
@@ -75,21 +74,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 <accept: " + tradeAccepted + "> to trade " + tradeID + " failed!");
}
if (tradeAccepted && success) {
// Do whatever we want with success
}

View File

@@ -22,18 +22,27 @@
*/
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal static class Utilities {
private static readonly Random Random = new Random();
internal static int RandomNumber(int min, int max) {
return Random.Next(min, max + 1);
}
internal static byte RandomDice() {
return (byte) RandomNumber(1, 6);
}
internal static async Task SleepAsync(int miliseconds) {
await Task.Delay(miliseconds).ConfigureAwait(false);
}
internal static ulong OnlyNumbers(string inputString) {
if (string.IsNullOrEmpty(inputString)) {
return 0;
@@ -48,90 +57,7 @@ namespace ArchiSteamFarm {
return 0;
}
ulong result = ulong.Parse(resultString, CultureInfo.InvariantCulture);
return result;
}
internal static async Task<HttpResponseMessage> UrlToHttpResponse(string websiteAddress, Dictionary<string, string> cookieVariables = 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;
}
}
}
} catch {
}
}
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 {
}
}
return result;
}
internal static async Task<bool> UrlPostRequest(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
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;
}
}
}
} catch {
}
}
return result;
return ulong.Parse(resultString, CultureInfo.InvariantCulture);
}
}
}

View File

@@ -0,0 +1,220 @@
using HtmlAgilityPack;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace ArchiSteamFarm {
internal static class WebBrowser {
internal const byte HttpTimeout = 180; // In seconds
private static readonly HttpClientHandler HttpClientHandler = new HttpClientHandler { UseCookies = false };
private static readonly HttpClient HttpClient = new HttpClient(HttpClientHandler) { Timeout = TimeSpan.FromSeconds(HttpTimeout) };
internal static void Init() {
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("ArchiSteamFarm/" + Program.Version);
}
private static async Task<HttpResponseMessage> UrlRequest(string request, HttpMethod httpMethod, Dictionary<string, string> data = null, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request) || httpMethod == null) {
return null;
}
HttpRequestMessage requestMessage = new HttpRequestMessage(httpMethod, request);
if (httpMethod == HttpMethod.Post && data != null) {
requestMessage.Content = new FormUrlEncodedContent(data);
}
if (cookies != null && cookies.Count > 0) {
StringBuilder cookieHeader = new StringBuilder();
foreach (KeyValuePair<string, string> cookie in cookies) {
cookieHeader.Append(cookie.Key + "=" + cookie.Value + ";");
}
requestMessage.Headers.Add("Cookie", cookieHeader.ToString());
}
if (referer != null) {
requestMessage.Headers.Referrer = new Uri(referer);
}
HttpResponseMessage responseMessage;
try {
responseMessage = await HttpClient.SendAsync(requestMessage).ConfigureAwait(false);
} catch { // Request failed, we don't need to know the exact reason, swallow exception
return null;
}
if (responseMessage == null || !responseMessage.IsSuccessStatusCode) {
return null;
}
if (!responseMessage.IsSuccessStatusCode) {
return null;
}
return responseMessage;
}
internal static async Task<HttpResponseMessage> UrlGet(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
return await UrlRequest(request, HttpMethod.Get, null, cookies, referer).ConfigureAwait(false);
}
internal static async Task<HttpResponseMessage> UrlPost(string request, Dictionary<string, string> postData = null, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
return await UrlRequest(request, HttpMethod.Post, postData, cookies, referer).ConfigureAwait(false);
}
internal static async Task<HtmlDocument> HttpResponseToHtmlDocument(HttpResponseMessage httpResponse) {
if (httpResponse == null || httpResponse.Content == null) {
return null;
}
string content = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
if (string.IsNullOrEmpty(content)) {
return null;
}
content = WebUtility.HtmlDecode(content);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(content);
return htmlDocument;
}
internal static async Task<string> UrlGetToContent(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
HttpResponseMessage responseMessage = await UrlGet(request, cookies, referer).ConfigureAwait(false);
if (responseMessage == null || responseMessage.Content == null) {
return null;
}
return await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
}
internal static async Task<string> UrlPostToContent(string request, Dictionary<string, string> postData = null, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
HttpResponseMessage responseMessage = await UrlPost(request, postData, cookies, referer).ConfigureAwait(false);
if (responseMessage == null || responseMessage.Content == null) {
return null;
}
return await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
}
internal static async Task<string> UrlGetToTitle(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
HtmlDocument htmlDocument = await UrlGetToHtmlDocument(request, cookies, referer).ConfigureAwait(false);
if (htmlDocument == null) {
return null;
}
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//head/title");
if (htmlNode == null) {
return null;
}
return htmlNode.InnerText;
}
internal static async Task<HtmlDocument> UrlGetToHtmlDocument(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
HttpResponseMessage httpResponse = await UrlGet(request, cookies, referer).ConfigureAwait(false);
if (httpResponse == null) {
return null;
}
return await HttpResponseToHtmlDocument(httpResponse).ConfigureAwait(false);
}
internal static async Task<JArray> UrlGetToJArray(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
if (string.IsNullOrEmpty(content)) {
return null;
}
JArray jArray;
try {
jArray = JArray.Parse(content);
} catch (Exception e) {
Logging.LogGenericException("WebBrowser", e);
return null;
}
return jArray;
}
internal static async Task<JObject> UrlGetToJObject(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
if (string.IsNullOrEmpty(content)) {
return null;
}
JObject jObject;
try {
jObject = JObject.Parse(content);
} catch (Exception e) {
Logging.LogGenericException("WebBrowser", e);
return null;
}
return jObject;
}
internal static async Task<XmlDocument> UrlGetToXML(string request, Dictionary<string, string> cookies = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
return null;
}
string content = await UrlGetToContent(request, cookies, referer).ConfigureAwait(false);
if (string.IsNullOrEmpty(content)) {
return null;
}
XmlDocument xmlDocument = new XmlDocument();
try {
xmlDocument.LoadXml(content);
} catch (XmlException e) {
Logging.LogGenericException("WebBrowser", e);
return null;
}
return xmlDocument;
}
}
}

BIN
ArchiSteamFarm/cirno.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

View File

@@ -1,30 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Every bot should have it's own unique .xml configuration file, this is example on which you can base on -->
<!-- Every bot should have it's own unique .xml configuration file, this is example on which you can base on -->
<!-- Notice, if you use special characters reserved for XML, you should escape them -->
<!-- Escape table: [& - &amp;] | [" - &quot;] | [' - &apos;] | [< - &lt;] | [> - &gt;] -->
<!-- So e.g. if your SteamPassword is "foo&" you should write value="foo&amp;" -->
<!-- Master switch to turn account on and off, set to "true" after you're done -->
<Enabled type="bool" value="false"/>
<!-- 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"/>
<!-- 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="null"/>
<!-- This is your steam password, the one you use for logging in to steam -->
<SteamPassword type="string" value="Bar"/>
<!-- 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="null"/>
<!-- This is steam nickname, the one you want to use for bot. Can be anything up to 32 characters -->
<SteamNickname 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 -->
<SteamApiKey type="string" value="null"/>
<!-- 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 steamID of the bot-master - you, in steamID64 format -->
<SteamMasterID type="ulong" value="76561198006963719"/>
<!-- 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"/>
<!-- If you want from the bot to join particular chat of given clan, set it here, otherwise leave at 0 -->
<SteamMasterClanID type="ulong" value="0"/>
<!-- This is steamID64 of the bot-master - you, [Example: 76561198006963719] -->
<!-- TIP: You can use "0", but bot won't accept steam cd-keys or trades from anybody" -->
<SteamMasterID type="ulong" value="0"/>
<!-- Comma-separated list of IDs that should not be considered for farming -->
<Blacklist type="HashSet(uint)" value="368020"/>
<!-- This defines clan of the master, bot will join chatroom of that clan automatically after logging in if set -->
<!-- SteamMasterClanID could be found by visiting your group-page -->
<!-- [Example: http://steamcommunity.com/groups/hellokitty/] -->
<!-- Adding "memberslistxml/?xml=1" to the end of this url so it looks like -->
<!-- [Example: http://steamcommunity.com/groups/hellokitty/memberslistxml/?xml=1] -->
<!-- Finally replace the SteamMasterClanID value with groupID64 you got from your groups xml-file -->
<!-- TIP: Most likely you don't want to change it -->
<SteamMasterClanID type="ulong" value="0"/>
</configuration>
<!-- This switch defines if the account has card drops restricted -->
<!-- Restricted card drops means that the account doesn't receive any steam cards until it plays the game for at least 2 hours -->
<!-- As there is no magical way to detect it by ASF, I made this option config-based switch -->
<!-- TIP: Based on this parameter, ASF will try to choose the most optimized cards farming algorithm for this account -->
<CardDropsRestricted type="bool" value="false"/>
<!-- 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="303700,335590,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-beta3" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
<package id="SteamKit2" version="1.6.5" targetFramework="net45" />
</packages>

View File

@@ -1,26 +1,53 @@
# ArchiSteamFarm
ArchiSteamFarm
===================
Big work-in-progress
ASF is a C# application that allows you to farm steam cards using multiple steam accounts simultaneously. Unlike idle master which works only on one account at given time, requires steam client running in background, and launches additional processes imitiating "game playing" status, ASF doesn't require any steam client running in the background, doesn't launch any additional processes and is made to handle unlimited steam accounts at once. In addition to that, it's meant to be run on servers or other desktop-less machines, and features full Mono support, which makes it possible to launch on any Mono-supported operating system, such as Windows, Linux or OS X. ASF is based on, and possible, thanks to [SteamKit2](https://github.com/SteamRE/SteamKit).
Allows you to farm steam cards using multiple accounts simultaneously.
**Core features:**
Each account is defined by it's own XML config in "config" directory.
- Automatically farm available games using any number of active accounts
- Automatically accept friend requests sent from master
- Automatically accept all trades coming from master
- Automatically accept all steam cd-keys sent via chat from master
- Possibility to choose the most efficient cards farming algorithm, based on given account
- SteamGuard / SteamParental / 2FA support
- Update notifications
- Full Mono support, cross-OS compatibility
Current functions:
- Does not need Steam client running, or even a GUI. Fully based on SteamKit2 and reverse-engineered Steam protocol.
- Automatically farm steam cards using any number of active accounts
- Automatically accept friend requests sent from master
- Automatically accept all trades coming from master
- Automatically accept all steam cd-keys sent via chat from master
- SteamGuard / 2-factor-authentication support
- Full Mono support, tested on Debian "9.0" Stretch (testing)
**Setting up:**
TODO:
- Smart multi-games farming till every game reaches 2 hours, then one-by-one (similar to Idle Master) - Backend code is already here, just missing the logic and tests.
- Possible integration with SteamTradeMatcher, bot can detect dupes and trade them automatically. Again, backend code is already here, just missing actual implementation.
- Automatic sending of steam trades to master, after game is fully farmed.
- Probably much more
Each ASF bot is defined in it's own XML config file in `config` directory. ASF comes with included ```example.xml``` config file, on which you should base all of your bots. Simply copy ```example.xml``` to a new file, and edit properties inside. Don't forget to switch ```Enabled``` property to ```true``` once you're done, as this is the master switch which enables configured bot to launch.
This is big WIP, so feel free to send pull requests if you wish.
ASF expects exclusive access to all steam accounts it's using, which means that you should not use the account which is currently being used by ASF at the same time. You may however ```!start``` and ```!stop``` bots during farming, as well as use config property such as ```ShutdownOnFarmingFinished``` which will automatically release account after farming is done.
I'll release some releases later, when everything is tested and code cleaned up.
After you set up all your bots (their configs), you should launch ```ASF.exe```. If your accounts require additional steps to unlock, such as Steam guard code, you'll need to enter those too after ASF tries to launch given bot. If everything ended properly, you should notice in the console output, as well as on your Steam, that all of your bots automatically started cards farming.
ASF doesn't require and doesn't interfere in any way with Steam client, which means that you can be logged in to Steam client as your primary account with e.g. Idle Master in the background, and launch ASF for all other accounts (your alts) at the same time.
**Current Commands:**
- `!exit` Stops whole ASF
- `!farm` Restarts cards farming module. ASF automatically executes that if any cd-key is successfully claimed
- `!redeem <KEY>` Redeems cd-key on current bot instance. You can also paste cd-key directly to the chat
- `!start <BOT>` Starts given bot instance, after it was ```!stop```pped
- `!status` Prints current status of ASF
- `!stop` Stops current bot instance
- `!stop <BOT>` Stops given bot instance
> Commands can be executed via a private chat with your bot.
> Remember that bot accepts commands only from ```SteamMasterID```. That property can be configured in the config.
**Supported / Tested Operating-Systems:**
- Windows 10 Professional/Enterprise Edition (Native)
- Windows 8.1 Professional (Native)
- Windows 7 Ultimate (Native)
- Debian 9.0 Stretch (Mono)
- Debian 8.1 Jessie (Mono)
- OS X 10.11.1 (Mono)
However, any operating system [listed here](http://www.mono-project.com/docs/about-mono/supported-platforms/) should run ASF flawlessly.
**Need help or more info?**
Head over to our [wiki](https://github.com/JustArchi/ArchiSteamFarm/wiki) then.

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.