Skip to content

Commit

Permalink
fix: Fix logOn giving up not being handled
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Oct 20, 2024
1 parent a4b2d72 commit a36198f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/bot.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* File: this.client.js
* File: bot.js
* Project: steam-idler
* Created Date: 2022-10-17 17:32:28
* Author: 3urobeat
*
* Last Modified: 2024-10-19 12:20:34
* Last Modified: 2024-10-20 18:39:11
* Modified By: 3urobeat
*
* Copyright (c) 2022 - 2024 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -216,9 +216,14 @@ Bot.prototype.attachEventListeners = function() {

} else { // Connection loss

if (controller.relogQueue.includes(this.loginindex)) return; // Don't handle this event if account is already waiting for relog
// If error occurred during relog (aka logOn gave up because connection is still down), move account to the back of the queue and call handleRelog again
if (controller.relogQueue.includes(this.loginindex)) {
logger("warn", `[${this.logOnOptions.accountName}] Failed to relog. Repositioning to the back of the queue and trying again. ${err}`);
controller.relogQueue.splice(0, 1);
} else {
logger("info", `[${this.logOnOptions.accountName}] Lost connection to Steam. ${err}. Trying to relog in ${config.relogDelay / 1000} seconds...`);
}

logger("info", `[${this.logOnOptions.accountName}] Lost connection to Steam. ${err}. Trying to relog in ${config.relogDelay / 1000} seconds...`);
this.handleRelog();
}
});
Expand All @@ -233,7 +238,9 @@ Bot.prototype.attachEventListeners = function() {
};


// Handles relogging this bot account
/**
* Handles relogging this bot account
*/
Bot.prototype.handleRelog = function() {
if (controller.relogQueue.includes(this.loginindex)) return; // Don't handle this request if account is already waiting for relog

Expand All @@ -255,8 +262,6 @@ Bot.prototype.handleRelog = function() {

// Attach relogdelay timeout
setTimeout(async () => {
logger("info", `[${this.logOnOptions.accountName}] Logging in...`);

// Generate steamGuardCode with shared secret if one was provided
if (this.logOnOptions.sharedSecret) {
this.logOnOptions.steamGuardCode = SteamTotp.generateAuthCode(this.logOnOptions.sharedSecret);
Expand All @@ -265,6 +270,8 @@ Bot.prototype.handleRelog = function() {
const refreshToken = await this.session.getToken();
if (!refreshToken) return; // Stop execution if getToken aborted login attempt

logger("info", `[${this.logOnOptions.accountName}] Logging in...`);

this.client.logOn({ "refreshToken": refreshToken });
}, config.loginDelay);
}, 1000);
Expand Down

0 comments on commit a36198f

Please sign in to comment.