diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index d5ee1b6e3..04a93e935 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -229,6 +229,30 @@ namespace ArchiSteamFarm { } } + internal static void InitBots() { + if (Bot.Bots.Count != 0) { + return; + } + + // Before attempting to connect, initialize our list of CMs + Bot.InitializeCMs(Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider); + + foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension)) { + switch (botName) { + case SharedInfo.ASF: + case "example": + case "minimal": + continue; + } + + new Bot(botName).Forget(); + } + + if (Bot.Bots.Count == 0) { + ArchiLogger.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); + } + } + internal static void InitFileWatcher() { if (FileSystemWatcher != null) { return; diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 58b2384f5..7d8124eca 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -230,6 +230,7 @@ namespace ArchiSteamFarm { case "--server": Mode |= EMode.Server; WCF.StartServer(); + ASF.InitBots(); break; default: if (arg.StartsWith("--", StringComparison.Ordinal)) { @@ -334,33 +335,8 @@ namespace ArchiSteamFarm { Exit(); } - // From now on it's server mode - if (!Directory.Exists(SharedInfo.ConfigDirectory)) { - ASF.ArchiLogger.LogGenericError("Config directory doesn't exist!"); - Thread.Sleep(5000); - Exit(1); - } - ASF.CheckForUpdate().Wait(); - - // Before attempting to connect, initialize our list of CMs - Bot.InitializeCMs(GlobalDatabase.CellID, GlobalDatabase.ServerListProvider); - - foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension)) { - switch (botName) { - case SharedInfo.ASF: - case "example": - case "minimal": - continue; - } - - new Bot(botName).Forget(); - } - - if (Bot.Bots.Count == 0) { - ASF.ArchiLogger.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); - } - + ASF.InitBots(); ASF.InitFileWatcher(); } diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index 191ee90f9..d1437f3b7 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -87,7 +87,7 @@ namespace ArchiSteamFarm { } internal void StartServer() { - if (ServiceHost != null) { + if (IsServerRunning) { return; } @@ -113,7 +113,7 @@ namespace ArchiSteamFarm { } internal void StopServer() { - if (ServiceHost == null) { + if (!IsServerRunning) { return; }