Skip to content

Commit

Permalink
chore: Reduce log msg amount on login/relog
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Mar 8, 2024
1 parent a373883 commit 690480a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
10 changes: 4 additions & 6 deletions src/bot/events/disconnected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Created Date: 2021-07-09 16:26:00
* Author: 3urobeat
*
* Last Modified: 2023-12-27 13:58:37
* Last Modified: 2024-03-08 17:40:03
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2023 3urobeat <https://github.com/3urobeat>
* Copyright (c) 2021 - 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 All @@ -28,8 +28,6 @@ Bot.prototype._attachSteamDisconnectedEvent = function() {

if (this.status == Bot.EStatus.OFFLINE && this.controller.info.activeLogin) return; // Ignore if account is already marked as offline and a login process is active

logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam. Message: ${msg} | Check: https://steamstat.us`);

// Store disconnect timestamp & reason
this.lastDisconnect.timestamp = Date.now();
this.lastDisconnect.reason = msg;
Expand All @@ -38,11 +36,11 @@ Bot.prototype._attachSteamDisconnectedEvent = function() {

// Don't relog if account is in skippedaccounts array or if relogAfterDisconnect is false
if (!this.controller.info.skippedaccounts.includes(this.loginData.logOnOptions.accountName) && this.controller.info.relogAfterDisconnect) {
logger("info", `${logger.colors.fggreen}[${this.logPrefix}] Initiating a login retry in ${this.controller.data.advancedconfig.loginRetryTimeout / 1000} seconds.`); // Announce relog
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam: '${msg}'. Initiating a login retry in ${this.controller.data.advancedconfig.loginRetryTimeout / 1000} seconds.`); // Announce relog

setTimeout(() => this.controller.login(), this.controller.data.advancedconfig.loginRetryTimeout); // Relog in loginRetryTimeout ms
} else {
logger("info", `[${this.logPrefix}] I won't queue myself for a relog because this account is either already being relogged, was skipped or this is an intended logOff.`);
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam: '${msg}'. I won't queue for a relog because this account is either already being relogged, was skipped or this is an intended logOff.`);
}

});
Expand Down
9 changes: 4 additions & 5 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-03-08 13:00:16
* Last Modified: 2024-03-08 17:44:50
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -49,7 +49,6 @@ 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}'`);
this.controller._statusUpdateEvent(this, Bot.EStatus.OFFLINE); // Set status of this account to offline

