Skip to content

Commit

Permalink
Add some delay for LoggedInElsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 9, 2015
1 parent 6c903b2 commit a90b3af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal sealed class Bot {

internal readonly string BotName;

private bool LoggedInElsewhere = false;
private bool IsRunning = false;
private string AuthCode, TwoFactorAuth;

Expand Down Expand Up @@ -402,13 +403,21 @@ 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
if (TwoFactorAuth == null) {
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();
}

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions ArchiSteamFarm/Trading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit a90b3af

Please sign in to comment.