From 5353d755a04825b96ac11e147cc8d1e24a87e60b Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sat, 12 Dec 2015 08:04:41 +0100 Subject: [PATCH] Misc cleanup --- ArchiSteamFarm/Bot.cs | 47 ++++++++++++++++++++------------------- ArchiSteamFarm/Program.cs | 4 ++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 7dbfeef5d..b70513ada 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -353,23 +353,24 @@ namespace ArchiSteamFarm { SteamClient.Disconnect(); } - private async Task Shutdown(string botNameToShutdown) { - Bot botToShutdown; - if (!Bots.TryGetValue(botNameToShutdown, out botToShutdown)) { - return false; + internal async Task Shutdown(string botName = null) { + Bot bot; + + if (string.IsNullOrEmpty(botName)) { + bot = this; + } else { + if (!Bots.TryGetValue(botName, out bot)) { + return false; + } } - await botToShutdown.Stop().ConfigureAwait(false); - Bots.TryRemove(botNameToShutdown, out botToShutdown); + await bot.Stop().ConfigureAwait(false); + Bots.TryRemove(botName, out bot); - Program.OnBotShutdown(botToShutdown); + Program.OnBotShutdown(); return true; } - internal async Task Shutdown() { - return await Shutdown(BotName).ConfigureAwait(false); - } - internal async Task OnFarmingFinished() { if (ShutdownOnFarmingFinished) { await Shutdown().ConfigureAwait(false); @@ -467,35 +468,35 @@ namespace ArchiSteamFarm { } } - private void ResponseStart(ulong steamID, string botNameToStart) { - if (steamID == 0 || string.IsNullOrEmpty(botNameToStart)) { + private void ResponseStart(ulong steamID, string botName) { + if (steamID == 0 || string.IsNullOrEmpty(botName)) { return; } - if (Bots.ContainsKey(botNameToStart)) { + if (Bots.ContainsKey(botName)) { SendMessageToUser(steamID, "That bot instance is already running!"); return; } - new Bot(botNameToStart); - if (Bots.ContainsKey(botNameToStart)) { + new Bot(botName); + if (Bots.ContainsKey(botName)) { SendMessageToUser(steamID, "Done!"); } else { - SendMessageToUser(steamID, "That bot instance failed to start, make sure that " + botNameToStart + ".xml config exists and bot is active!"); + SendMessageToUser(steamID, "That bot instance failed to start, make sure that XML config exists and bot is active!"); } } - private async Task ResponseStop(ulong steamID, string botNameToShutdown) { - if (steamID == 0 || string.IsNullOrEmpty(botNameToShutdown)) { + private async Task ResponseStop(ulong steamID, string botName) { + if (steamID == 0 || string.IsNullOrEmpty(botName)) { return; } - if (!Bots.ContainsKey(botNameToShutdown)) { + if (!Bots.ContainsKey(botName)) { SendMessageToUser(steamID, "That bot instance is already inactive!"); return; } - if (await Shutdown(botNameToShutdown).ConfigureAwait(false)) { + if (await Shutdown(botName).ConfigureAwait(false)) { SendMessageToUser(steamID, "Done!"); } else { SendMessageToUser(steamID, "That bot instance failed to shutdown!"); @@ -572,8 +573,8 @@ namespace ArchiSteamFarm { if (LoggedInElsewhere) { LoggedInElsewhere = false; - Logging.LogGenericWarning(BotName, "Account is being used elsewhere, will try reconnecting in 15 minutes..."); - await Utilities.SleepAsync(15 * 60 * 1000).ConfigureAwait(false); + Logging.LogGenericWarning(BotName, "Account is being used elsewhere, will try reconnecting in 5 minutes..."); + await Utilities.SleepAsync(5 * 60 * 1000).ConfigureAwait(false); } SteamClient.Connect(); diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index a7b28fd3a..e9cd5ef1a 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -138,7 +138,7 @@ namespace ArchiSteamFarm { return result.Trim(); // Get rid of all whitespace characters } - internal static async void OnBotShutdown(Bot bot) { + internal static async void OnBotShutdown() { if (Bot.GetRunningBotsCount() == 0) { Logging.LogGenericInfo("Main", "No bots are running, exiting"); await Utilities.SleepAsync(5000).ConfigureAwait(false); // This might be the only message user gets, consider giving him some time @@ -182,7 +182,7 @@ namespace ArchiSteamFarm { } // Check if we got any bots running - OnBotShutdown(null); + OnBotShutdown(); ShutdownResetEvent.WaitOne(); }