Internal improvements

This commit is contained in:
JustArchi
2015-12-16 01:17:54 +01:00
parent 83934af041
commit b17960096e
4 changed files with 54 additions and 15 deletions

View File

@@ -45,6 +45,7 @@ namespace ArchiSteamFarm {
private bool LoggedInElsewhere = false;
private bool IsRunning = false;
private bool IsBeingUsedAsPrimaryAccount = false;
private string AuthCode, LoginKey, TwoFactorAuth;
internal ArchiHandler ArchiHandler { get; private set; }
@@ -541,16 +542,28 @@ namespace ArchiSteamFarm {
SteamPassword = Program.GetUserInput(BotName, Program.EUserInputType.Password);
}
// TODO: We should use SteamUser.LogOn with proper LoginID once https://github.com/SteamRE/SteamKit/pull/217 gets merged
ArchiHandler.HackedLogOn(0xBAADF00D, new SteamUser.LogOnDetails {
Username = SteamLogin,
Password = SteamPassword,
AuthCode = AuthCode,
LoginKey = LoginKey,
TwoFactorCode = TwoFactorAuth,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
if (!IsBeingUsedAsPrimaryAccount) {
SteamUser.LogOn(new SteamUser.LogOnDetails {
Username = SteamLogin,
Password = SteamPassword,
AuthCode = AuthCode,
LoginKey = LoginKey,
TwoFactorCode = TwoFactorAuth,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
} else {
// TODO: We should use SteamUser.LogOn with proper LoginID once https://github.com/SteamRE/SteamKit/pull/217 gets merged
ArchiHandler.HackedLogOn(0xBAADF00D, new SteamUser.LogOnDetails {
Username = SteamLogin,
Password = SteamPassword,
AuthCode = AuthCode,
LoginKey = LoginKey,
TwoFactorCode = TwoFactorAuth,
SentryFileHash = sentryHash,
ShouldRememberPassword = true
});
}
}
private async void OnDisconnected(SteamClient.DisconnectedCallback callback) {
@@ -705,9 +718,12 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo(BotName, "Logged off of Steam: " + callback.Result);
switch (callback.Result) {
case EResult.LogonSessionReplaced:
Logging.LogGenericInfo(BotName, "This is primary account, changing logic alt -> main");
IsBeingUsedAsPrimaryAccount = true;
break;
case EResult.AlreadyLoggedInElsewhere:
case EResult.LoggedInElsewhere:
case EResult.LogonSessionReplaced:
LoggedInElsewhere = true;
break;
}

View File

@@ -143,6 +143,22 @@ namespace ArchiSteamFarm {
return;
}
// Check if farming is possible
Logging.LogGenericInfo(Bot.BotName, "Checking possibility to farm...");
NowFarming = true;
Semaphore.Release();
Bot.ArchiHandler.PlayGames(1337);
// We'll now either receive OnLoggedOff() with LoggedInElsewhere, or nothing happens
if (await Task.Run(() => FarmResetEvent.WaitOne(5000)).ConfigureAwait(false)) { // If LoggedInElsewhere happens in 5 seconds from now, abort farming
NowFarming = false;
return;
}
Logging.LogGenericInfo(Bot.BotName, "Farming is possible!");
await Semaphore.WaitAsync().ConfigureAwait(false);
Logging.LogGenericInfo(Bot.BotName, "Checking badges...");
// Find the number of badge pages
@@ -299,7 +315,7 @@ namespace ArchiSteamFarm {
}
private async Task CheckGamesForFarming() {
if (NowFarming || CurrentGamesFarming.Count > 0 || GamesToFarm.Count > 0) {
if (NowFarming || GamesToFarm.Count > 0) {
return;
}

View File

@@ -29,9 +29,11 @@ using System.Runtime.CompilerServices;
namespace ArchiSteamFarm {
internal static class Logging {
private static void Log(string message) {
lock (Program.ConsoleLock) {
Console.WriteLine(DateTime.Now + " " + message);
if (Program.ConsoleIsBusy) {
return;
}
Console.WriteLine(DateTime.Now + " " + message);
}
internal static void LogGenericError(string botName, string message, [CallerMemberName] string previousMethodName = "") {

View File

@@ -52,10 +52,12 @@ namespace ArchiSteamFarm {
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private static readonly string ExecutablePath = Assembly.Location;
private static readonly AssemblyName AssemblyName = Assembly.GetName();
private static readonly object ConsoleLock = new object();
//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 bool ConsoleIsBusy = false;
private static async Task CheckForUpdate() {
JObject response = await WebBrowser.UrlGetToJObject(LatestGithubReleaseURL).ConfigureAwait(false);
@@ -104,6 +106,7 @@ namespace ArchiSteamFarm {
internal static string GetUserInput(string botLogin, EUserInputType userInputType, string extraInformation = null) {
string result;
lock (ConsoleLock) {
ConsoleIsBusy = true;
switch (userInputType) {
case EUserInputType.Login:
Console.Write("<" + botLogin + "> Please enter your login: ");
@@ -134,7 +137,9 @@ namespace ArchiSteamFarm {
}
result = Console.ReadLine();
Console.Clear(); // For security purposes
ConsoleIsBusy = false;
}
return result.Trim(); // Get rid of all whitespace characters
}