Misc cleanup

This commit is contained in:
JustArchi
2015-12-12 08:04:41 +01:00
parent d2dff449d1
commit 5353d755a0
2 changed files with 26 additions and 25 deletions

View File

@@ -353,23 +353,24 @@ namespace ArchiSteamFarm {
SteamClient.Disconnect();
}
private async Task<bool> Shutdown(string botNameToShutdown) {
Bot botToShutdown;
if (!Bots.TryGetValue(botNameToShutdown, out botToShutdown)) {
return false;
internal async Task<bool> 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<bool> 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();

View File

@@ -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();
}