diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index 61fe12ccd..389b0c152 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -221,7 +221,7 @@ namespace ArchiSteamFarm { continue; } - new Bot(botName).Forget(); + Bot.RegisterBot(botName); } if (Bot.Bots.Count == 0) { @@ -263,7 +263,7 @@ namespace ArchiSteamFarm { return; } - new Bot(botName).Forget(); + Bot.RegisterBot(botName); } private static async void OnChanged(object sender, FileSystemEventArgs e) { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index e185353d8..f3020576a 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -122,7 +122,7 @@ namespace ArchiSteamFarm { private string TwoFactorCode; private byte TwoFactorCodeFailures; - internal Bot(string botName) { + private Bot(string botName) { if (string.IsNullOrEmpty(botName)) { throw new ArgumentNullException(nameof(botName)); } @@ -225,8 +225,6 @@ namespace ArchiSteamFarm { TimeSpan.FromMinutes(1) + TimeSpan.FromMinutes(0.2 * Bots.Count), // Delay TimeSpan.FromMinutes(1) // Period ); - - InitStart().Forget(); } public void Dispose() { @@ -583,6 +581,24 @@ namespace ArchiSteamFarm { return false; } + internal static void RegisterBot(string botName) { + if (string.IsNullOrEmpty(botName)) { + ASF.ArchiLogger.LogNullError(nameof(botName)); + return; + } + + Bot bot; + + try { + bot = new Bot(botName); + } catch (ArgumentException e) { + ASF.ArchiLogger.LogGenericException(e); + return; + } + + bot.InitStart().Forget(); + } + internal void RequestPersonaStateUpdate() { if (!IsConnectedAndLoggedOn) { return; @@ -1119,7 +1135,7 @@ namespace ArchiSteamFarm { ArchiLogger.LogGenericError(Strings.BotHeartBeatFailed); Destroy(true); - new Bot(BotName).Forget(); + RegisterBot(BotName); } private async Task InitStart() {