Jump to content


Photo

"Not logged in"

node.js node-steam-tradeoffer-manager

  • Please log in to reply
10 replies to this topic

#1 MrInka

MrInka

    Newbie

  • Member
  • Pip
  • 9 posts

Posted 20 April 2017 - 04:51 AM

Hey,  

I see that there are already topics discussing this particular error, but most of them aren't including code examples. Tried to fix it myself, but it doesn't seem to work.  

 

So when accepting an offer, I sometimes get this error:  

Error: Not Logged In
    at SteamCommunity._checkCommunityError (/home/pi/Desktop/bot_final/node_modules/steamcommunity/components/http.js:128:9)
    at Request._callback (/home/pi/Desktop/bot_final/node_modules/steamcommunity/components/http.js:51:88)
    at Request.self.callback (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Gunzip.<anonymous> (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:1001:12)
    at Gunzip.g (events.js:291:16)

So to log in, I am using this:  

var config = require('./config.js');
var SteamCommunity = require('steamcommunity');
var SteamTotp = require('steam-totp');
var SteamUser = require('steam-user');
var TradeOfferManager = require('steam-tradeoffer-manager');


var community = new SteamCommunity();
var client = new SteamUser();
var manager = new TradeOfferManager({
  steam: client,
  domain: 'example.com',
  language: 'en'
});

client.logOn({
    accountName: config.username,
    password: config.password,
    twoFactorCode: SteamTotp.generateAuthCode(config.sharedsecret)
});

client.on('loggedOn', function(details) {
  console.log("Bot logged in");
  client.setPersona(SteamUser.Steam.EPersonaState.Online,config.botname);
});

client.on('webSession', function(sessionID, cookies) {
  manager.setCookies(cookies, function(err) {
    if (err) return console.log(err);
    console.log(" > Got API key!");
  });
  community.setCookies(cookies);
  community.startConfirmationChecker(10000, config.identitysecret);
})

And to keep the bot from coming up with the "Not logged in error", I added this (which obviously doesnt work).  

var lastLoginAttempt = Date.now();

client.on("sessionExpired", function(err) {
    if(Date.now() - lastLoginAttempt > 30000) {
        lastLoginAttempt = Date.now();
        console.log(" > Session Expired, relogging.");
        client.webLogOn();
    } else {
        console.log(" Session Expired, waiting a while before attempting to relogin.");
    }
});

I was told to add a "timer" so it doesn't spam the login when the websession expires.

 

Any idea why it doesn't work? Is client.webLogOn() the right way to log in again?  

 

 

 

Any help is appreciated! :)

 
 

Edited by MrInka, 20 April 2017 - 08:42 AM.


#2 Dr. McKay

Dr. McKay

    Administrator

  • Administrator
  • 1,170 posts

Posted 20 April 2017 - 10:22 AM

Yes, client.webLogOn is the correct way to do it. I suspect that you're getting a new web session successfully (add some logging to the webSession event to make sure), and you're just doing something else wrong.



#3 DevDuck

DevDuck

    Member

  • Member
  • PipPip
  • 21 posts

Posted 01 May 2017 - 09:29 AM

Yes, client.webLogOn is the correct way to do it. I suspect that you're getting a new web session successfully (add some logging to the webSession event to make sure), and you're just doing something else wrong.

 

sessionExpired event is not a module node-steamcommunity?

 

client.on('sessionExpired') or community.on('sessionExpired')?

 

I have similar code:

community.on('sessionExpired', (err) => {

});

But I get a error after a couple days of work of the bot:

Error: Not Logged In

But the event community.on('sessionExpired') is not triggered. Maybe need to catch event client.on('sessionExpired')?


Edited by DevDuck, 01 May 2017 - 10:40 AM.


#4 SunriseM

SunriseM

    Advanced Member

  • Member
  • PipPipPip
  • 46 posts
  • LocationVenezuela

Posted 01 May 2017 - 12:02 PM

sessionExpired event is not a module node-steamcommunity?

 

client.on('sessionExpired') or community.on('sessionExpired')?

 

Yes its in the community module. What do you have exactly inside of 

community.on('sessionExpired', (err) => {

});

