From 76bdd898e120785d6006aeafbb41d1d7d1be09b1 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 21 Dec 2015 09:28:59 +0100 Subject: [PATCH] Add extra logging --- ArchiSteamFarm/Bot.cs | 35 ++++++++++++++++++++++------------- ArchiSteamFarm/CardsFarmer.cs | 19 +++++++++++++++---- ArchiSteamFarm/Logging.cs | 7 +------ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 419e25d57..51d760a9b 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -105,7 +105,9 @@ namespace ArchiSteamFarm { } internal Bot(string botName) { + Logging.LogGenericDebug(botName, "Created new bot object: " + ToString()); if (Bots.ContainsKey(botName)) { + Logging.LogGenericDebug(botName, "But that name is already in use, so returning!"); return; } @@ -338,12 +340,12 @@ namespace ArchiSteamFarm { } internal async Task Start() { + Logging.LogGenericDebug(BotName, "Got signal to start!"); if (IsRunning) { + Logging.LogGenericDebug(BotName, "But it's started already, so returning"); return; } - IsRunning = true; - Logging.LogGenericInfo(BotName, "Starting..."); // 2FA tokens are expiring soon, use limiter only when we don't have any pending @@ -351,18 +353,25 @@ namespace ArchiSteamFarm { await Program.LimitSteamRequestsAsync().ConfigureAwait(false); } + IsRunning = true; + Logging.LogGenericDebug(BotName, "Connecting steam client!"); SteamClient.Connect(); + Logging.LogGenericDebug(BotName, "Turned on callback handle!"); var fireAndForget = Task.Run(() => HandleCallbacks()); } internal async Task Stop() { + Logging.LogGenericDebug(BotName, "Got signal to stop"); if (!IsRunning) { + Logging.LogGenericDebug(BotName, "But it's stopped already, so returning"); return; } + Logging.LogGenericDebug(BotName, "Stopping CF module..."); await CardsFarmer.StopFarming().ConfigureAwait(false); IsRunning = false; + Logging.LogGenericDebug(BotName, "Disconnecting steam client!"); SteamClient.Disconnect(); } @@ -391,10 +400,12 @@ namespace ArchiSteamFarm { } private void HandleCallbacks() { + Logging.LogGenericDebug(BotName, "Started Loop"); TimeSpan timeSpan = TimeSpan.FromMilliseconds(CallbackSleep); while (IsRunning) { CallbackManager.RunWaitCallbacks(timeSpan); } + Logging.LogGenericDebug(BotName, "Stopped Loop"); } private void SendMessageToUser(ulong steamID, string message) { @@ -571,21 +582,21 @@ namespace ArchiSteamFarm { return; } + Logging.LogGenericInfo(BotName, "Disconnected from Steam, reconnecting..."); + await CardsFarmer.StopFarming().ConfigureAwait(false); - Logging.LogGenericWarning(BotName, "Disconnected from Steam, reconnecting..."); - - // 2FA tokens are expiring soon, use limiter only when we don't have any pending - if (TwoFactorAuth == null) { - await Program.LimitSteamRequestsAsync().ConfigureAwait(false); - } - if (LoggedInElsewhere) { LoggedInElsewhere = false; Logging.LogGenericWarning(BotName, "Account is being used elsewhere, will try reconnecting in 5 minutes..."); await Utilities.SleepAsync(5 * 60 * 1000).ConfigureAwait(false); } + // 2FA tokens are expiring soon, use limiter only when we don't have any pending + if (TwoFactorAuth == null) { + await Program.LimitSteamRequestsAsync().ConfigureAwait(false); + } + SteamClient.Connect(); } @@ -641,6 +652,8 @@ namespace ArchiSteamFarm { return; } + Logging.LogGenericDebug(BotName, "Got command: " + message); + if (!message.Contains(" ")) { switch (message) { case "!2fa": @@ -815,8 +828,6 @@ namespace ArchiSteamFarm { return; } - Logging.LogGenericInfo(BotName, "Updating sentryfile..."); - int fileSize; byte[] sentryHash; @@ -844,8 +855,6 @@ namespace ArchiSteamFarm { OneTimePassword = callback.OneTimePassword, SentryFileHash = sentryHash, }); - - Logging.LogGenericInfo(BotName, "Sentryfile updated successfully!"); } private void OnNotification(ArchiHandler.NotificationCallback callback) { diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 53a60e341..6a5a62b80 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -134,11 +134,15 @@ namespace ArchiSteamFarm { } internal async Task StartFarming() { + Logging.LogGenericDebug(Bot.BotName, "Got signal to start farming, calling StopFarming firstly"); await StopFarming().ConfigureAwait(false); + Logging.LogGenericDebug(Bot.BotName, "StopFarming done, waiting for semaphore now..."); await Semaphore.WaitAsync().ConfigureAwait(false); + Logging.LogGenericDebug(Bot.BotName, "Got it!"); if (NowFarming) { + Logging.LogGenericDebug(Bot.BotName, "But for some reason farming is already active, probably called in a meantime, so returning!"); Semaphore.Release(); return; } @@ -146,6 +150,7 @@ namespace ArchiSteamFarm { // Check if farming is possible Logging.LogGenericInfo(Bot.BotName, "Checking possibility to farm..."); NowFarming = true; + Logging.LogGenericDebug(Bot.BotName, "Releasing semaphore while waiting!"); Semaphore.Release(); Bot.ArchiHandler.PlayGames(1337); @@ -155,10 +160,11 @@ namespace ArchiSteamFarm { return; } - NowFarming = false; Logging.LogGenericInfo(Bot.BotName, "Farming is possible!"); + Logging.LogGenericDebug(Bot.BotName, "Waiting for semaphore..."); await Semaphore.WaitAsync().ConfigureAwait(false); + Logging.LogGenericDebug(Bot.BotName, "Got it!"); if (await Bot.ArchiWebHandler.ReconnectIfNeeded().ConfigureAwait(false)) { Semaphore.Release(); @@ -302,13 +308,16 @@ namespace ArchiSteamFarm { } internal async Task StopFarming() { - await Semaphore.WaitAsync().ConfigureAwait(false); - + Logging.LogGenericDebug(Bot.BotName, "Got signal to stop farming"); if (!NowFarming) { - Semaphore.Release(); + Logging.LogGenericDebug(Bot.BotName, "Farming is already stopped, so returning"); return; } + Logging.LogGenericDebug(Bot.BotName, "Waiting for semaphore"); + await Semaphore.WaitAsync().ConfigureAwait(false); + Logging.LogGenericDebug(Bot.BotName, "Got it!"); + Logging.LogGenericInfo(Bot.BotName, "Sending signal to stop farming"); FarmResetEvent.Set(); for (var i = 0; i < 5 && NowFarming; i++) { @@ -317,6 +326,7 @@ namespace ArchiSteamFarm { } FarmResetEvent.Reset(); Logging.LogGenericInfo(Bot.BotName, "Farming stopped!"); + Logging.LogGenericDebug(Bot.BotName, "Releasing semaphore..."); Semaphore.Release(); } @@ -325,6 +335,7 @@ namespace ArchiSteamFarm { return; } + Logging.LogGenericDebug(Bot.BotName, "START!"); await StartFarming().ConfigureAwait(false); } diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 6e33168d8..87cb0e597 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -56,14 +56,9 @@ namespace ArchiSteamFarm { Log("[*] NOTICE: " + previousMethodName + "() <" + botName + "> " + message); } - [Conditional("DEBUG")] + //[Conditional("DEBUG")] internal static void LogGenericDebug(string botName, string message, [CallerMemberName] string previousMethodName = "") { Log("[#] DEBUG: " + previousMethodName + "() <" + botName + "> " + message); } - - [Conditional("DEBUG")] - internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") { - LogGenericDebug("DEBUG", message, previousMethodName); - } } }