From a90b3afcdd1fe2343cf187ff8eb1db8d98b88eee Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 9 Dec 2015 20:55:43 +0100 Subject: [PATCH] Add some delay for LoggedInElsewhere --- ArchiSteamFarm/Bot.cs | 17 +++++++++++++++++ ArchiSteamFarm/Trading.cs | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 8841cc0089c74..27b97b05b1d14 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -41,6 +41,7 @@ internal sealed class Bot { internal readonly string BotName; + private bool LoggedInElsewhere = false; private bool IsRunning = false; private string AuthCode, TwoFactorAuth; @@ -402,6 +403,8 @@ private async void OnDisconnected(SteamClient.DisconnectedCallback callback) { return; } + 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 @@ -409,6 +412,12 @@ private async void OnDisconnected(SteamClient.DisconnectedCallback callback) { await Program.LimitSteamRequestsAsync().ConfigureAwait(false); } + 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); + } + SteamClient.Connect(); } @@ -519,6 +528,14 @@ private void OnLoggedOff(SteamUser.LoggedOffCallback callback) { } Logging.LogGenericInfo(BotName, "Logged off of Steam: " + callback.Result); + + switch (callback.Result) { + case EResult.AlreadyLoggedInElsewhere: + case EResult.LoggedInElsewhere: + case EResult.LogonSessionReplaced: + LoggedInElsewhere = true; + break; + } } private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) { diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 8b469bf1b7347..92cb1a8a64328 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -74,14 +74,15 @@ private async Task ParseTrade(SteamTradeOffer tradeOffer) { return; } - ulong otherSteamID = tradeOffer.OtherSteamID64; - bool success = false; - bool tradeAccepted = false; + bool success, tradeAccepted; - if (tradeOffer.items_to_give.Count == 0 || otherSteamID == Bot.SteamMasterID) { + if (tradeOffer.items_to_give.Count == 0 || tradeOffer.OtherSteamID64 == Bot.SteamMasterID) { tradeAccepted = true; + Logging.LogGenericInfo(Bot.BotName, "Accepting trade: " + tradeID); success = await Bot.ArchiWebHandler.AcceptTradeOffer(tradeID).ConfigureAwait(false); } else { + tradeAccepted = false; + Logging.LogGenericInfo(Bot.BotName, "Rejecting trade: " + tradeID); success = Bot.ArchiWebHandler.DeclineTradeOffer(tradeID); }