Slain some bugs

This commit is contained in:
JustArchi
2015-10-28 20:01:43 +01:00
parent 30ca6ce7ef
commit d30d90a5b0
7 changed files with 70 additions and 15 deletions

8
.gitignore vendored
View File

@@ -1,3 +1,11 @@
#################
## ArchiSteamFarm
#################
# Ignore all config files, apart from example.xml
ArchiSteamFarm/config/*
!ArchiSteamFarm/config/example.xml
################# #################
## Eclipse ## Eclipse
################# #################

View File

@@ -53,7 +53,12 @@ namespace ArchiSteamFarm {
internal ArchiWebHandler(Bot bot, string apiKey) { internal ArchiWebHandler(Bot bot, string apiKey) {
Bot = bot; Bot = bot;
if (!string.IsNullOrEmpty(apiKey) && !apiKey.Equals("null")) {
ApiKey = apiKey; ApiKey = apiKey;
} else {
ApiKey = null;
}
} }
internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL) { internal void Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL) {
@@ -123,6 +128,10 @@ namespace ArchiSteamFarm {
} }
internal List<SteamTradeOffer> GetTradeOffers() { internal List<SteamTradeOffer> GetTradeOffers() {
if (ApiKey == null) {
return null;
}
KeyValue response; KeyValue response;
using (dynamic iEconService = WebAPI.GetInterface("IEconService")) { using (dynamic iEconService = WebAPI.GetInterface("IEconService")) {
// Timeout // Timeout
@@ -212,6 +221,10 @@ namespace ArchiSteamFarm {
} }
internal bool DeclineTradeOffer(ulong tradeID) { internal bool DeclineTradeOffer(ulong tradeID) {
if (ApiKey == null) {
return false;
}
if (tradeID == 0) { if (tradeID == 0) {
return false; return false;
} }

View File

@@ -187,6 +187,9 @@ namespace ArchiSteamFarm {
if (callback == null) { if (callback == null) {
return; return;
} }
if (SteamClient == null) {
return;
}
Logging.LogGenericWarning(BotName, "Disconnected from Steam, reconnecting..."); Logging.LogGenericWarning(BotName, "Disconnected from Steam, reconnecting...");
Thread.Sleep(TimeSpan.FromMilliseconds(CallbackSleep)); Thread.Sleep(TimeSpan.FromMilliseconds(CallbackSleep));
@@ -278,7 +281,12 @@ namespace ArchiSteamFarm {
break; break;
case EResult.OK: case EResult.OK:
Logging.LogGenericInfo(BotName, "Successfully logged on!"); Logging.LogGenericInfo(BotName, "Successfully logged on!");
SteamFriends.SetPersonaName(SteamNickname);
string steamNickname = SteamNickname;
if (!string.IsNullOrEmpty(steamNickname) && !steamNickname.Equals("null")) {
SteamFriends.SetPersonaName(steamNickname);
}
ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL); ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, callback.VanityURL);
ulong clanID = SteamMasterClanID; ulong clanID = SteamMasterClanID;
@@ -288,12 +296,17 @@ namespace ArchiSteamFarm {
await CardsFarmer.StartFarming().ConfigureAwait(false); await CardsFarmer.StartFarming().ConfigureAwait(false);
break; break;
default: case EResult.Timeout:
case EResult.TryAnotherCM:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult + ", retrying..."); Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult + ", retrying...");
Stop(); Stop();
Thread.Sleep(5000); Thread.Sleep(5000);
Start(); Start();
break; break;
default:
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult);
Stop();
break;
} }
} }

View File

@@ -40,6 +40,7 @@ namespace ArchiSteamFarm {
} }
internal async Task StartFarming() { internal async Task StartFarming() {
Logging.LogGenericInfo(Bot.BotName, "Checking badges...");
// Find the number of badge pages // Find the number of badge pages
HtmlDocument badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false); HtmlDocument badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false);
if (badgesDocument == null) { if (badgesDocument == null) {
@@ -64,7 +65,7 @@ namespace ArchiSteamFarm {
HtmlNodeCollection badgesPageNodes = badgesDocument.DocumentNode.SelectNodes("//a[@class='btn_green_white_innerfade btn_small_thin']"); HtmlNodeCollection badgesPageNodes = badgesDocument.DocumentNode.SelectNodes("//a[@class='btn_green_white_innerfade btn_small_thin']");
if (badgesPageNodes == null) { if (badgesPageNodes == null) {
break; continue;
} }
foreach (HtmlNode badgesPageNode in badgesPageNodes) { foreach (HtmlNode badgesPageNode in badgesPageNodes) {
@@ -86,6 +87,7 @@ namespace ArchiSteamFarm {
// Start farming // Start farming
while (appIDs.Count > 0) { while (appIDs.Count > 0) {
Logging.LogGenericInfo(Bot.BotName, "Farming in progress...");
uint appID = appIDs[0]; uint appID = appIDs[0];
if (await Farm(appID).ConfigureAwait(false)) { if (await Farm(appID).ConfigureAwait(false)) {
appIDs.Remove(appID); appIDs.Remove(appID);
@@ -93,6 +95,8 @@ namespace ArchiSteamFarm {
break; break;
} }
} }
Logging.LogGenericInfo(Bot.BotName, "Farming finished!");
} }
private async Task<bool?> ShouldFarm(ulong appID) { private async Task<bool?> ShouldFarm(ulong appID) {
@@ -119,6 +123,7 @@ namespace ArchiSteamFarm {
while (keepFarming == null || keepFarming.Value) { while (keepFarming == null || keepFarming.Value) {
if (!NowFarming) { if (!NowFarming) {
NowFarming = true; NowFarming = true;
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID);
Bot.PlayGame(appID); Bot.PlayGame(appID);
} }
if (AutoResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { if (AutoResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) {
@@ -128,6 +133,7 @@ namespace ArchiSteamFarm {
keepFarming = await ShouldFarm(appID).ConfigureAwait(false); keepFarming = await ShouldFarm(appID).ConfigureAwait(false);
} }
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID);
Bot.PlayGame(0); Bot.PlayGame(0);
NowFarming = false; NowFarming = false;
return success; return success;

View File

@@ -28,8 +28,10 @@ using System.Runtime.CompilerServices;
namespace ArchiSteamFarm { namespace ArchiSteamFarm {
internal static class Logging { internal static class Logging {
private static void Log(string message) { private static void Log(string message) {
lock (Program.ConsoleLock) {
Console.WriteLine(DateTime.Now + " " + message); Console.WriteLine(DateTime.Now + " " + message);
} }
}
internal static void LogGenericError(string botName, string message, [CallerMemberName] string previousMethodName = "") { internal static void LogGenericError(string botName, string message, [CallerMemberName] string previousMethodName = "") {
Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message); Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message);

View File

@@ -39,14 +39,16 @@ namespace ArchiSteamFarm {
} }
internal static string GetSteamGuardCode(string botLogin, bool twoFactorAuthentication) { internal static string GetSteamGuardCode(string botLogin, bool twoFactorAuthentication) {
string result;
lock (ConsoleLock) { lock (ConsoleLock) {
if (twoFactorAuthentication) { if (twoFactorAuthentication) {
Console.Write("<" + botLogin + "> Please enter your 2 factor auth code from your authenticator app: "); Console.Write("<" + botLogin + "> Please enter your 2 factor auth code from your authenticator app: ");
} else { } else {
Console.Write("<" + botLogin + "> Please enter the auth code sent to your email : "); Console.Write("<" + botLogin + "> Please enter the auth code sent to your email : ");
} }
return Console.ReadLine(); result = Console.ReadLine();
} }
return result;
} }
private static void ShutdownAllBots() { private static void ShutdownAllBots() {

View File

@@ -3,14 +3,25 @@
<!-- 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 -->
<Enabled value="true"/> <!-- Master switch to turn account on and off --> <!-- Master switch to turn account on and off, set to "true" after you're done -->
<Enabled type="bool" value="false"/>
<!-- Steam --> <!-- This is your steam login, the one you use for logging in to steam -->
<SteamLogin value="Foo"/> <!-- This is your steam login, the one you use for logging in to steam --> <SteamLogin type="string" value="Foo"/>
<SteamPassword value="Bar"/> <!-- This is your steam password, the one you use for logging in to steam -->
<SteamNickname value="ArchiSteamFarmer"/> <!-- This is your steam nickname, the one you want to use for bot. Can be anything up to 32 characters --> <!-- This is your steam password, the one you use for logging in to steam -->
<SteamApiKey value="FFFFFFFF"/> <!-- Get one at https://steamcommunity.com/dev/apikey --> <SteamPassword type="string" value="Bar"/>
<SteamMasterID value="76561198006963719"/> <!-- This is steamID of the master, aka the "root" user being able to execute any command -->
<SteamMasterClanID value="0"/> <!-- If you want from the bot to join particular chat of given clan, set it here, otherwise leave at 0 --> <!-- This is steam nickname, the one you want to use for bot. Can be anything up to 32 characters -->
<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 steamID of the bot-master - you, in steamID64 format -->
<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 -->
<SteamMasterClanID type="ulong" value="0"/>
</configuration> </configuration>