Edited by SunriseM, 01 May 2017 - 12:03 PM.


#5 DevDuck

DevDuck

    Member

  • Member
  • PipPip
  • 21 posts

Posted 01 May 2017 - 12:21 PM

this.community.on('sessionExpired', (err) => {
    console.log('sessionExpired. ', + err);
    this.client.webLogOn();
});

But in the logs I don't see errors (sessionExpired. + err)... based on this the event is not triggered.

 

Update.

 

I tried this:

setTimeout(() => {
    this.community.setCookies(['steamLogin=invalid', 'steamLoginSecure=invalid']);
}, 30000);

but the event sessionExpired anyway is not triggered


Edited by DevDuck, 01 May 2017 - 04:43 PM.


#6 Dr. McKay

Dr. McKay

    Administrator

  • Administrator
  • 1,170 posts

Posted 01 May 2017 - 06:37 PM

Pass the community instance in to the constructor of TradeOfferManager, as per the docs.



#7 DevDuck

DevDuck

    Member

  • Member
  • PipPip
  • 21 posts

Posted 01 May 2017 - 06:59 PM

Pass the community instance in to the constructor of TradeOfferManager, as per the docs.

 

Thank you! And one more question: this event (sessionExpired) will be emitted when be done some error? Or this event is the interval?



#8 SunriseM

SunriseM

    Advanced Member

  • Member
  • PipPipPip
  • 46 posts
  • LocationVenezuela

Posted 01 May 2017 - 07:30 PM

Pass the community instance in to the constructor of TradeOfferManager, as per the docs.

 

I tested with this code:


    self.community.on('sessionExpired', (err) => {
      log.info("Session Expired");
    });

    setTimeout(function(){
      log.info("Killing Cookies");
      self.community.setCookies(["steamLogin=1||invalid", "steamLoginSecure=1||invalid"]);
    }, 31000);

    setTimeout(function(){
      log.info("Fixing Cookies");
      self.client.webLogOn();
    },60000);

    setInterval(function(){
      self.community.getNotifications(function(err, notifications){
        if(err) log.error(err);
        else log.info(notifications);
      });
    }, 15000);

After the Killing Cookies part. getNotifications returns HTTP Error 401 (Not authorized), after the Fixing Cookies part i get the notifications without errors. Then i checked the source code and found out that you only emit "sessionExpired" when HTTP Error is from 300 to 399. When its 401 it just callbacks the error. 

if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
		err = new Error("Not Logged In");
		callback(err, response, body);
		this._notifySessionExpired(err);
		return err;
	}


Edit: i found this part too. but for some reason im not getting the sessionExpired event.

if (typeof html === 'string' && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) {
		err = new Error("Not Logged In");
		callback(err);
		this._notifySessionExpired(err);
		return err;
	}

Edit 2: Modified this part and it worked, but i suppose it needs more changes.

	if (response.statusCode >= 400) {
		err = new Error("HTTP error " + response.statusCode);
		err.code = response.statusCode;
		callback(err, response, body);
                this._notifySessionExpired(err); // <-----
		return err;
	}

Edited by SunriseM, 01 May 2017 - 07:56 PM.


#9 Dr. McKay

Dr. McKay

    Administrator

  • Administrator
  • 1,170 posts

Posted 02 May 2017 - 01:28 AM

"status code >= 400" is inappropriate for detecting if the session has expired. Using that, you'll end up relogging constantly if you end up getting rate-limited (403 or 429), for example.



#10 SunriseM

SunriseM

    Advanced Member

  • Member
  • PipPipPip
  • 46 posts
  • LocationVenezuela

Posted 02 May 2017 - 10:24 AM

"status code >= 400" is inappropriate for detecting if the session has expired. Using that, you'll end up relogging constantly if you end up getting rate-limited (403 or 429), for example.

Yes i know that you didn't put that there for some reason. But what if we check only for status code === 401?



#11 Dr. McKay

Dr. McKay

    Administrator

  • Administrator
  • 1,170 posts

Posted 02 May 2017 - 04:41 PM

That should probably be fine, although I don't know for sure that Steam would give 401 for only logged-out errors. Steam is weird.







Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users