diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 947c7562b..556e3e2f0 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -452,7 +452,9 @@ namespace ArchiSteamFarm { // But here we're dealing with WinAuth authenticator Logging.LogGenericInfo("ASF requires a few more steps to complete authenticator import...", BotName); - InitializeLoginAndPassword(); + if (!InitializeLoginAndPassword()) { + return; + } UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword); LoginResult loginResult; @@ -460,6 +462,9 @@ namespace ArchiSteamFarm { switch (loginResult) { case LoginResult.Need2FA: userLogin.TwoFactorCode = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName); + if (string.IsNullOrEmpty(userLogin.TwoFactorCode)) { + return; + } break; default: Logging.LogGenericError("Unhandled situation: " + loginResult, BotName); @@ -1143,7 +1148,9 @@ namespace ArchiSteamFarm { Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName); - InitializeLoginAndPassword(); + if (!InitializeLoginAndPassword()) { + return; + } UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword); LoginResult loginResult; @@ -1151,6 +1158,9 @@ namespace ArchiSteamFarm { switch (loginResult) { case LoginResult.NeedEmail: userLogin.EmailCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName); + if (string.IsNullOrEmpty(userLogin.EmailCode)) { + return; + } break; default: Logging.LogGenericError("Unhandled situation: " + loginResult, BotName); @@ -1165,6 +1175,9 @@ namespace ArchiSteamFarm { switch (linkResult) { case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber: authenticatorLinker.PhoneNumber = Program.GetUserInput(Program.EUserInputType.PhoneNumber, BotName); + if (string.IsNullOrEmpty(authenticatorLinker.PhoneNumber)) { + return; + } break; default: Logging.LogGenericError("Unhandled situation: " + linkResult, BotName); @@ -1174,7 +1187,12 @@ namespace ArchiSteamFarm { BotDatabase.SteamGuardAccount = authenticatorLinker.LinkedAccount; - AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(Program.GetUserInput(Program.EUserInputType.SMS, BotName)); + string sms = Program.GetUserInput(Program.EUserInputType.SMS, BotName); + if (string.IsNullOrEmpty(sms)) { + return; + } + + AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(sms); if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) { Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName); DelinkMobileAuthenticator(); @@ -1210,14 +1228,22 @@ namespace ArchiSteamFarm { SteamFriends.JoinChat(BotConfig.SteamMasterClanID); } - private void InitializeLoginAndPassword() { + private bool InitializeLoginAndPassword() { if (string.IsNullOrEmpty(BotConfig.SteamLogin)) { BotConfig.SteamLogin = Program.GetUserInput(Program.EUserInputType.Login, BotName); + if (string.IsNullOrEmpty(BotConfig.SteamLogin)) { + return false; + } } if (string.IsNullOrEmpty(BotConfig.SteamPassword) && string.IsNullOrEmpty(BotDatabase.LoginKey)) { BotConfig.SteamPassword = Program.GetUserInput(Program.EUserInputType.Password, BotName); + if (string.IsNullOrEmpty(BotConfig.SteamPassword)) { + return false; + } } + + return true; } private void OnConnected(SteamClient.ConnectedCallback callback) { @@ -1248,7 +1274,10 @@ namespace ArchiSteamFarm { } } - InitializeLoginAndPassword(); + if (!InitializeLoginAndPassword()) { + Stop(); + return; + } Logging.LogGenericInfo("Logging in...", BotName); @@ -1476,10 +1505,18 @@ namespace ArchiSteamFarm { switch (callback.Result) { case EResult.AccountLogonDenied: AuthCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName); + if (string.IsNullOrEmpty(AuthCode)) { + Stop(); + return; + } break; case EResult.AccountLoginDeniedNeedTwoFactor: if (BotDatabase.SteamGuardAccount == null) { TwoFactorAuth = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName); + if (string.IsNullOrEmpty(TwoFactorAuth)) { + Stop(); + return; + } } else { TwoFactorAuth = BotDatabase.SteamGuardAccount.GenerateSteamGuardCode(); } @@ -1512,6 +1549,10 @@ namespace ArchiSteamFarm { if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) { BotConfig.SteamParentalPIN = Program.GetUserInput(Program.EUserInputType.SteamParentalPIN, BotName); + if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) { + Stop(); + return; + } } if (!ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN)) { diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index d8c3f5577..2a1f5c2f1 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -49,6 +49,9 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal bool Debug { get; private set; } = false; + [JsonProperty(Required = Required.DisallowNull)] + internal bool Headless { get; private set; } = false; + [JsonProperty(Required = Required.DisallowNull)] internal bool AutoUpdates { get; private set; } = true; diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 58156ee9c..6cf3ff94e 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -274,6 +274,11 @@ namespace ArchiSteamFarm { return null; } + if (GlobalConfig.Headless) { + Logging.LogGenericWarning("Received a request for user input, but process is running in headless mode!"); + return null; + } + string result; lock (ConsoleLock) { ConsoleIsBusy = true; diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index 0d856caec..07a3f3c23 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -44,6 +44,9 @@ namespace ArchiSteamFarm { internal static void Init() { if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) { Program.GlobalConfig.WCFHostname = Program.GetUserInput(Program.EUserInputType.WCFHostname); + if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) { + return; + } } URL = "http://" + Program.GlobalConfig.WCFHostname + ":" + Program.GlobalConfig.WCFPort + "/ASF"; diff --git a/ArchiSteamFarm/config/ASF.json b/ArchiSteamFarm/config/ASF.json index 5f4251bac..047208413 100644 --- a/ArchiSteamFarm/config/ASF.json +++ b/ArchiSteamFarm/config/ASF.json @@ -1,5 +1,6 @@ { "Debug": false, + "Headless": false, "AutoUpdates": true, "UpdateChannel": 1, "SteamProtocol": 6, diff --git a/ConfigGenerator/GlobalConfig.cs b/ConfigGenerator/GlobalConfig.cs index 0f008c1ce..f15caec7b 100644 --- a/ConfigGenerator/GlobalConfig.cs +++ b/ConfigGenerator/GlobalConfig.cs @@ -48,6 +48,9 @@ namespace ConfigGenerator { [JsonProperty(Required = Required.DisallowNull)] public bool Debug { get; set; } = false; + [JsonProperty(Required = Required.DisallowNull)] + public bool Headless { get; set; } = false; + [JsonProperty(Required = Required.DisallowNull)] public bool AutoUpdates { get; set; } = true;