Skip to content

Commit

Permalink
fix(Bot): Fix softlocked login process after proxy switch
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Mar 8, 2024
1 parent 10c6dff commit a373883
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions src/bot/events/error.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-02-29 14:32:11
* Last Modified: 2024-03-08 13:00:16
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
Expand All @@ -31,7 +31,7 @@ Bot.prototype._attachSteamErrorEvent = function() {
// Custom behavior for LogonSessionReplaced error
if (err.eresult == EResult.LogonSessionReplaced) {
logger("", "", true);
logger("warn", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam! Reason: LogonSessionReplaced. I won't try to relog this account because someone else is using it now.`, false, false, null, true); // Force print this message now
logger("warn", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam! Reason: 'Error: LogonSessionReplaced'. I won't try to relog this account because someone else is using it now.`, false, false, null, true); // Force print this message now

// Abort or skip account. No need to attach handleRelog() here
if (this.index == 0) {
Expand All @@ -49,7 +49,7 @@ Bot.prototype._attachSteamErrorEvent = function() {

// Check if this is a connection loss and not a login error (because disconnects are thrown here when SteamUser's autoRelogin is false)
if (this.status == Bot.EStatus.ONLINE) { // It must be a fresh connection loss if status has not changed yet
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam. Reason: ${err}`);
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam. Reason: '${err}'`);
this.controller._statusUpdateEvent(this, Bot.EStatus.OFFLINE); // Set status of this account to offline

// Store disconnect timestamp & reason
Expand All @@ -67,9 +67,15 @@ Bot.prototype._attachSteamErrorEvent = function() {

} else { // Actual error during login

let blockedEnumsForRetries = [EResult.Banned, EResult.AccountNotFound]; // No need to block InvalidPassword anymore as the SessionHandler handles credentials
// Unlock login, but only if not already done by loginTimeout handler to prevent duplicate login requests
if (!this.loginData.pendingLogin) return logger("debug", `[${this.logPrefix}] Won't handle this login error because 'pendingLogin' is already 'false'; handleLoginTimeout must already have taken action`);

this.loginData.pendingLogin = false;


// Check if all logOnTries are used or if this is a fatal error
let blockedEnumsForRetries = [EResult.Banned, EResult.AccountNotFound]; // No need to block InvalidPassword anymore as the SessionHandler handles credentials

if (this.loginData.logOnTries > this.controller.data.advancedconfig.maxLogOnRetries || blockedEnumsForRetries.includes(err.eresult)) {
logger("error", `Couldn't log in bot${this.index} after ${this.loginData.logOnTries} attempt(s). ${err} (${err.eresult})`);

Expand Down Expand Up @@ -100,12 +106,7 @@ Bot.prototype._attachSteamErrorEvent = function() {

} else {

logger("warn", `[${this.logPrefix}] '${err}' while trying to log in.${this.loginData.pendingLogin ? " Retrying in 5 seconds..." : ""}`, false, false, null, true); // Log error as warning

// Unlock login, but only if not already done by loginTimeout handler to prevent duplicate login requests
if (!this.loginData.pendingLogin) return logger("debug", `[${this.logPrefix}] Won't handle this login error because 'pendingLogin' is already 'false'; handleLoginTimeout must already have taken action`);

this.loginData.pendingLogin = false;
logger("warn", `[${this.logPrefix}] '${err}' while trying to log in. Retrying in 5 seconds..."}`, false, false, null, true); // Log error as warning

// Try again in 5 sec, Controller's login function waits for any status that is not offline
setTimeout(() => this._loginToSteam(), 5000);
Expand Down
6 changes: 3 additions & 3 deletions src/bot/helpers/handleRelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Created Date: 2023-10-05 16:14:46
* Author: 3urobeat
*
* Last Modified: 2023-12-27 13:59:47
* Last Modified: 2024-03-08 11:48:23
* Modified By: 3urobeat
*
* Copyright (c) 2023 3urobeat <https://github.com/3urobeat>
* Copyright (c) 2023 - 2024 3urobeat <https://github.com/3urobeat>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand Down Expand Up @@ -106,7 +106,7 @@ Bot.prototype.checkAndSwitchMyProxy = async function() {

// Switch proxy and relog, no need for handleRelog() to do something
this.switchProxy(leastUsedProxy.proxyIndex);
this.status = Bot.EStatus.OFFLINE;
this.controller._statusUpdateEvent(this, Bot.EStatus.OFFLINE);
this.controller.login();
return true;

Expand Down
4 changes: 2 additions & 2 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
{
"path": "src/bot/events/error.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/events/error.js",
"checksum": "1d9acb9bc2e620a84bb2aaecef3de96b"
"checksum": "6823b9bcda9d8abe8892f4f3cca0dce9"
},
{
"path": "src/bot/events/friendMessage.js",
Expand Down Expand Up @@ -373,7 +373,7 @@
{
"path": "src/bot/helpers/handleRelog.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/helpers/handleRelog.js",
"checksum": "05712aba973391541848a6940b0de537"
"checksum": "3808cfde6f188582a539628ef4f5eb76"
},
{
"path": "src/bot/helpers/steamChatInteraction.js",
Expand Down

0 comments on commit a373883

Please sign in to comment.