// Store disconnect timestamp & reason
Expand All @@ -58,11 +57,11 @@ Bot.prototype._attachSteamErrorEvent = function() {

// Check if this is an intended logoff
if (this.controller.info.relogAfterDisconnect && !this.controller.info.skippedaccounts.includes(this.loginData.logOnOptions.accountName)) {
logger("info", `${logger.colors.fggreen}[${this.logPrefix}] Initiating a login retry in ${this.controller.data.advancedconfig.loginRetryTimeout / 1000} seconds.`); // Announce relog
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam: '${err}'. Initiating a login retry in ${this.controller.data.advancedconfig.loginRetryTimeout / 1000} seconds.`); // Announce relog

setTimeout(() => this.controller.login(), this.controller.data.advancedconfig.loginRetryTimeout); // Relog after waiting loginRetryTimeout ms
} else {
logger("info", `[${this.logPrefix}] I won't queue myself for a relog because this account was skipped or this is an intended logOff.`);
logger("info", `${logger.colors.fgred}[${this.logPrefix}] Lost connection to Steam: '${err}'. I won't queue for a relog because this account was skipped or this is an intended logOff.`);
}

} else { // Actual error during login
Expand Down Expand Up @@ -106,7 +105,7 @@ Bot.prototype._attachSteamErrorEvent = function() {

} else {

logger("warn", `[${this.logPrefix}] '${err}' while trying to log in. Retrying in 5 seconds..."}`, false, false, null, true); // Log error as warning
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
7 changes: 2 additions & 5 deletions src/bot/events/loggedOn.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-10 14:08:02
* Last Modified: 2024-03-08 17:49:10
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
Expand All @@ -28,7 +28,7 @@ Bot.prototype._attachSteamLoggedOnEvent = function() {
this.user.on("loggedOn", () => {

// Print message and set status to online
logger("info", `[${this.logPrefix}] Account logged in! Waiting for websession...`, false, true, logger.animation("loading"));
logger("debug", `[${this.logPrefix}] Account logged in! Public IP of this account: ${this.user.publicIP}`, false, true);

if (this.index == 0) {
logger("debug", `[${this.logPrefix}] Setting online status '${this.data.advancedconfig.onlineStatus}' as enum '${EPersonaState[this.data.advancedconfig.onlineStatus]}'`);
Expand All @@ -38,9 +38,6 @@ Bot.prototype._attachSteamLoggedOnEvent = function() {
this.user.setPersona(EPersonaState[this.data.advancedconfig.childAccOnlineStatus]); // Set child acc online status
}

logger("debug", `[${this.logPrefix}] Public IP of this account: ${this.user.publicIP}`);


// Increase progress bar if one is active
if (logger.getProgressBar()) logger.increaseProgressBar((100 / this.data.logininfo.length) / 3);

Expand Down
11 changes: 7 additions & 4 deletions src/bot/events/webSession.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:10:29
* Last Modified: 2024-03-08 16:21:53
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -39,9 +39,12 @@ Bot.prototype._attachSteamWebSessionEvent = function() {
this.loginData.relogTries = 0; // Reset relogTries to indicate that this proxy is working should one of the next logOn retries fail
this.loginData.pendingLogin = false; // Unlock login again


if (!this.controller.info.readyAfter) logger("info", `[${this.logPrefix}] Got websession and set cookies. Accepting offline friend & group invites...`, false, true, logger.animation("loading")); // Only print message with animation if the bot was not fully started yet
else logger("info", `[${this.logPrefix}] Got websession and set cookies. Accepting offline friend & group invites...`, false, true);
// Print logged in message with animation on initial login, otherwise without
if (!this.controller.info.readyAfter) {
logger("info", `[${this.logPrefix}] Logged in! Accepting pending friend requests & group invites...`, false, true, logger.animation("loading"));
} else {
logger("info", `[${this.logPrefix}] Logged in! Accepting pending friend requests & group invites...`, false, true);
}


// Run check if all friends are in lastcomment.db database for main bot account
Expand Down
4 changes: 2 additions & 2 deletions src/controller/events/statusUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2023-03-30 21:05:13
* Author: 3urobeat
*
* Last Modified: 2024-02-28 19:57:36
* Last Modified: 2024-03-08 17:49:26
* Modified By: 3urobeat
*
* Copyright (c) 2023 - 2024 3urobeat <https://github.com/3urobeat>
Expand All @@ -31,7 +31,7 @@ Controller.prototype._statusUpdateEvent = function(bot, newStatus) {
bot.status = newStatus;

// Log debug message
logger("info", `[${bot.logPrefix}] Event statusUpdate: Changed status from ${Bot.EStatus[oldStatus]} to ${Bot.EStatus[newStatus]}`, false, true, logger.animation("loading"));
logger("debug", `[${bot.logPrefix}] Event statusUpdate: Changed status from ${Bot.EStatus[oldStatus]} to ${Bot.EStatus[newStatus]}`, false, true);

// Emit event
this.events.emit("statusUpdate", bot, oldStatus, newStatus);
Expand Down
12 changes: 6 additions & 6 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@
{
"path": "src/bot/events/disconnected.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/events/disconnected.js",
"checksum": "38cf0c4ac7164d5cb902b65d287b902d"
"checksum": "92fda70994fd7f04246c75ca85d6aa3e"
},
{
"path": "src/bot/events/error.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/events/error.js",
"checksum": "6823b9bcda9d8abe8892f4f3cca0dce9"
"checksum": "8415adcfa88700af656c85657a3c05c3"
},
{
"path": "src/bot/events/friendMessage.js",
Expand All @@ -343,7 +343,7 @@
{
"path": "src/bot/events/loggedOn.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/events/loggedOn.js",
"checksum": "b0e36936c50b3efc27dc7fb7255b39eb"
"checksum": "94405ecfae8f113b0e38169b09c1f2dd"
},
{
"path": "src/bot/events/relationship.js",
Expand All @@ -353,7 +353,7 @@
{
"path": "src/bot/events/webSession.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/bot/events/webSession.js",
"checksum": "9a5ae34296fcaa9912f5e7e818841fa9"
"checksum": "23ffa55367ac713ce9ce6c2ec4c3d913"
},
{
"path": "src/bot/helpers/checkMsgBlock.js",
Expand Down Expand Up @@ -503,7 +503,7 @@
{
"path": "src/controller/events/statusUpdate.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/controller/events/statusUpdate.js",
"checksum": "3d8ee1a34d7d4f9911ade350dd03b7f7"
"checksum": "5a7c66ae19eb320bacf6d2c2abeba9d6"
},
{
"path": "src/controller/events/steamGuardInput.js",
Expand Down Expand Up @@ -728,7 +728,7 @@
{
"path": "src/sessions/helpers/tokenStorageHandler.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/sessions/helpers/tokenStorageHandler.js",
"checksum": "edd3065f5f2d0a9b5e178d5dfc701ded"
"checksum": "3b7bee517850238ba69d7e369cd0950b"
},
{
"path": "src/sessions/sessionHandler.js",
Expand Down
4 changes: 2 additions & 2 deletions src/sessions/helpers/tokenStorageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2022-10-10 12:53:20
* Author: 3urobeat
*
* Last Modified: 2024-02-27 17:27:32
* Last Modified: 2024-03-08 17:49:48
* Modified By: 3urobeat
*
* Copyright (c) 2022 - 2024 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -61,7 +61,7 @@ SessionHandler.prototype._getTokenFromStorage = function(callback) {

// Compare expire value (unix timestamp in seconds) to current date
if (jwtObj.exp * 1000 > Date.now()) {
logger("info", `[${this.bot.logPrefix}] Found valid token until '${validUntilStr}' in tokens.db! Logging in with it to reuse session...`, false, true, logger.animation("loading"));
logger("debug", `[${this.bot.logPrefix}] Found valid token until '${validUntilStr}' in tokens.db! Logging in with it to reuse session...`, false, true);
callback(doc.token);
} else {
logger("info", `[${this.bot.logPrefix}] Found invalid token in tokens.db. It was valid till '${validUntilStr}'. Logging in with credentials to get a new session...`, false, true, logger.animation("loading"));
Expand Down

0 comments on commit 690480a

Please sign in to comment.