Skip to content

Commit

Permalink
feat(Bot): Potentially finally fix Already logged on errors when relo…
Browse files Browse the repository at this point in the history
…gging for good
  • Loading branch information
3urobeat committed May 4, 2024
1 parent 80551c6 commit 75d5766
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
38 changes: 31 additions & 7 deletions src/bot/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2021-07-09 16:26:00
* Author: 3urobeat
*
* Last Modified: 2024-05-03 12:46:26
* Last Modified: 2024-05-04 15:27:37
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -192,10 +192,37 @@ Bot.prototype._loginToSteam = async function() {
// Count this attempt
this.loginData.logOnTries++;

// Always call logOff() before logOn() like an idiot to prevent "Already attempting to log on, cannot log on again" errors
this.user.logOff();
const currentLogOnTry = this.loginData.logOnTries;

if (this.sessionHandler.session) this.sessionHandler.session.cancelLoginAttempt(); // TODO: This might cause an error as idk if we are polling. Maybe use the timeout event of steam-session

// Attach loginTimeout handler
this.handleLoginTimeout();


// If logged in, wait for account to be logged off before continuing. This prevents "Already logged in, ..." & "Already attempting to log on, ..." errors
if (this.user.steamID || this.user._connecting) { // https://github.com/DoctorMcKay/node-steam-user/blob/cb8e098969c10555fe41dd9487be140c79006c41/components/09-logon.js#L51
await (async () => {
return new Promise((resolve) => {

this.user.logOff();
if (this.sessionHandler.session) this.sessionHandler.session.cancelLoginAttempt(); // TODO: This might cause an error as idk if we are polling. Maybe use the timeout event of steam-session

let logOffInterval = setInterval(() => {
logger("warn", `[${this.logPrefix}] Login requested but account seems to be logged in! Attempting log off before continuing...`, true, true); // Cannot log with date to prevent log output file spam

// Resolve when logged off or when logOnTries has changed (handleLoginTimeout has probably taken action)
if ((!this.user.steamID && !this.user._connecting) || currentLogOnTry != this.loginData.logOnTries) {
clearInterval(logOffInterval);
resolve();
}
}, 250);

});
})();
}

// Cancel if not on the same logOnTries value anymore (handleLoginTimeout has probably taken action)
if (currentLogOnTry != this.loginData.logOnTries) return logger("debug", `[${this.logPrefix}] Aborting login because _loginToSteam() was called again from somewhere else. Potentially logging off took too long and handleLoginTimeout took action.`);


// Find proxyIndex from steam-user object options instead of loginData to get reliable log data
Expand All @@ -205,9 +232,6 @@ Bot.prototype._loginToSteam = async function() {
if (!thisProxy.proxy) logger("info", `[${this.logPrefix}] Trying to log in without proxy... (Attempt ${this.loginData.logOnTries}/${this.controller.data.advancedconfig.maxLogOnRetries + 1})`, false, true, logger.animation("loading"));
else logger("info", `[${this.logPrefix}] Trying to log in with proxy ${thisProxy.proxyIndex}... (Attempt ${this.loginData.logOnTries}/${this.controller.data.advancedconfig.maxLogOnRetries + 1})`, false, true, logger.animation("loading"));

// Attach loginTimeout handler
this.handleLoginTimeout();


// Call our steam-session helper to get a valid refresh token for us
let refreshToken = await this.sessionHandler.getToken();
Expand Down
2 changes: 1 addition & 1 deletion src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
{
"path": "src/bot/bot.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/bot.js",
"checksum": "97b6b1fb055bd3a19c11bbe68147b8c5"
"checksum": "f5ffdab3eaaaeed3035b76200c932c47"
},
{
"path": "src/bot/events/debug.js",
Expand Down

0 comments on commit 75d5766

Please sign in to comment.